任何人都可以帮我这个,我不知道如何在SQL中编写我所需的输出, [英] Can anyone help me with this, I dont know how to code for my required output in SQL,
问题描述
我的数据
-------
BID DEPT QTY
1 AAA 21
1 SSS 22
2 SSS 25
2 AAA 21
2 DDD 36
3 AAA 52 >
3 SSS 63
1 DDD 41
2 FFF 52
预期输出
----------------
BID DEPT QTY
1 AAA 21
SSS 22
DDD 41
2 SSS 25
AAA 21
DDD 36
FFF 52
3 AAA 52
SSS 63 < br $> b $ b
我尝试了什么:
我想了解更多信息sql,它的我的项目工作需要一些帮助这个
MY DATA
-------
BID DEPT QTY
1 AAA 21
1 SSS 22
2 SSS 25
2 AAA 21
2 DDD 36
3 AAA 52
3 SSS 63
1 DDD 41
2 FFF 52
EXPECTING OUTPUT
----------------
BID DEPT QTY
1 AAA 21
SSS 22
DDD 41
2 SSS 25
AAA 21
DDD 36
FFF 52
3 AAA 52
SSS 63
What I have tried:
am just want to learn more in sql, and its for my project work need some help with this
推荐答案
尝试
try
WITH CTE
AS
(
SELECT bid, dept, qty,
ROW_NUMBER() OVER(PARTITION BY bid ORDER BY bid) RowNo
FROM tblTest
)
SELECT
CASE RowNo
WHEN 1 THEN bid
ELSE null // null or empty, decide what you want to print for duplicate value
END AS bid
,dept, qty
FROM CTE
SELECT
NULLIF(bid,LAG(bid)OVER(ORDER BY bid)) AS BID,
DEPT,
QTY
FROM Test_table
这篇关于任何人都可以帮我这个,我不知道如何在SQL中编写我所需的输出,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!