sqlite 获取具有相同列值的记录 [英] sqlite get records with same column value

查看:59
本文介绍了sqlite 获取具有相同列值的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含姓氏、名字、部门的 SQLite 数据库,我需要进行查询以显示任何具有相同名字和姓名的人.姓氏.我发现以下语句据说可以对单个字段执行我想要的操作,但是当我尝试使用它来提取姓氏相同的所有记录时,它似乎对我不起作用.我该怎么做?

I have a SQLite DB that has people LastName, FirstName, Department and I need to make a query that shows me any people with the same First & Last Names. I've found the following statement that supposedly does what I want for a single field, however it doesn't seem to work for me when I try to use it to pull all records with just the last name being the same. How can I do this?

Select myField From myTable Group by myField Where count(myField)>1 

推荐答案

尝试:

Select 
    firstname,LastName,Count(*)
    From myTable 
    Group by firstname,LastName 
    HAVING Count(*)>1

GROUP BY 合并命名值相同的行.
HAVING 删除不满足条件的组.

GROUP BY combines rows where the named values are the same.
HAVING removes groups that do not meet the condition.

上述查询将列出名字和姓氏,以及所有实际有重复的名字/姓氏的重复计数.

The above query will list the first and last names, along with a count of duplicates for all first/last names that actually have duplicates.

这篇关于sqlite 获取具有相同列值的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆