create table #tb (data int,nn int)
insert into #tb
select 23,100 union all
select 21,200 union all
select 24,200 union all
select 25,100 union all
select 24,100 union all
select 20,100 union all
select 22,200 union allselect top 1 *
from
(
select *,bl=(select sum(nn)*100.0 from #tb where nn<=t.nn)/(select sum(nn) from #tb)
from #tb t
)t
where bl>30
order by bl
这是我之前发问贴的内容,但无法在mysql中查询,提示 t 格式不对,"where nn<=t.nn" 请教在mysql中如何实现:
查询目的,实现data(从低到高)对应的 nn累计值 占 NN总计值的比例
查询结果:data,nn累计量,比例
20,100,0.01
21,300,0.03
22,500,0.05
23,600,0.06
24,900,0.09
25,1000,1.00
insert into #tb
select 23,100 union all
select 21,200 union all
select 24,200 union all
select 25,100 union all
select 24,100 union all
select 20,100 union all
select 22,200 union allselect top 1 *
from
(
select *,bl=(select sum(nn)*100.0 from #tb where nn<=t.nn)/(select sum(nn) from #tb)
from #tb t
)t
where bl>30
order by bl
这是我之前发问贴的内容,但无法在mysql中查询,提示 t 格式不对,"where nn<=t.nn" 请教在mysql中如何实现:
查询目的,实现data(从低到高)对应的 nn累计值 占 NN总计值的比例
查询结果:data,nn累计量,比例
20,100,0.01
21,300,0.03
22,500,0.05
23,600,0.06
24,900,0.09
25,1000,1.00
帮你转MS SQL 版
http://topic.csdn.net/u/20110326/09/899d4c01-56dc-4777-83be-cd7a02fe41c0.html
我需要 mysql版的查询SQL
在mysql中如何实现 甲骨文的PERCENT_RANK函数