-2

我的数据库中有 20 万条数据,需要每 15 天根据“上传日期时间”(数据库中的列)获取记录。例如,

Date               Number of Records.
April 1st-15th            20
April 16th-30th           40
May 1st to 15th           1000
May 16th to 31st          4000

到目前为止,有任何想法使用 Microsoft SQL-2008 R2 获取数据

4

1 回答 1

1

你可以做这样的事情

select 
case 
when date_col>='20130401' and date_col<'20130416' then 'April 1st-15th'
when date_col>='20130416' and date_col<'20130501' then 'April 16th-30th'
.
.
as date_range
end
count(*) as total
from table
group by 
when date_col>='20130401' and date_col<'20130416' then 'April 1st-15th'
when date_col>='20130416' and date_col<'20130501' then 'April 16th-30th'
.
.
end
于 2013-10-07T07:28:16.910 回答