Table1
Id name status type
1 a start 1
2 b end 2
3 a start 1
4 b end 2
5 a start 1
6 b end 2
7 a start 1
8 b end 2
期望结果:Status=‘start’并且count(type=1)count(type=2)
Group by name
得到列为:
Name 时长 type1次数合计 type2次数合计我用
Select t.name,count(status) s1,sum(type=1) t1,sum(type=2) t2
From table1 t
where status=’start’
group by name
不正确请问这个语句怎么写呀?
Id name status type
1 a start 1
2 b end 2
3 a start 1
4 b end 2
5 a start 1
6 b end 2
7 a start 1
8 b end 2
期望结果:Status=‘start’并且count(type=1)count(type=2)
Group by name
得到列为:
Name 时长 type1次数合计 type2次数合计我用
Select t.name,count(status) s1,sum(type=1) t1,sum(type=2) t2
From table1 t
where status=’start’
group by name
不正确请问这个语句怎么写呀?
From table1 t
where status=’start’
group by name
用楼上的方法试过,有许多重复列怎么去除呀
Select distinct t.name,count(status) s1,sum(decode(type,1,1,0)) t1,sum(decode(type,2,1,0)) t2 From table1 t where status=’start’ group by name