我有 3 個 store_id (0,1,6) 。我只想讓 id 有 storeid <> 0 ,但 24340 也有 storeid =0 ,我也想洗掉它
原來的:
valueid store_id
24346 6
24345 6
24345 1
24344 0
24340 6
24340 1
24340 0
預期的:
valueid store_id
24346 6
24345 6
24345 1
嘗試使用 store_id NOT IN (0,1,6) 或 store_id<>0 And store_id<>1 AND store_id<>6 但似乎不起作用
uj5u.com熱心網友回復:
嘗試:
select *
from my_tbl
where valueid not in (select valueid
from my_tbl
where store_id=0);
演示:https : //www.db-fiddle.com/f/4raGrSSZtagsBMDereNzTa/0
結果:
valueid store_id 24346 6 24345 6 24345 1
uj5u.com熱心網友回復:
使用聚合:
SELECT valueid, store_id
FROM yourTable
WHERE valueid IN (SELECT valueid FROM yourTable
GROUP BY valueid HAVING SUM(store_id = 0) = 0);
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/365697.html
標籤:mysql
