这是一个表是如何呈现
SELECT RequestsID, Country, Activity,
[People needed (each day)], [Start date], [End date]
FROM dbo.Requests
会有很多的要求,我想总结一下,每天(!)的“人们需要”,还不如开始和结束日期之间。
此外,我想组由国家,有其历史我想获得的数据之间设置的可能性。
有些日子,可能是空的就需要人(0),但日期应反正呈现。 请注意,可以指出相同的日期,并在同一个国家多个请求 - 但活动是那么不同。
查询应该是这样的(当然,it's不是SQL,你可以看到,只是想显示逻辑)
From Requests,
show Country and SUM 'People needed'
where (column not in Requests table-Date) is a Date (will be
a number of dates, I want to set the scope by a Start and End date)
and Requests.Country is @Country
(and the Date(s) above of course is between the Requests Start date and End date...)
And from (a non existing table...?) show Date
Group by Country
我希望看到这样的事情:
Date Country People needed
06/01/2010 Nigeria 34 // this might be from three different Requests, all pointing out Nigeria. People needed might be (30+1+3 = 34)
06/02/2010 Nigeria 10
06/03/2010 Nigeria 0
06/04/2010 Nigeria 1
06/05/2010 Nigeria 134
06/01/2010 China 2
06/02/2010 China 0
06/03/2010 China 14
06/04/2010 China 23
06/05/2010 China 33
06/01/2010 Chile 3
06/02/2010 Chile 4
06/03/2010 Chile 0
06/04/2010 Chile 0
06/05/2010 Chile 19
你会怎么做呢?
注:我希望看到某种类型的示例代码,即可开始:-)