gpt4 book ai didi

mysql - mysql IF条件中的多个表达式

转载 作者:太空宇宙 更新时间:2023-11-03 10:56:34 26 4
gpt4 key购买 nike

我需要比较表中的一些值,即如果小于、大于和等于...

我的查询如下:

  SELECT `t1`.`K1`
IF (Sum(`t1`.`K1`) > Sum(`t2`.`K1`), 'Greater', 'Less') AS State
FROM `t1`
INNER JOIN `t2` ON `t1`.`Code` = `t2`.`Code`
GROUP BY `t1`.`K1`

如果值相等,如何实现条件?

最佳答案

SELECT `t1`.`K1`,
case when Sum(`t1`.`K1`) = Sum(`t2`.`K1`) then 'Equal'
when Sum(`t1`.`K1`) > Sum(`t2`.`K1`) then 'Greater'
else 'Less'
end AS State
FROM `t1`
INNER JOIN `t2` ON `t1`.`Code` = `t2`.`Code`
GROUP BY `t1`.`K1`

关于mysql - mysql IF条件中的多个表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20143421/

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