易截截图软件、单文件、免安装、纯绿色、仅160KB

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模糊查询问题

Java code:

模糊查询书按照书名-------------------
java.sql.SQLException: Illegal mix of collations (gb2312_chinese_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation 'like'
at com.mys ......

C语言 Mysql 疑问

if(mysql_init(&mysql)==NULL)
{
sprintf(ErrMsg,"We are outof Memory");
return(false);
}

if(!mysql_real_connect(&mysql,"localhost","test" ......

Mysql 数据库删除不了怎么办

我之前导入的数据库,现在删除不了,用了命令行和工具都不行,重启也不行,这是为什么呢?
你是如何删除的?
有什么提示?


问题说明越详细,回答也会越准确!参见如何提问。(提问的智慧)

......

mysql的连接超时时间怎么设置 - VC/MFC / 数据库

我是用mysql自带的C API
if(mysql_real_connect(&mysql,"125.0.0.108","root","root","home",3306,NULL,0))

AfxMessageBox("数据库连接失败") ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号