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
试试
不好意思,因为已经有人回答了,所以将分给了第一个回答的人!见谅!大家的回答都挺对的!
相关问答:
代码如下:
$sql = "select count(*) from admin";
$result = mysql_query($sql);
$num=mysql_num_rows($result);
echo $num;
为什么不管我的记录有多少条,都是输出1,
我想输出查询的 ......
现在有一个网站,想在另外一台服务器上做一个这个网站的镜像。
在主网站上的数据更新要同步到镜像服务器上
同时用户访问镜像服务器时的数据更新也要同步到主网站上
其中数据更新 主要包括 Mysql数据 ......
大家好,我在创建索引时,出现错误提示,代码如下:
create uique index stu_cou_index on student_info.results (student_id, course_id);
show index from student_info.results;
保存为index ......
在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自带的C API
if(mysql_real_connect(&mysql,"125.0.0.108","root","root","home",3306,NULL,0))
{
AfxMessageBox("数据库连接失败") ......