col不为空时的sql case

uplii1fm  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(417)

我早些时候问了一个类似的问题,然后回去重新审视我的逻辑。这里有一个更新。我在teamsql中运行mysql。
我想在col(lc.ladder\u)不为空时限制这个情况。

SELECT 
@row_number:=(CASE
    WHEN @member_id = lh.member_id and lc.ladder_advocacy IS NOT NULL 
THEN @row_number + 1
    ELSE 1
END) AS rank,
@member_id:=lh.member_id AS member_id,
lc.name,
lh.trigger_event_date,
lc.ladder_advocacy 
FROM
leenk_ladder_history AS lh
LEFT JOIN leeds_so.leenk_ladder_config AS lc ON lh.ladder_config_id = lc.id
WHERE
ladder_change = 1 AND trigger_active = 1 
ORDER BY member_id , trigger_event_date DESC;

我也试过:

lc.ladder_advocacy <> ``
lc.ladder_advocacy <> ""
lc.ladder_advocacy != ""
lc.ladder_advocacy != ``

lc.ladder\u col显示空白值时仍得到回报。

有什么想法吗?

wsewodh2

wsewodh21#

原来teamsql中的美化功能增加了一个额外的空间。
回答:

SELECT 
@row_number:=(CASE
    WHEN @member_id = lh.member_id
    THEN @row_number + 1
    ELSE 1
END) AS rank,
@member_id:=lh.member_id AS member_id,
lc.name,
lh.trigger_event_date,
lc.ladder_advocacy 
FROM
leeds.leenk_ladder_history AS lh
    LEFT JOIN leeds_so.leenk_ladder_config AS lc ON lh.ladder_config_id = lc.id
WHERE
    ladder_change = 1 AND trigger_active = 1 and lc.ladder_advocacy <> '' 
ORDER BY member_id , trigger_event_date DESC;

相关问题