跨列添加并显示总计

lnlaulya  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(283)

我肯定这个问题已经解决了,但是找不到。我有以下几点: select id, one_num, two_num, (IFNULL(one_num,0) + IFNULL(two_num, 0)) as total from posts where total > 0; 它给了我一个错误: ERROR 1054 (42S22): Unknown column 'total' in 'where clause' 我想我得做一些子查询。但我试过了,运气不好。

tsm1rwdh

tsm1rwdh1#

中的表达式不能使用自定义别名 where 子句或使用 having 或者在where子句中重复完整表达式

select id, one_num, two_num, (ifnull(one_num,0) + ifnull(two_num, 0)) as total
from posts 
having total > 0;

select id, one_num, two_num, (ifnull(one_num,0) + ifnull(two_num, 0)) as total
from posts 
where (ifnull(one_num,0) + ifnull(two_num, 0)) > 0;

相关问题