gpt4 book ai didi

mysql - 如何在 MySQL 2 中连接多个表?

转载 作者:搜寻专家 更新时间:2023-10-30 22:10:35 25 4
gpt4 key购买 nike

我想看一个公民的全名

reportBasket,reportNoBasket 表中的 notifyEmployee ='1'

AND reportNoBasket.groupEmail 不为空

并且计算来自 reportBasket 的电子邮件,citizenEmail reportNOBasket 在一个计数器中

表格:

citizen(email, firstname,lastname)

reportBasket(email,notifyEmployee)

reportNoBasket(citizenEmail, notifyEmployee , groupEmail)

之前 我代表我的查询以这种方式显示他们的电子邮件,它运行良好:

SELECT email,count(email) as email_count 
FROM (
SELECT email
FROM reportBasket
WHERE notifyEmployee='1'
UNION ALL
SELECT citizenEmail
FROM reportNoBasket
WHERE notifyEmployee='1'
) as T
GROUP BY email
ORDER BY email ASC

但现在我想显示公民的全名而不是电子邮件地址 concat(citizen.firstname,' 'citizen.lastname)

如何加入?

最佳答案

尝试这样的事情:

SELECT concat(firstname, ' ', lastname), count(*) as citizen_count 
FROM (
SELECT c.firstname, c.lastname
FROM reportBasket rb
JOIN citizen c
ON rb.email = c.email
WHERE notifyEmployee='1'
UNION ALL
SELECT c.firstname, c.lastname
FROM reportNoBasket rnb
JOIN citizen c
ON rnb.citizenEmail = c.email
WHERE notifyEmployee='1'
) as T
GROUP BY firstname, lastname
ORDER BY firstname, lastname ASC

关于mysql - 如何在 MySQL 2 中连接多个表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30936816/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com