求一个sql语句

WBOY
Release: 2016-06-23 14:22:19
Original
990 people have browsed it

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;
Copy after login


类似这样的 通过计算得到一个临时列exp,然后再去判断exp的值是否小于某个数的SQL语句应该怎么写?我写成这样后提示语法错误:Unknown column 'exp' in 'where clause'


回复讨论(解决方案)

.... (A.az*7+B.bz)<='.$time.'....

SQL是从右到左的,所以where的时候exp还没有定义。

试一试 HAVING 应该是可以

select *,(A.az*7+B.bz) as exp HAVING exp<='.$time.' ORDER BY A.ay;
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template