0
我是一名實習生,接管了我公司在前實習生的一個項目,而我的數據庫經驗非常少。該項目的範圍已擴大,我需要從數據庫中獲取更多數據。我有以下SQL查詢:通過條目循環
select
DSR_SEGMENT_LIGNE.SEG_NOM as "name",
DSR_NOEUD_SIMUL.NOE_NUMERO_NOEUD as "start",
DSR_NOEUD_SIMUL_ARRIVEE.NOE_NUMERO_NOEUD as "end",
DSR_SEGMENT_LIGNE.SEG_CIRCUIT as "circuit",
case DSR_SEGMENT_LIGNE.SEG_R0_MANUELLE
when 0 then DSR_SEGMENT_LIGNE.SEG_R0
else DSR_SEGMENT_LIGNE.SEG_R0_MANUELLE
end as "r0",
case DSR_SEGMENT_LIGNE.SEG_X0_MANUELLE
when 0 then DSR_SEGMENT_LIGNE.SEG_X0
else DSR_SEGMENT_LIGNE.SEG_X0_MANUELLE
end as "x0",
case DSR_SEGMENT_LIGNE.SEG_R1_MANUELLE
when 0 then DSR_SEGMENT_LIGNE.SEG_R1
else DSR_SEGMENT_LIGNE.SEG_R1_MANUELLE
end as "r1",
case DSR_SEGMENT_LIGNE.SEG_X1_MANUELLE
when 0 then DSR_SEGMENT_LIGNE.SEG_X1
else DSR_SEGMENT_LIGNE.SEG_X1_MANUELLE
end as "x1",
sum(DSR_SECTION_LIGNE.SEC_LONGUEUR) as "length",
DSR_SEGMENT_LIGNE.SEG_PARALLELE as "parallel",
from
DSR_SEGMENT_LIGNE
inner join DSR_NOEUD_SIMUL
on DSR_SEGMENT_LIGNE.SEG_ID_NOEUD_DEPART
= DSR_NOEUD_SIMUL.NOE_ID_NOEUD
inner join DSR_NOEUD_SIMUL DSR_NOEUD_SIMUL_ARRIVEE
on DSR_SEGMENT_LIGNE.SEG_ID_NOEUD_ARRIVEE
= DSR_NOEUD_SIMUL_ARRIVEE.NOE_ID_NOEUD
inner join DSR_LIGNE
on DSR_LIGNE.LIG_ID_LIGNE
= DSR_SEGMENT_LIGNE.LIG_ID_LIGNE
inner join DSR_SECTION_LIGNE
on DSR_SEGMENT_LIGNE.SEG_ID_SEGMENT
= DSR_SECTION_LIGNE.SEG_ID_SEGMENT
where DSR_LIGNE.LIG_NOM = "3040"
group by
DSR_SECTION_LIGNE.SEG_ID_SEGMENT
order by
1, 2
它輸出這樣的:
name start end circuit r0 x0 r1 x1 length parallel
A 1370 1382 1 0,0005425630938234 0,00167906265425173 7,3195053173195E-5 0,00055148562601198 0,177540954416641 0
B 1382 1383 1 0,0126386706603645 0,0378025148848846 0,00563519872024541 0,0131910224409082 3,70050627461981 1
C 1382 1383 2 0,0126386706603645 0,0378025148848846 0,00563519872024541 0,0131910224409082 3,70050627461981 1
D 1383 5515 1 0,021837386745766 0,0747186186014143 0,00948008366199402 0,023230913897742 6,82876115295014 0
其它表收集更多的數據所需要的相關元素是「名」(在這種情況下,四個名字是A ,B,C和D,並且始終是唯一的)。是否有可能以某種方式循環訪問這四行(類似於:for each "name" do ...
)而無需手動命名該名稱(例如where name = "A"
)併爲每個名稱收集特定於名稱的數據並將該數據放入該名稱的行中?
玩過內部連接後,我想我可以管理這個。 SQL查詢是一種非常不同的思考方式......但是,謝謝! – PhilHQ 2014-09-26 19:28:20