日期:2014-05-16 浏览次数:20699 次
select store,sum(endprice*nb) as sum_sales_lweek,SUM(nb) as sum_nb,count(distinct nos) as sum_nos
from [CMD].[dbo].[cmd_xjjx_sale]
where outdate<='20140223' and outdate>='20140216' and endprice>0
group by store
declare @begindate varchar(20),@enddate varchar(20)
select @begindate='20140216',@enddate='20140223'
select a.store,
a.sum_sales_lweek,a.sum_nb,a.sum_nos,
isnull(b.sum_sales_lweek,0) 'lastyear_sum_sales_lweek',
isnull(a.sum_nb,0) 'lastyear_sum_nb',
isnull(a.sum_nos,0) 'lastyear_sum_nos',
from
(select store,
sum(endprice*nb) as sum_sales_lweek,
sum(nb) as sum_nb,
count(distinct nos) as sum_nos
from [CMD].[dbo].[cmd_xjjx_sale]
where outdate>=@begindate and outdate<=@enddate and endprice>0
group by store) a
left join
(select store,
sum(endprice*nb) as sum_sales_lweek,
sum(nb) as sum_nb,
count(distinct nos) as sum_nos
from [CMD].[dbo].[cmd_xjjx_sale]
where outdate>=convert(varchar,dateadd(yyyy,-1,@begindate),112)
and outdate<=convert(varchar,dateadd(yyyy,-1,@enddate),112) and endprice>0
group by store) b on a.store=b.store
declare @page_size int;
declare @page_num int;
--比如:每页10条记录
set @page_size = 10;
--比如:先取第1页
set @page_num = 1;
select *
from
(
select a.dbno, a.names,a.qsq,a.class2,a.area_no,b.sum_sales_lweek,b.sum_nb,b.sum_nos,b.last_