gpt4 book ai didi

Mysql where 列条件

转载 作者:行者123 更新时间:2023-11-29 04:23:25 25 4
gpt4 key购买 nike

最小的例子

select a.order_id as X from orders as a
WHERE
X > 8000

查询将失败,因为 X 不是列,有什么解决办法吗?

其他例子

select (if (E.size > 0, E.Size, (B.height x B.width)) as sizeX from
orders as a, report as E, size as B

where

(E.id = a.id and B.id = a.id)
and
sizeX > 100

我的查询可能包含拼写错误,但我希望我的问题是清楚的

最佳答案

你有两个选择:

1) 使用 HAVING(不是很有效,因为 having 子句的条件是在返回结果后应用的,因此没有使用索引)

select a.order_id as X from orders as a
HAVING
X > 8000

2) 使用列名(如果在 where 子句中使用列的索引,则效率高)

select a.order_id as X from orders as a
WHERE
a.order_id > 8000

关于Mysql where 列条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17209148/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com