现在我有一个表“水果”,其中包含以下数据
ID Fruit Users
===============
1 Apple 5
2 Orange 4
3 Banana 3
我想根据用户的价值查询生成的虚拟行(或重复的记录)数据
Fruit Users
===========
Apple 5
Apple 5
Apple 5
Apple 5
Apple 5
Orange 4
Orange 4
Orange 4
Orange 4
Banana 3
Banana 3
Banana 3
我尝试加入表格,但由于行数已修复,因此无效。
答案 0 :(得分:1)
with a (idx) as (
select level from dual connect by level <= (select max(users) from fruits)),
b as (select fruit, users, idx from fruits join a on idx <= users)
select fruit, users from b order by users desc, fruit