【发布时间】:2014-08-09 12:20:36
【问题描述】:
我有这张桌子:
table tblCountry
name char(30)
table tblSite
name char(30) primary key not null,
country char(30)
table tblDivingClub
number int
name char(30)
country char(30)
table tblDiving
diving_number int
number_of_divers int
diving_club int
guide int
我写了这个查询:
select
tblSite.name,tblSite.site_length,tblSite.site_depth,
tblSite.water_type,tblSite.country,
COUNT(distinct tblDivingClub.number) as number_of_clubs,
COUNT(distinct tblDiving.diving_number) as number_of_divings,
COUNT(distinct tblDiving.guide) as number_of_guids,
sum(tblDiving.number_of_divers) as number_of_divers
from tblCountry
inner join tblSite
on tblCountry.name=tblSite.country
inner join tblDiving
on tblSite.name = tblDiving.diving_site
inner join tblDivingClub
on tblDiving.diving_club = tblDivingClub.number
where tblSite.name in (
select tblSite.name
from tblSite
where tblSite.country = 'New York'
)
and tblDiving.date_of_diving >= DATEADD(year,-1, GETDATE())
group by tblSite.name,tblSite.site_length,tblSite.site_depth,
tblSite.water_type,tblSite.country
我想显示潜水次数最多的月份 ('tblDiving.date_of_diving') 和本月的潜水次数。
有可能吗?
【问题讨论】:
标签: sql sql-server group-by