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
试试
不好意思,因为已经有人回答了,所以将分给了第一个回答的人!见谅!大家的回答都挺对的!
相关问答:
Java code:
模糊查询书按照书名-------------------
java.sql.SQLException: Illegal mix of collations (gb2312_chinese_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation 'like'
at com.mys ......
问题是这样的,现在有个用户mysql 密码为空,然后我先把它改成123,这样写为什么不能改mysqladmin -u mysql password 123,结果出现mysqladmin: Can't turn off logging; error: 'Access denied; you need t ......
一个行业网站,要实现的功能要求为:
一搜索表单可选搜索 产品/资讯/商家,搜索时希望先搜标题后全文,当前的数据量估计3万多,定位期望在百万级也可用。
数据类型为innodb,当前的方法是对关键词进行 ......
if(mysql_init(&mysql)==NULL)
{
sprintf(ErrMsg,"We are outof Memory");
return(false);
}
if(!mysql_real_connect(&mysql,"localhost","test" ......
我之前导入的数据库,现在删除不了,用了命令行和工具都不行,重启也不行,这是为什么呢?
你是如何删除的?
有什么提示?
问题说明越详细,回答也会越准确!参见如何提问。(提问的智慧)
......