--> 测试数据:@te declare @te table(id varchar(14),[成交量] int) insert @te select '玉米期货合约',333 union all select '大豆',222 union all select '黄金',333 union all select '玉米期货合约',222 union all select '大豆',333 --如何查询并列第一的现象 --常规方法1: select top 1 * from @te order by [成交量] desc --或方法2 select top 1 id,SUM([成交量]) as 总成交量 from @te group by id order by 总成交量 desc select top 1 with ties id,SUM([成交量]) as 总成交量 ,COUNT(1) from @te group by id order by 总成交量 desc --或 --SQL 2008 动态前N列 declare @n int set @n = 3 select TOP(@n) * from @te
declare @n int set @n=[参数]select top(@n) from tb
declare @n int set @n=[参数]select top(@n)* from tb
不好意思各位,我司现在还是用MSSQL2000版本
他差5分,双星sql2000 不行,不支持!
declare @n int set @n=[参数]exec ('select top '+@n+' * from tb')
select top (@n) * from tb
declare @te table(id varchar(14),[成交量] int)
insert @te
select '玉米期货合约',333 union all
select '大豆',222 union all
select '黄金',333 union all
select '玉米期货合约',222 union all
select '大豆',333 --如何查询并列第一的现象
--常规方法1:
select top 1 * from @te order by [成交量] desc
--或方法2
select top 1 id,SUM([成交量]) as 总成交量 from @te group by id order by 总成交量 desc
select top 1 with ties id,SUM([成交量]) as 总成交量 ,COUNT(1) from @te group by id order by 总成交量 desc
--或
--SQL 2008 动态前N列
declare @n int
set @n = 3
select TOP(@n) * from @te
set @n=[参数]select top(@n) from tb
set @n=[参数]select top(@n)* from tb
set @n=[参数]exec ('select top '+@n+' * from tb')
其中有一段主要用MSSQL2000完成某个表中的数据行的打印页码,根据用户需求设计每页纸打印多少行。
有字段:
单据编号、单据日期、货品编号、数量、页码