gpt4 book ai didi

mysql - 带或不带括号的求和和比较

转载 作者:行者123 更新时间:2023-11-29 13:15:33 26 4
gpt4 key购买 nike

我有 3 列,其类型为 double

我需要获得 3 列的总和大于 x 的结果。

也许是一个愚蠢的问题,以下哪种方法更适合这个

1) 通常求和:WHERE col1 + col2 + col3 > x

2) 或在括号中求和:WHERE (col1 + col2 + col3) > x

或者说这两种方法完全没有区别?

最佳答案

您的两个查询都没有问题。根据运算符层次结构,最好使用括号方法。

MySQL Operator Precedence documentation

Operator precedences are shown in the following list, from highest precedence to the lowest. Operators that are shown together on a line have the same precedence.

INTERVAL
BINARY, COLLATE
!
- (unary minus), ~ (unary bit inversion)
^
*, /, DIV, %, MOD
-, +
<<, >>
&
|
= (comparison), <=>, >=, >, <=, <, <>, !=, IS, LIKE, REGEXP, IN
BETWEEN, CASE, WHEN, THEN, ELSE
NOT
&&, AND
XOR
||, OR
= (assignment), :=
Its better to handle the summarized values among three columns.

WHERE (col1 + col2 + col3) > x

关于mysql - 带或不带括号的求和和比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21509591/

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