多联机冷凝水管坡度:SQL语句问题
来源:百度文库 编辑:中科新闻网 时间:2024/10/03 03:21:37
请帮忙看看,假如在User表中
Sim DataTime State
1001 12:21 0
1002 12:31 1
1003 12:35 1
1001 12:22 1
1002 12:33 1
1003 12:36 0
1004 12:20 0
1004 12:21 0
结果
1001 12:22 1
1002 12:31 1
1003 12:35 1
1004 12:20 0
相同的Sim卡号,只显示一次,并且根据State字段来选择,如果一天中有一次为1,则最后结果中为1,否则为0,时间上不做要求.
麻烦各位!!!
Sim DataTime State
1001 12:21 0
1002 12:31 1
1003 12:35 1
1001 12:22 1
1002 12:33 1
1003 12:36 0
1004 12:20 0
1004 12:21 0
结果
1001 12:22 1
1002 12:31 1
1003 12:35 1
1004 12:20 0
相同的Sim卡号,只显示一次,并且根据State字段来选择,如果一天中有一次为1,则最后结果中为1,否则为0,时间上不做要求.
麻烦各位!!!
select distinct sim from user
这样就可以相同的Sim卡号,只显示一次了,至于你后面的State,不太明白你的意思!!
select distinct sim ,case state when state==1 then 1 else 0 end from user
试一下,我现在试不了。