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命令输入错误后,执行错误命令发出可怕的叫声
怎么样解决???
那叫声音跟指针读数据读错了,发出一样可以怕的叫声
搞的我不敢用命令行
呵呵!lz真可爱!
方法一,把你的PC上的喇叭拆除
方 ......
一个行业网站,要实现的功能要求为:
一搜索表单可选搜索 产品/资讯/商家,搜索时希望先搜标题后全文,当前的数据量估计3万多,定位期望在百万级也可用。
数据类型为innodb,当前的方法是对关键词进行 ......
if(mysql_init(&mysql)==NULL)
{
sprintf(ErrMsg,"We are outof Memory");
return(false);
}
if(!mysql_real_connect(&mysql,"localhost","test" ......
在MySQL5.0中船舰存储过程通不过,提示:
[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' ......