得到从20040101开始的第一天的记录
select top 1 日期, 商品ID,sum(卖出金额) as 卖出金额
from zwzl
where 商品ID = 某种商品ID and 日期 between '20040101' and '20041212'
group by 日期, 商品ID
order by 日期
select top 1 日期, 商品ID,sum(卖出金额) as 卖出金额
from zwzl
where 商品ID = 某种商品ID and 日期 between '20040101' and '20041212'
group by 日期, 商品ID
order by 日期
convert(varchar(10),a.日期,120) as 最近的日期,
sum(a.卖出金额) as 当日卖出金额
from
zwzl a
where
datediff(dd,(select max(日期) from zwzl where 商品ID = a.商品ID and (日期 between 日期1 and 日期2)),a.日期) = 0
and
a.商品ID = ...
group by
convert(varchar(10),a.日期,120)
select top 1 日期, 商品ID,sum(卖出金额) as 卖出金额
from zwzl
where 商品ID = 某种商品ID and 日期 between '20040101' and '20041212'
group by 日期, 商品ID
order by 日期得到最靠近20041212的一天的记录
select top 1 日期, 商品ID,sum(卖出金额) as 卖出金额
from zwzl
where 商品ID = 某种商品ID and 日期 between '20040101' and '20041212'
group by 日期, 商品ID
order by 日期 desc
select top 1 with ties convert(char(10),日期,120) as 日期, 商品ID,
sum(卖出金额) as 卖出金额
from #zwzl
where 日期 between '20040101' and '20041212'
group by 日期, 商品ID with rollup
order by 日期 desc