Home > database > Two fields A and B, no matter A=1, B=2, B=2, A=1 group by one article
Two fields A and B, no matter A=1, B=2, B=2, A=1 group by one article
Time:04-22
As title, I do not know can use a query, it is ok to take out a, please tall person to give directions, thank you very much!
Such as
ID A, B 1 1 2 2 2 1 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- After the search, just a record 1 1 2
CodePudding user response:
Top 1??????
CodePudding user response:
select * from top 1 yourtable
CodePudding user response:
with t as ( Select 1 as id, 1 as a, as 2 b Union all Select 2, 2, 1 ) Select * from t a Cross the apply ( Select ( Select the ', '+ convert (varchar, val) The from t Unpivot (val for col in (a, b)) p Where id=Anderson d The order by val For XML path (' ') ) as group_val B)
Don't know whether you have this idea, group_val same that all values are the same