【发布时间】:2020-03-26 11:17:39
【问题描述】:
是否可以从查询的HAVING 部分更改SELECT 查询中字段的值?我不想接触数据库中的数据,这只是选择中返回的值。
这是一个人为的例子,因为真正的查询很长而且很复杂。
SELECT t.col1, t.col2, (@all_is_ok = TRUE) as all_is_ok
FROM table t
WHERE t.col1 = 'something'
HAVING (
(t.col2 = 1 AND t.col3 = 1)
OR (t.col2 = 2 AND t.col3 = 2)
OR (SET @all_is_ok = FALSE) /* If we get into this final OR in the HAVING
then I want the column all_is_ok to be set
to FALSE so that I still get the row back,
but can see that the row wasn't as expected */
)
我们使用的是 MariaDB 10.4。
我希望这是有道理的,有人可以提供帮助。谢谢。
【问题讨论】:
-
请提供样本数据和期望的结果。并且解释您想要实现的逻辑也会有所帮助。
-
有传言称@variables 将被删除。因此,请努力寻找不同的技术。