当前方法:
当前查询1
SELECT
a.user,ui.contact_fname, ui.contact_lname,a.uid, COALESCE(pu.name,'N/A') AS UserPolicy,COALESCE(count(ea.user_ack),0) AS ack_count
FROM master_access.accounts a
RIGHT JOIN master_events.events_cleared ea ON a.uid=ea.user_ack
INNER JOIN master_biz.user_information as ui on ui.uid=a.uid
LEFT JOIN `master`.policies_users pu ON (a.template_id=pu.policy_id AND a.template_id!=0)
WHERE YEAR(ea.date_ack)=YEAR(NOW()) and MONTH(ea.date_ack)=10 and a.uid in (120,119,125,128,123,117,122,118,121,127)
GROUP BY a.user
ORDER BY COUNT(ea.user_ack) DESC
当前查询1 -输出
当前查询2
SELECT
a.user,ui.contact_fname, ui.contact_lname,a.uid, COALESCE(pu.name,'N/A') AS UserPolicy,COALESCE(count(ea.user_ack),0) AS ack_count
FROM master_access.accounts a
RIGHT JOIN master_events.events_active ea ON a.uid=ea.user_ack
INNER JOIN master_biz.user_information as ui on ui.uid=a.uid
LEFT JOIN `master`.policies_users pu ON (a.template_id=pu.policy_id AND a.template_id!=0)
WHERE YEAR(ea.date_ack)=YEAR(NOW()) and MONTH(ea.date_ack)=10 and a.uid in (120,119,125,128,123,117,122,118,121,127)
GROUP BY a.user
ORDER BY COUNT(ea.user_ack) DESC
当前查询2 -输出
所需输出
基本上是将两个输出添加到一个视图中,如果“用户ID”匹配,则添加值。有人可以帮助完成此操作吗?
1条答案
按热度按时间bkhjykvo1#
以
master_access.accounts
表为基表。将两个查询都左联接到该表。筛选至少有一个子查询行匹配的行。生成输出列列表。在输出列表中-取不带表别名的
uid
列,而不是所有其他列。