日期:2014-05-18 浏览次数:20661 次
select * from (select sum(saleAmount) as allamount, customerName, productName from View_ProductSellInfoDetail group by customername, productname)t where allamount >= 100 and allamount <= 400
------解决方案--------------------
sorry, i am wrong. using having is the right way.
select sum(saleAmount) as allamount, customerName, productName from View_ProductSellInfoDetail group by customername, productname having sum(saleAmount) between 100 and 400
------解决方案--------------------
declare @t table(customername nvarchar(5), productCode int, productName nvarchar(5), saleAmount int,saleDate datetime)
insert @t select '欣欣超市',1, '软中华',100, '2007-1-1'
insert @t select '华联商贸',2, '硬中华',50 , '2007-1-3'
insert @t select '欣欣超市',1, '软中华',200, '2007-1-6'
insert @t select '文峰超市',1, '软中华',60 , '2007-1-7'
insert @t select '欣欣超市',3, '苏烟',50 , '2007-1-8'
insert @t select '农工商超市',2, '硬中华', 300, '2007-1-9'
select
customername,
productName,
sum(saleAmount)as '销量'
from
@t
where
saleDate between '2007-1-1' and '2007-1-10'
group by
customername,productName
having
(sum(saleAmount) between 100 and 400 )