我正在使用别名。
以下是我的查询。我想避免使用NULL
计数器显示行。
SELECT activity_id, user_id,
(CASE WHEN activity_id = 1 OR activity_id = 2 THEN user_id END) AS counter
FROM eventedge_ticket_activity
它给出了以下结果:
如何跳过包含计数器NULL
的行?
答案 0 :(得分:1)
未经测试,但下面应该有效。
SELECT activity_id, user_id,
CASE activity_id WHEN 1 THEN user_id
WHEN 2 THEN user_id
ELSE NULL
END AS counter
FROM eventedge_ticket_activity
WHERE counter IS NOT NULL
答案 1 :(得分:0)
以下是成功运行的查询。
SELECT * FROM (SELECT activity_id, user_id, case when activity_id=1 then user_id when activity_id=2 then user_id end as counter FROM eventedge_ticket_activity) db where counter != 'NULL'
答案 2 :(得分:0)
我感觉样本数据已经过度简化,所以我可能错了,但这看起来只是解析数据一次的相同查询。
SELECT activity_id, user_id,
user_id AS counter
FROM eventedge_ticket_activity
WHERE activity_id in(1,2)
顺便说一下,marmeladze提供的答案也应该与我在评论中提到的改变一致[/ p>