【发布时间】:2021-10-14 07:23:56
【问题描述】:
我尝试通过 join 连接两个表并将它们分组以获取计数。但不幸的是,这两个表没有任何共同的加入价值(或者我误解了解决方案)。
select date_format(check_in.date,'%M') as Month, count(check_in.Id) as checkInCount
from check_in
group by month(check_in.date);
| Month | checkInCount |
|---|---|
| July | 1 |
| October | 2 |
这是第一张桌子。
select date_format(reservation.date,'%M') as Month, count(reservation.id) as reserveCount
from reservation
group by month(reservation.date);
| Month | reserveCount |
|---|---|
| July | 3 |
| October | 5 |
这是第二张桌子。 我想在一张表中显示这两个表。
| Month | checkInCount | reserveCount |
|---|---|---|
| July | 1 | 3 |
| October | 2 | 5 |
感谢您尝试这个,如果这太简单了,我们很抱歉。
【问题讨论】:
-
将这些查询作为 FROM 中的子查询,按月加入。