gpt4 book ai didi

mysql - 根据事件和响应代码计算邀请响应

转载 作者:可可西里 更新时间:2023-11-01 08:27:30 25 4
gpt4 key购买 nike

我有这张表用于响应代码: enter image description here

这张表用于邀请: enter image description here

到目前为止,我的查询给出了这个: enter image description here

虽然我想实现这个: enter image description here

我的查询:

SELECT 
i.eventId
,code.responseCode
,COUNT(i.attendeeResponse) responseCount
FROM invitations i
LEFT JOIN response_codes code
ON code.responseCode = i.attendeeResponse
GROUP BY i.eventId, code.responseCode, i.attendeeResponse;

SQLFiddle

最佳答案

首先需要构造所有eventIdresponseCode的笛卡尔积(可以无条件join实现) :

select c.eventId
, c.responseCode
, count( i.attendeeResponse ) as responseCount
from ( select distinct t1.responseCode
, t2.eventId
from `response_codes` t1
join `invitations` t2 ) c
left join `invitations` i on c.responseCode = i.attendeeResponse and c.eventId = i.eventId
group by c.eventId, c.responseCode;

SQLFiddle

关于mysql - 根据事件和响应代码计算邀请响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33977241/

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