SQLServer中如何查出数据库中百分比的数据
3个回答
展开全部
sql2005以后.优先使用如下方式,扩展性强。
---------------------------------------------------------------------
select A.* from
(
SELECT ROW_NUMBER() OVER(ORDER BY ID DESC) AS rownum ,B.*
FROM dbo.testB
) A
where A.rownum>=1 and A.rownum<=(select count(*)*3/10 from dbo.test)
---------------------------------------------------------------------
2000 数据库
SELECT TOP (select count(*)*3/10 from dbo.test) * FROM test order by ID DESC
----------------------------------------------------------
---------------------------------------------------------------------
select A.* from
(
SELECT ROW_NUMBER() OVER(ORDER BY ID DESC) AS rownum ,B.*
FROM dbo.testB
) A
where A.rownum>=1 and A.rownum<=(select count(*)*3/10 from dbo.test)
---------------------------------------------------------------------
2000 数据库
SELECT TOP (select count(*)*3/10 from dbo.test) * FROM test order by ID DESC
----------------------------------------------------------
展开全部
select top( select convert(int, (select count(*) from test)*0.3))* from test order by ID desc
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
1> SELECT
2> *
3> FROM
4> union_tab_2
5> go
id val
----------- ----------
1 A
1 A
2 B
4 D
(4 行受影响)
1> SELECT
2> TOP ((SELECT COUNT(1) FROM union_tab_2) * 3 / 10)
3> *
4> FROM
5> union_tab_2
6> go
id val
----------- ----------
1 A
(1 行受影响)
2> *
3> FROM
4> union_tab_2
5> go
id val
----------- ----------
1 A
1 A
2 B
4 D
(4 行受影响)
1> SELECT
2> TOP ((SELECT COUNT(1) FROM union_tab_2) * 3 / 10)
3> *
4> FROM
5> union_tab_2
6> go
id val
----------- ----------
1 A
(1 行受影响)
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询