我肯定这个问题已经解决了,但是找不到。我有以下几点: 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' 我想我得做一些子查询。但我试过了,运气不好。
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'
tsm1rwdh1#
中的表达式不能使用自定义别名 where 子句或使用 having 或者在where子句中重复完整表达式
where
having
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;
1条答案
按热度按时间tsm1rwdh1#
中的表达式不能使用自定义别名
where
子句或使用having
或者在where子句中重复完整表达式或