1

我有 2 个表,其中包含以下内容:

表格1

start | end | pcs 
0840   1030   35
1040   1230   30

表2

timestamp | line
0841
0842
1041
1042

我想从table1的时间范围计算table2每次的总计数?

我希望有人能得到这个,

谢谢

4

1 回答 1

2
select
    t1.[start], t1.[end], count(*)
from table1 as t1
    left outer join table2 as t2 on t2.timestamp between t1.[start] and t1.[end]
group by t1.[start], t1.[end]

sql fiddle demo

于 2013-08-23T05:39:14.740 回答