如何获得具有不同列值的多个行值 [英] How to get multiple row values having distinct column value
问题描述
我的表''patientdata''包含三列fname,lname和loc中的患者数据。
我希望有一个查询,显示哪些患者在多个地点被诊断出来。
这是样品表:
fname lname loc
tom hanks mi
tom hanks ca
jon trevolta nj
jon trevolta nj
tom hanks mi
jim kerry md
答案应该是:
tom hanks mi
tom hanks ca
提前致谢
Chintan
Hi,
I have table ''patientdata'' consisting of patient data in three columns fname, lname and loc.
I want to have a query that shows which of these patients were diagnosed in more than one location.
Here is sample table:
fname lname loc
tom hanks mi
tom hanks ca
jon trevolta nj
jon trevolta nj
tom hanks mi
jim kerry md
Answer should be:
tom hanks mi
tom hanks ca
Thanks in advance
Chintan
推荐答案
你可以使用一个不同的计数查询名字和姓氏。任何计数大于1的东西都是你要找的结果。如果你绝对必须拥有这些位置,那么你可以在from子句中对它进行子查询。
You could use a count distinct query that groups by the first name and last name. Anything having a count greater than 1 would be the results you''re looking for. If you absolutely have to have the locations as well, then you could subquery it in the from clause.
我有什么方法可以在一个查询中完成这个
Is there any way I can accomplish this in one single query
这是我不想要不同的fname或lname,但我想要相同名称的不同loc
And here is the thing I dont want distinct fname or lname but I want distinct loc for same names
这篇关于如何获得具有不同列值的多个行值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!