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
试试
不好意思,因为已经有人回答了,所以将分给了第一个回答的人!见谅!大家的回答都挺对的!
相关问答:
数据库引擎使用MYISAM
例如表名:LOG 每天会产生400万左右的记录
日积月累数据量会非常之宠大
所以考虑到这点
我想了两个方案
1、每天产生一个表,类似LOG20091010、LOG20091011
2、每天 ......
问题是这样的,现在有个用户mysql 密码为空,然后我先把它改成123,这样写为什么不能改mysqladmin -u mysql password 123,结果出现mysqladmin: Can't turn off logging; error: 'Access denied; you need t ......
if(mysql_init(&mysql)==NULL)
{
sprintf(ErrMsg,"We are outof Memory");
return(false);
}
if(!mysql_real_connect(&mysql,"localhost","test" ......
在mysql中repair table xxxxx;提示
mysql> repair table recordTbl;
+-----------------+--------+----------+----------------------------------------------+
| Table   ......