易截截图软件、单文件、免安装、纯绿色、仅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配置文件(my.cnf)

现有的服务器是4核,内存为4G,数据库只使用innodb数据引擎。链接数可能比较高,先设置为500吧,而且数据库中的数据插入、更新和删除操作会非常的频繁。
有没有高人帮忙配置一下my.cnf

这个没有定论的,具体 ......

关于MYSQL单表存储问题

数据库引擎使用MYISAM
例如表名:LOG 每天会产生400万左右的记录

日积月累数据量会非常之宠大

所以考虑到这点
我想了两个方案
1、每天产生一个表,类似LOG20091010、LOG20091011
2、每天 ......

求救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 ......

mysql:创建索引出错

大家好,我在创建索引时,出现错误提示,代码如下:

create uique index stu_cou_index on student_info.results (student_id, course_id);
show index from student_info.results;

保存为index ......

C语言 Mysql 疑问

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

if(!mysql_real_connect(&mysql,"localhost","test" ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号