sql查询以特定格式显示数据

问题描述:

我想要如下格式的显示数据。

I want the display data like below format.

1 1
2 1
2 2
3 1
3 2 
3 3
4 1
4 2
4 3
4 4
5 1
5 2
5 4
.
.
.
.
7 6
7 7
after 7 then
8 8
9 8
9 9
10 8
.
.
.
.
100 99
100 100



i想要高达100


i want upto 100

试试这段代码!!希望你会喜欢它:)



Try this code!!Hope you will njoy it :)

CREATE TABLE #temp1(
Numbers int
)
/**********/
	DECLARE @idt INT 
	Declare @count int
	SET @idt = 0
	SET @count=0
	WHILE (@idt < 100)
	BEGIN
		SELECT @idt = @idt + 1
		SELECT @count=1
		WHILE(@idt>=@count)
			BEGIN
				SELECT @count = @count + 1
				insert into #temp1(Numbers)values(@idt)
				--print @idt
			END
	END
/**********/
Select Numbers,ROW_NUMBER() Over(Partition by Numbers order by Numbers) As RowNum  from #temp1 

Select * from #temp1


使用while循环适当的条件和解决这个问题

快乐编码!

:)
use while loop with proper conditions and solve this puzzel
Happy Coding!
:)