gpt4 book ai didi

mysql - 将这两个查询组合成一个 JOIN?

转载 作者:太空宇宙 更新时间:2023-11-03 11:09:21 24 4
gpt4 key购买 nike

这两个查询有效:

SELECT
u.id,
u.email,
COUNT(*) as Current
FROM
users u,
rounds cur
WHERE
cur.user = u.id
AND u.email = 'foo@foo.com'
GROUP BY cur.user;

SELECT
u.id,
u.email,
COUNT(*) as old
FROM
users u,
rounds__20120311_010951 old
WHERE
old.user = u.id
AND u.email = 'foo@foo.com'
GROUP BY old.user;

但我真的很想这样做:

SELECT
u.id,
u.email,
COUNT(old.*) as March11,
COUNT(cur.*) as Current
FROM
users u,
rounds cur,
rounds__20120311_010951 old
WHERE
old.user = u.id
AND cur.user = u.id
AND u.email = 'foo@foo.com'
GROUP BY old.user, cur.user

我认为语法错误来自这个 COUNT(old.*) 但我不确定。

是否可以组合这些查询?

最佳答案

使用 GROUP BY u.id, u.email。然后,在您的选择中,使用 COUNT(old.id)COUNT(cur.id)

关于mysql - 将这两个查询组合成一个 JOIN?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9721656/

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