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
试试
不好意思,因为已经有人回答了,所以将分给了第一个回答的人!见谅!大家的回答都挺对的!
相关问答:
用jsp做东西给完全不懂mysql的人用,可是备份时只有空文件,这是什么情况,
最好有源代码,谢谢
其实备份的过程我想大概是这样的:
将表A中的数据放到ArrayList中,然后将这个ArrayList中的数据再存到表B中。 ......
现有的服务器是4核,内存为4G,数据库只使用innodb数据引擎。链接数可能比较高,先设置为500吧,而且数据库中的数据插入、更新和删除操作会非常的频繁。
有没有高人帮忙配置一下my.cnf
这个没有定论的,具体 ......
代码如下:
$sql = "select count(*) from admin";
$result = mysql_query($sql);
$num=mysql_num_rows($result);
echo $num;
为什么不管我的记录有多少条,都是输出1,
我想输出查询的 ......
大家好,我在创建索引时,出现错误提示,代码如下:
create uique index stu_cou_index on student_info.results (student_id, course_id);
show index from student_info.results;
保存为index ......
我安装好mysql后,默认的数据库路径是在C盘下,我想把它改到E盘里: 我先把mysql服务停止,再在mysql安装目录(也是在E盘)下找到my.ini文件,就改了下面那么多:
#Path to the database root
datadir="E ......