sql查询以特定格式显示数据 [英] sql query to display data in a particular format

查看:246
本文介绍了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!
:)


这篇关于sql查询以特定格式显示数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆