我嘗試在childs的記錄爲1的一對多關係child中進行選擇。對於用一個記錄獲取childs,我使用以下查詢。mysql group by with where返回其他結果
下面是一個簡單的查詢,如果我不使用where
聲明
select a.iid,
account_id,
count(*) as props
from accounts_prop a
group by a.account_id
having props = 1
當我使用where
我回來完全其他結果其中工程。在這種情況下,我得到記錄這表明道具爲1分的紀錄,但實際上有一個以上的
select a.iid,
account_id,
count(*) as props
from accounts_prop a
where a.von >= '2017-08-25'
group by a.account_id
having props = 1
我錯過了在這種情況下
這兩個查詢是不同的第一個涉及所有行第二個只有行與a.von> ='2017-08-25'那麼你有不同的行組集..你的問題是不是清..試試解釋更好 – scaisEdge