"congers(code_conger primary key,date_depart,date_retour,duree)"
和
"ouvriers_congers(#idouvrier, #idconger)"
和
"ouvriers(matricule,nom,prenom)"
什麼我想要我期從他們的工人報「NOM」和「prenom」表康吉爾斯獲取數據並通過idconger
<% ResultSet rsS = st.executeQuery("select o.matricule,o.nom,o.prenom, c.*, oc.* from ouvriers o, congers c, ouvriers_conger oc where c.code_conger = oc.idconger and oc.idouvrier = o.matricule");
while(rsS.next()){
int cd = rsS.getInt("code_conger");
%>
<tr>
<td><%= cd %></td>
<td><%= rsS.getDate("date_depart") %></td>
<td><%= rsS.getDate("date_retour") %></td>
<td><%= rsS.getInt("duree") %></td>
<td><%= rsS.getString("nom") %></td>
</tr>
<% } %>
分組,但它告訴我這樣
1 05/01/2015 05/05/2015 4 adil 1 05/01/2015 05/05/2015 4 souf 2 08/20/2015 08/30/2015 9 smith
的數據,你看到的結果ISN 「T由 「code_conger」
電郵宣傳我試圖這組它:
select o.*, c.*, oc.idconger,oc.idouvrier from ouvriers o, congers c, ouvriers_conger oc where c.code_conger = oc.idconger and oc.idouvrier = o.matricule group by oc.idconger
它給我一個錯誤:ORA-00979:不是GROUP BY表達式
的結果,我希望得到的是:
1 05/01/2015 05/05/2015 4 -adil -souf 2 08/20/2015 08/30/2015 9 smith
這裏是測試用的DDL語句
create table congers
(
code_conger NUMBER(5) PRIMARY KEY,
date_depart DATE DEFAULT (sysdate),
date_retour DATE DEFAULT (sysdate),
duree NUMBER(5)
);
create table ouvriers_congers
(
idouvrier NUMBER(5),
idconger NUMBER(5),
CONSTRAINT ouvriers_congers_pk PRIMARY KEY (idouvrier, idconger)
);
create table ouvriers
(
matricule NUMBER(5) PRIMARY KEY,
nom VARCHAR2(15),
prenom VARCHAR2(15)
);
INSERT INTO congers VALUES (1,to_date('05/01/2015','MM/DD/YYYY'),
to_date('05/05/2015','MM/DD/YYYY'),
4);
INSERT INTO congers VALUES (2,to_date('08/20/2015','MM/DD/YYYY'),
to_date('08/30/2015','MM/DD/YYYY'),
9);
INSERT INTO ouvriers VALUES (1,'adil','adil');
INSERT INTO ouvriers VALUES (2,'souf','souf');
INSERT INTO ouvriers VALUES (3,'smith','smith');
INSERT INTO ouvriers_congers VALUES (1,1);
INSERT INTO ouvriers_congers VALUES (2,1);
INSERT INTO ouvriers_congers VALUES (3,2);
如果數據庫變大,「select * from congers」可能會變得很危險,你應該找到一種方法來限制或分頁 – Robson
我沒有使用分頁...因爲這不會返回一個大數據(最多50個結果或更少) – ADiL