MYSQL中根据字段值判断返回不同的值
在mysql中有一张表,有三个字段total,max, min,都是int型的值,可以写一个sql语句完成功能:
根据每条记录中,如果total>max,返回2,如果total <min返回1,如果都条件都不符合返回0。急求!!!!
mysql?
差点看成ms sql了.
试试:
SQL code:
select * ,case when total>max then 2
when total <min then 1
else 0
end
from 表
select case when total > max then 2 else case when total < min then 1 else null end end
from ta
case when
SQL code:
select case
when total > max then 2
when total < min then 1
else 0
end
from ta
试试
SQL code:
select case
when total > max then 2
when total < min then 1
else 0
end
from ta
试试
不好意思,因为已经有人回答了,所以将分给了第一个回答的人!见谅!大家的回答都挺对的!
相关问答:
在mysql中repair table xxxxx;提示
mysql> repair table recordTbl;
+-----------------+--------+----------+----------------------------------------------+
| Table   ......
我用一个循环往数据库里面存文件,本来可以作为文件存放数据库里面只放文件的位置的,但是没有办法租的服务器网页空间大小有限制数据库没有限制。语句是这样的
public static final DataBase.MAXSIZE=102 ......
关于mysql存储过程变量的问题?变量什么时候前面要加@符号,用declare声明的变量与前者有和区别,我不懂?
@是用来屏蔽错误或警告的,当前面加了@符号后,若此处有错或警告,网页将不显示出来。
前面加@代表会话 ......
我是用mysql自带的C API
if(mysql_real_connect(&mysql,"125.0.0.108","root","root","home",3306,NULL,0))
{
AfxMessageBox("数据库连接失败") ......