SELECT TOP 程序传递过来的1000参数变量 sum(je) FROM (SELECT sum(je) AS je FROM Table1 GROUP BY 客户名编号) a先合并一个客户多个定单,再取前1000个客户,
谢谢2位回复,这其实和程序无关,只是统计分析用,看看每增加1000人的销售增长趋势,所以需要SQL语句, 因为用户数的增加肯定随着时间的增加,在目前这张表中,我只能根据订单时间来判断人数, select sum(金额) from order where 订单时间<'xxxx-xx-xx xx:xx:xx',当用户正好是第1000个人的时候,得到这个订单时间,随即计算该时间之前的所有销售额,即算出人数达到1000人时的销售额,但这个订单时间如何得到呢?? 上面这句SELECT TOP 程序传递过来的1000参数变量 sum(je) FROM (SELECT sum(je) AS je FROM Table1 GROUP BY 客户名编号) a 如果我的客户编号存在,而且是自增的,那没问题,现在没这个编号,
如只是看看。 没编号直接就select top 1000 from 表 最后一条1000条就是最后时间 就行了。
可以用累加值 通过时间排序 select * from ( select *,(select sum(je) as je from tb where 客户名编号=t.客户名编号 and 时间<=t.时间) as je from tb t ) where je<=1000
declare @i int,@sql varchar(200) set @i=1000 set @sql='select a.* from (select top '+convert(char(10),@i)+' * from tb) a left join (select top '+convert(char(10),@i-1)+' * from tb) b on a.订单号=b.a.订单号 where b.a.订单号 is null' exec (@sql)
declare @i int,@sql varchar(200) set @i=1000 set @sql='select a.* from (select top '+convert(char(10),@i)+' * from tb) a left join (select top '+convert(char(10),@i-1)+' * from tb) b on a.订单号=b.a.订单号 where b.订单号 is null' exec (@sql)
SELECT TOP 程序传递过来的1000参数变量 sum(je) FROM (SELECT sum(je) AS je FROM Table1 GROUP BY 客户名编号) a先合并一个客户多个定单,再取前1000个客户,
因为用户数的增加肯定随着时间的增加,在目前这张表中,我只能根据订单时间来判断人数,
select sum(金额) from order where 订单时间<'xxxx-xx-xx xx:xx:xx',当用户正好是第1000个人的时候,得到这个订单时间,随即计算该时间之前的所有销售额,即算出人数达到1000人时的销售额,但这个订单时间如何得到呢??
上面这句SELECT TOP 程序传递过来的1000参数变量 sum(je) FROM (SELECT sum(je) AS je FROM Table1 GROUP BY 客户名编号) a
如果我的客户编号存在,而且是自增的,那没问题,现在没这个编号,
没编号直接就select top 1000 from 表 最后一条1000条就是最后时间 就行了。
select * from
(
select *,(select sum(je) as je from tb where 客户名编号=t.客户名编号 and 时间<=t.时间) as je from tb t
)
where
je<=1000
declare @i int,@sql varchar(200)
set @i=1000
set @sql='select a.* from
(select top '+convert(char(10),@i)+' * from tb) a left
join
(select top '+convert(char(10),@i-1)+' * from tb) b
on a.订单号=b.a.订单号
where b.a.订单号 is null'
exec (@sql)
declare @i int,@sql varchar(200)
set @i=1000
set @sql='select a.* from
(select top '+convert(char(10),@i)+' * from tb) a left
join
(select top '+convert(char(10),@i-1)+' * from tb) b
on a.订单号=b.a.订单号
where b.订单号 is null'
exec (@sql)