SQL语句重复输出记录问题

来源:百度知道 编辑:UC知道 时间:2024/05/27 19:56:37
表[table]中有如下数据:

ID Count
1 2
2 3
3 2
4 1
怎样输出总共为8条记录?如:
ID Count
1 2
1 2
2 3
2 3
2 3
3 2
3 2
4 1
用SQL语句实现

SELECT ID,COUNT(*)
FROM TABLE
GROUP BY ID
HAVING COUNT(*)>1

看反了,呵呵!
建议你从程序实现吧!

很少有像你这么做的,一般ID都会被设为主键,你这样做不是自找没趣吗,我也拿2分走人

select * from table a
union
select * from table b

这个只能用PL/SQL用循环和游标做,SQL无法实现的

table1是你的表名 ,这里的c.Count 大于100的话他只能输出一百了,如果需求小的话(个位数,下面的可以简化,如果大于100,在a,b,后面在挂一个10单位的,可以把上限提高到1000,类推加一个*10)
select c.ID,c.Count
from table1 c inner join
(
select ROW_NUMBER() over(order by a.id) as RowCountNum,b.id
from
(select 0 id union all
select 1 id union all
select 2 id union all
select 3 id union all
select 4 id union all
select 5 id union all
select 6 id union all
select 7 id union all
select 8 id union all
select 9 ) a,
(select 0 id union all
select 1 id union all
select 2 id union all
select 3 id union all
select 4 id union all
select 5 id union all
select 6 id union all
select