根据mysql发送的通知的发生情况查找用户
我正在尝试获取用户对通知模板id的计数。 表示如果用户不止一次以通知模板id 56作为目标 例如 我正在尝试的查询是:根据mysql发送的通知的发生情况查找用户,mysql,sql,Mysql,Sql,我正在尝试获取用户对通知模板id的计数。 表示如果用户不止一次以通知模板id 56作为目标 例如 我正在尝试的查询是: SELECT user_id, notification_template_id, count(notification_template_id) AS cnt FROM user_notifications GROUP BY user_id; 但它只显示每个用户的通知总数。sql是: SELECT user_id,
SELECT
user_id,
notification_template_id,
count(notification_template_id) AS cnt
FROM
user_notifications
GROUP BY
user_id;
但它只显示每个用户的通知总数。sql是:
SELECT
user_id,
notification_template_id,
count(notification_template_id) AS count
FROM
user_notifications
GROUP BY
user_id,
notification_template_id;
只需按通知模板id分组,而不仅仅是按用户id分组。
SELECT
user_id,
notification_template_id,
count(notification_template_id) AS count
FROM
user_notifications
GROUP BY
user_id,
notification_template_id;