图像表中的
- 1是来自另一个表的Primery密钥ID自动编号和DeclarationContentId作为FK的表。有两列GrantedAmount和DeclaredAmount由另一列AmountType标识。我想要一个左外连接查询,它将返回给我一个与GrantedAmount的DeclartionContentId和在一行中的DeclaredAmount togather
答案 0 :(得分:0)
在这里做一些假设
declarationcontent
和declarationcontentamount
试试这个
SELECT dc.declarationcontentid,
Isnull(ga.grantedamount, 0) grantedamount,
Isnull(dc.declaredamount, 0) declaredamount
FROM declarationcontent dc
LEFT JOIN declarationcontentamount ga
ON dc.declarationcontentid = ga.declarationcontentid
AND amounttype = 1
LEFT JOIN declarationcontentamount dc
ON dc.declarationcontentid = ga.declarationcontentid
AND amounttype = 2