select group,count(select * from tb a where (finish-start) between 0 and 100 ) as less100, count(select * from tb where (finish-start) between 101 and 200) as less200
from tb group by group
select team,count(select * from tb_job where (finish-start) between 0 and 100 ) as less100, count(select * from tb_job where (finish-start) between 101 and 200) as less200
from tb_job group by team
T less100 less200 less300 more300
A 2 1 0 1
B 2 0 2 1
C 2 0 0 2
ถ้าใช่ล่ะก็ ข้างล่างนี่เป็รคำสั่งครับ
Code (SQL)
select team as t, (select count(*) from tb_job where (finish-start) between 0 and 100 ) as less100, (select count(*) from tb_job where ((finish-start) between 101 and 200) and team = t) as less200,
(select count(*) from tb_job where ((finish-start) between 201 and 300) and team = t) as less300,
(select count(*) from tb_job where ((finish-start) > 300) and team = t) as more300
from tb_job group by team
select team as t, (select count(*) from tb_job where ((finish-start) between 0 and 100 ) and team = t) as less100, (select count(*) from tb_job where ((finish-start) between 101 and 200) and team = t) as less200,
(select count(*) from tb_job where ((finish-start) between 201 and 300) and team = t) as less300,
(select count(*) from tb_job where ((finish-start) > 300) and team = t) as more300
from tb_job group by team
t less100 less200 less300 more300
A 1 1 0 1
B 0 0 2 1
C 1 0 0 2