mysql 条件计算
表A,字段ax,ay,az
表B,字段bx,by,bz
$time = time();select *,(A.az*7+B.bz) as exp WHERE exp<='.$time.' ORDER BY A.ay;
类似这样的 通过计算得到一个临时列exp,然后再去判断exp的值是否小于某个数的SQL语句应该怎么写?我写成这样后提示语法错误:Unknown column 'exp' in 'where clause'
回复讨论(解决方案)
.... (A.az*7+B.bz)
SQL是从右到左的,所以where的时候exp还没有定义。
试一试 HAVING 应该是可以
select *,(A.az*7+B.bz) as exp HAVING exp<='.$time.' ORDER BY A.ay;
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn