SQLize Online / PHPize Online

A A A
Share   Donate   Blog   Popular
Copy Format Clear
Create table Agents ( Agent char(1), [Location] int ); insert into Agents VALUES ('A', 1), ('A', 2), ('A', 6), ('B', 3), ('B', 4), ('C', 1), ('C', 4), ('C', 5); select t.Agent, STRING_AGG(t.Location, ',') WITHIN GROUP (ORDER BY Location ASC) as Locations from ( select Agent, Location, rank() over (partition by [Location] order by Agent) as rnk from Agents ) as t --will return agents with distinct locations, because they have the rank equals to 1 where t.rnk = 1 group by t.Agent;
Stuck with a problem? Need help? Ask professionals on our Telegram channel!
Join the channel
Your quersion is posted.
Join our Telegram channel and get answers.
Send
Copy