表:TAB1使用MySQL的加入兩個表
id date_time zoneid accountid slotid trequest bidder width height
_50832 2017-09-04 15:41:06 153 1654 153x468x60 10 aaa 468 60
_50832 2017-09-04 15:41:06 152 1654 152x468x60 10 bbb 468 60
表:TAB2
id date_time zoneid accountid slotid bidder count
_50832 2017-09-04 15:41:06 152 1654 152x468x60 bbb 6
_50832 2017-09-04 15:41:06 152 1654 152x468x60 bbb 4
_50832 2017-09-04 15:41:06 153 1654 153x468x60 aaa 9
_50832 2017-09-04 15:41:06 153 1654 153x468x60 aaa 1
下面
是我的查詢:
SELECT SUM(req.trequest) as REQ, SUM(win.count) as IMP
FROM tab1 as req
JOIN tab2 as win ON (req.id=win.id AND req.zoneid=win.zoneid)
GROUP BY req.zoneid
我得到下面的結果,
REQ IMP
20 10
20 10
IMP計數正確,但我得到錯誤的REQ計數。我的預期結果是
REQ IMP
10 10
10 10
如何獲得我的預期結果?
爲什麼你在做SUM(req.trequest)?我認爲,因爲SUM(req.trequest),你得到了錯誤的結果... –
我需要SUM trequest從tab1和計數從tab2 – Thiyagu