简体   繁体   English

有关分离返回结果的SQL查询帮助

[英]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. 示例:在电话表上,某人有两个电话号码,SQL会给我同一个人的第二行,该行具有不同的电话号码,而不是第二列。 What query do I use to check if person_id appears more than once insert second row of data in a separate column? 我使用哪种查询来检查person_id是否出现多次,请在单独的列中插入第二行数据?

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. 该查询将返回所有多次插入同一person_id键的记录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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