我想选择具有条件但不起作用的数据库。
我有这个问题:
SELECT c.*
,s.*
,f.*
,count(c.id) as instock_count
,totals.orders_total
,GROUP_CONCAT(c.sku SEPARATOR '<br/>') AS sku
FROM produse_com c
INNER JOIN (SELECT * , SUM(stoc) as stoc_sum
FROM stocuri_mentor
GROUP BY sku ) s
ON c.sku = s.sku
INNER JOIN (SELECT count(id) as orders_total, id_comanda
FROM produse_com
WHERE NOT ridicat = 'Da'
GROUP BY id_comanda ) totals
ON totals.id_comanda = c.id_comanda
INNER JOIN (SELECT data_add, status, id_comanda
FROM comenzi
WHERE NOT (status = 'Impachetat' OR status = 'Stornat' OR status = 'Anulat')
) f
ON f.id_comanda = c.id_comanda
WHERE stoc_sum >= c.qty
GROUP BY c.id_comanda
HAVING instock_count = orders_total
问题是我有条件WHERE NOT ridicat = 'Da'
但结果包含ridicat = 'Da'
编辑:
如果我删除此查询INNER JOIN (SELECT * ,SUM(stoc) as stoc_sum FROM stocuri_mentor GROUP BY sku ) s ON c.nume_produs = s.sku
和WHERE stoc_sum >= c.qty
,结果就可以了
编辑2:解决方案=再添加一个条件WHERE stoc_sum >= c.qty AND ridicat <> 'Da'
答案 0 :(得分:-1)
您可以尝试此查询。
SELECT count(id) as orders_total, id_comanda, ridicat
FROM produse_com
WHERE ridicat != 'Da'
GROUP BY id_comanda;