示例伪SQL
SELECT *, condlabel FROM tbl WHERE cond1:(col1 = 1) OR cond2:(col2 = 2 and col3 = 4)
因此结果将具有附加列,这些列具有它们所满足的精确条件标签
hgc7kmma1#
正如AymDev评论的那样,完美的解决方案是在选择块中添加as别名的条件
as
nvbavucw2#
不可以,你只能在SELECT子句和you cannot use those in a WHERE clause中标记(创建别名表达式),但是你可以使用子查询来实现这一点:
SELECT
WHERE
SELECT * FROM ( SELECT *, (col1 = 1) AS cond1, (col2 = 2 and col3 = 4) AS cond2 FROM tbl ) AS tmp WHERE cond1 OR cond2
或者只是重复它们:
SELECT *, (col1 = 1) AS cond1, (col2 = 2 and col3 = 4) AS cond2 FROM tbl WHERE (col1 = 1) OR (col2 = 2 and col3 = 4)
2条答案
按热度按时间hgc7kmma1#
正如AymDev评论的那样,完美的解决方案是在选择块中添加
as
别名的条件nvbavucw2#
不可以,你只能在
SELECT
子句和you cannot use those in aWHERE
clause中标记(创建别名表达式),但是你可以使用子查询来实现这一点:或者只是重复它们: