我有这样的架构
http://sqlfiddle.com/#!3/690e8
我想显示TransactionID和TransactionDate(格式' yyyy.MM.dd'),其中MedicineTypeName不是' Syrup'和MedicinePrice大于15000使用转换,存在和...
结果应该是这样的
我试过了:
select th.TransactionID,convert(varchar,th.TransactionDate,20)[tanggal]
from TransactionHeader th
join TransactionDetail td on th.TransactionID = td.TransactionID
where td.MedicineID in
(
select md.MedicineID
from MsMedicine md join MsMedicineType mmt on mmt.MedicineTypeID = d.MedicineTypeID
where mmt.MedicineTypeName not like 'syrup' and md.MedicinePrice > 15000
)
答案 0 :(得分:0)
将d.MedicineTypeID更改为md.MedicineTypeID
添加了distinct以防止重复
select distinct th.TransactionID,convert(varchar,th.TransactionDate,20)[tanggal]
from TransactionHeader th
join TransactionDetail td on th.TransactionID = td.TransactionID
where td.MedicineID in
(
select md.MedicineID
from MsMedicine md join MsMedicineType mmt on mmt.MedicineTypeID = md.MedicineTypeID
where mmt.MedicineTypeName not like 'syrup' and md.MedicinePrice > 15000
)