SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      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 Agent, STRING_AGG([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 Agent
Stuck with a problem? Got Error? Ask ChatGPT!
Copy Clear