我有一个像这样的数据库表:
citizen-gender-age-personid
uk female-35 -1
uk male -35 -1
de male -24 -2
gr female 15 -3
female 15 -3
ab male 20 -4
male 20 -4
ab female 21 -5
所以personid
可能有多个年龄或性别或公民或所有nullable
。我必须编写一个sql,结果必须只是所有personid.like
的一条记录:
uk female-35 -1
de male -24 -2
gr female 15 -3
ab male 20 -4
ab female 21 -5
答案 0 :(得分:0)
SELECT personid
,MAX(age) AS age
,MAX(gender) AS gender
,MAX(citizen) AS citizen
FROM TableName
GROUP BY personid;
答案 1 :(得分:0)
我找到了解决方案:
SELECT t.citizen, t.gender, t.age,count(distinct(personid)) FROM table1 t
,其中 rowid =(SELECT MAX(ROWID) 从 table1 B 哪里 t.personid = B.personid)group by t.citizen,t.gender,t.age