我有一张这样的表
id tran_id event_name
1 55262 activate
2 55262 suspended
3 47282 approval
如果发现event_name等于'激活'不要显示具有相同tran_id的所有数据
我试图使用sql-script获取此功能,但我认为它应该使用php脚本
答案 0 :(得分:0)
SELECT *
FROM yourTable
WHERE tran_id NOT IN (
SELECT tran_id
FROM yourTable
WHERE event_name = 'activate')
或
SELECT a.*
FROM yourTable AS a
LEFT JOIN yourTable AS b ON a.tran_id = b.tran_id AND b.event_name = 'activate'
WHERE b.tran_id IS NULL