简体   繁体   中英

SQL Query Help on separating return result

Example: On the phone table, someone has two phone number SQL would give me the a second row of the same person with different phone number instead of second column. What query do I use to check if person_id appears more than once insert second row of data in a separate column?

I hope this make sense. Thanks in advance!

Try something like this:

SELECT person_id, COUNT(person_id) AS 'PersonIDCount' FROM phone_table
GROUP BY person_id
HAVING COUNT(person_id) > 1

The query will return all records where the same person_id key was inserted more than once.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM