易截截图软件、单文件、免安装、纯绿色、仅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的查询结果

代码如下:
$sql = "select count(*) from admin";
$result = mysql_query($sql);
$num=mysql_num_rows($result);
echo $num;
为什么不管我的记录有多少条,都是输出1,
我想输出查询的 ......

网站镜像,主网站和镜像网站Mysql数据同步

现在有一个网站,想在另外一台服务器上做一个这个网站的镜像。
在主网站上的数据更新要同步到镜像服务器上
同时用户访问镜像服务器时的数据更新也要同步到主网站上

其中数据更新 主要包括 Mysql数据 ......

mysql:创建索引出错

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

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

保存为index ......

MySQL创建存储过程出错

在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 '' ......

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号