gpt4 book ai didi

mysql - 将两个查询放入同一个表中(按日期分组)

转载 作者:行者123 更新时间:2023-11-29 05:14:03 25 4
gpt4 key购买 nike

我正在使用 MySQL 数据库尝试我的第一个 select 语句,当您不知道要用 google 搜索什么时,这非常困难。

所以这就是我想要做的,我有两个问题:

select date(server_time) as d, count(*) as x
from table_A, table_B
where date(server_time) >= '2015-07-17'
and table_A.id = table_B.id
and idname is not null
and idurl is not null
group by date(server_time)

 select date(server_time) as d, count(*) as y
from table_A
where date(sever_time) >= '2015-07-17'
group by date(server_time)

我想要实现的是将两个计数列与日期放在一起:

d               x     y
-------------|-----|-------
2015-07-17 | 3 | 20
2015-07-18 | 2 | 50
2015-07-19 | 7 | 10
-------------|-----|-------

我一直在使用 UNIONSELECT(SELECT count) 等,但没有成功。

最佳答案

SELECT date(server_time) AS d, 
count(*) AS x,
(SELECT y
FROM (SELECT date(server_time) AS d,
id,
count(*) AS y
FROM table_A
WHERE date(sever_time) >= '2015-07-17'
GROUP BY date(server_time)) sub
WHERE SUB.id = a.id) AS y
FROM table_A a
INNER JOIN table_B b ON a.id = b.id
WHERE date(server_time) >= '2015-07-17'
AND idname IS NOT NULL
AND idurl IS NOT NULL
GROUP BY date(server_time)

关于mysql - 将两个查询放入同一个表中(按日期分组),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35574840/

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