前 10 个名字 - 多个表(联合)- SQL
Top 10 Firstnames - Multiple tables (Union) - SQL
我想要数据库中最常出现的前 10 个名字,其中有几个 table
对于 1 table:
SELECT n.prenomsNouveauNe, COUNT(*)
FROM <database>.naissance n
GROUP BY n.prenomsNouveauNe
ORDER BY COUNT(*) DESC
LIMIT 10
对于多个 tables:
(
SELECT
n.prenomNouveauNe, COUNT(*)
FROM
<database>.naissance n
group by n.prenomsNouveauNe
)
UNION ALL
(
SELECT
d.prenomDefunt, count(*)
FROM
<database>.deces d
group by d.prenomDefunt
)
但是我进不了前10...
select theName, count(*) as cnt from
(
SELECT
n.prenomNouveauNe as theName
FROM
genearmor.naissance n
UNION ALL
SELECT
d.prenomDefunt as theName
FROM
<database>.deces d
) tmp
group by theName
order by count(*) desc
limit 10;
我想要数据库中最常出现的前 10 个名字,其中有几个 table
对于 1 table:
SELECT n.prenomsNouveauNe, COUNT(*)
FROM <database>.naissance n
GROUP BY n.prenomsNouveauNe
ORDER BY COUNT(*) DESC
LIMIT 10
对于多个 tables:
(
SELECT
n.prenomNouveauNe, COUNT(*)
FROM
<database>.naissance n
group by n.prenomsNouveauNe
)
UNION ALL
(
SELECT
d.prenomDefunt, count(*)
FROM
<database>.deces d
group by d.prenomDefunt
)
但是我进不了前10...
select theName, count(*) as cnt from
(
SELECT
n.prenomNouveauNe as theName
FROM
genearmor.naissance n
UNION ALL
SELECT
d.prenomDefunt as theName
FROM
<database>.deces d
) tmp
group by theName
order by count(*) desc
limit 10;