mySQL INNER JOIN和UNION ALL一起

编程入门 行业动态 更新时间:2024-10-24 12:31:00
本文介绍了mySQL INNER JOIN和UNION ALL一起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个表,其中如果日期和类别"bar"匹配则对行进行分组,现在我需要对其他表进行 INNER JOIN 并使用 WHERE answer ='2'从该表开始,但我不知道该怎么做.

I have a table with rows that's grouped if the date and the category 'bar' matches, now I need to INNER JOIN these with another table and use a WHERE answer = '2' from that table, but I don't know how to do that.

SELECT category, date, client FROM sbs_events WHERE category <> 'bar' UNION ALL SELECT category, date, MIN(client) AS client FROM sbs_events WHERE category = 'bar' GROUP BY category, date

我制作了 SQL小提琴

我需要添加到小提琴中的东西是

The thing I need to add to the fiddle is

INNER JOIN sbs_userEvents ON sbs_events.id = sbs_userEvents.event_id WHERE answer = 2 AND user_id = 1

但是由于我已经有一个 WHERE category ='bar',所以我不知道如何添加它.

But since I already have a WHERE category = 'bar' I don't know how to add this.

推荐答案

SELECT category, date, client FROM sbs_events INNER JOIN sbs_userEvents ON sbs_events.id = sbs_userEvents.event_id WHERE category <> 'bar' AND answer = 2 AND user_id = 1 UNION ALL SELECT category, date, MIN(client) AS client FROM sbs_events INNER JOIN sbs_userEvents ON sbs_events.id = sbs_userEvents.event_id WHERE category = 'bar' AND answer = 2 AND user_id = 1 GROUP BY category, date

更多推荐

mySQL INNER JOIN和UNION ALL一起

本文发布于:2023-07-09 02:24:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1082882.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:mySQL   JOIN   UNION

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!