我有以下查询。
select paytype, sum(amtpaid)
from `tbl_payments`
where locationid = 3 and
checkstatus not in ('Refund','Tip','Tipadj') and
paytype not in ('Void', 'Comp') and
oid in (select oid
from `tbl_checkout_stage`
where locationid = 3
group by oid
having count(checkid) = sum(checkstatus = 'Paid')
)
group by paytype
如何在上面的情况下用join替换子查询。 提前谢谢。
答案 0 :(得分:0)
尝试此查询
select paytype, sum(amtpaid)
from `tbl_payments`
join (select oid
from `tbl_checkout_stage`
where locationid = 3
group by oid
having count(checkid) = sum(checkstatus = 'Paid')
) a on a.oid=`tbl_payments`.oid
where locationid = 3 and
checkstatus not in ('Refund','Tip','Tipadj') and
paytype not in ('Void', 'Comp') and
group by paytype