2013-05-22 92 views
0

我有這個疑問在這裏:修改在SQL查詢更多結果

$strSQL = "select sum(lhd.sasih)-sum(lhd.sasid) as sasi,lhd.kartllg as kartllg 
from d2013..levizjehd lhd,supersick_db..produkt as prod 
where lhd.kartllg=prod.kodfinance 
group by lhd.kartllg" 

現在,這個查詢給了我兩列:SASI和kartllg 我需要提取第三列是在supersick_db..produkt表列pershkrim 我需要提取一個prod.pershkrim ...我該怎麼做?

如何修改查詢?

我把它修改爲:

$strSQL = "select sum(lhd.sasih)-sum(lhd.sasid) as sasi,lhd.kartllg as kartllg, produkt.pershkrimfinance 
from d2013..levizjehd lhd 
INNER JOIN supersick_db.produkt ON lhd.kartllg = prod.kodfinance 
group by lhd.kartllg"; 
} 

感謝

回答

1

你需要使用一個JOIN,包括在SELECT列名:

select sum(lhd.sasih)-sum(lhd.sasid) as sasi,lhd.kartllg as kartllg, produkt.pershkrim 
from d2013..levizjehd lhd 
INNER JOIN supersick_db.produkt ON produckt.ID = levizjehd.ID 
where lhd.kartllg=prod.kodfinance 
group by lhd.kartllg 

你將不得不改變produckt.IDlevizjehd.ID添加到您的兩個表中的相應標識符。

+0

感謝達倫您的建議.. ,但我只是需要得到prod.pershkrim,我不需要任何其他條件.. – alandr

+0

你可以去看看,請我修改了它.. – alandr

+0

@alandr - 會發生什麼事你運行修改後的查詢?你有什麼錯誤信息嗎? –