日期:2014-05-18  浏览次数:20500 次

sql查询季度问题?
有一张SQL数据表EM,有销售合同号(accid),员工编号(emid),销售日期(ShippedDate)和销售金额(account)—4个字段,编写计算出2010年各个季度中,公司销售总份数与总销售金额?

select year(ShippedDate) as 年份,
sum
  (
  case when  
  month(ShippedDate) in (1,2,3))  
  then count(accid) as 销售总份数,sum(account) as 销售总金额
  else 0
  ) as 第一季度

from EM where ShippedDate like'2010?'
group by year(ShippedDate)
order by year(ShippedDate)

请各位帮忙看看,我这么写有问题吗?

------解决方案--------------------
探讨
有一张SQL数据表EM,有销售合同号(accid),员工编号(emid),销售日期(ShippedDate)和销售金额(account)—4个字段,编写计算出2010年各个季度中,公司销售总份数与总销售金额?

select year(ShippedDate) as 年份,
sum
(
case when
month(ShippedDate) in (1,2,3)) ……

------解决方案--------------------
SQL code
select year(ShippedDate) as 年份,
sum
  (
  case when   
  month(ShippedDate) in (1,2,3))   
  then count(accid) end as 销售总份数,sum(account) as 销售总金额   --这里的end忘记了哦
  else 0
  ) as 第一季度

from EM 
where ShippedDate like'2010%'   --还有这里的? 要用%
group by year(ShippedDate)
order by year(ShippedDate)