正确的 SQL 查询是什么


What is the correct SQL query for this?

>我有一个存储所有用户活动的表。我称之为带有字段的"会话"表:

+--------------------------------------------------+
|  id   |  content_type  |  content_id  |  action  |
+--------------------------------------------------+

content_type可以是 1=视频,2=幻灯片,3=表单,4=调查,5=网站,6=互动

content_id是实际内容的 ID。例如,我有"网站"表

+---------------------------------------------+
|  id   |   name   |           url            |
+------------------+--------------------------+
|   3   |  Google  |  http://www.google.com/  |
+------------------+--------------------------+

在应用程序上,用户访问了 google.com 网站。将存储在"会话"表上的是:

+----------------------------------------------------------+
|  content_type  |  content_id  |          action          |
+----------------------------------------------------------+
|        5       |       3      |  Visited Google Website  |
+----------------------------------------------------------+

"网站"(或表单、视频等(表的这些内容可以附加或标记到多个产品组。

我通过将它存储到名为"attached_product_groups"的表中来做到这一点

在该表上,我有字段:

+----------------------------------------------------+
|  content_type  |  content_id  |  product_group_id  |
+----------------------------------------------------+

例如,我必须从"product_groups"表中将 3 个产品组附加到 google.com 网站:

+----------------------------+
|  id  |        name         |
+----------------------------+
|  3   |  Mobile             |
+----------------------------+
|  8   |  Social Networking  |
+----------------------------+
|  9   |  Adsense            |
+----------------------------+

"attached_product_groups"表将存储:

+----------------------------------------------------+
|  content_type  |  content_id  |  product_group_id  |
+----------------------------------------------------+
|       5        |      3       |         3          |
+----------------------------------------------------+
|       5        |      3       |         8          |
+----------------------------------------------------+
|       5        |      3       |         9          |
+----------------------------------------------------+

现在我的问题是,如何选择cetain产品组的所有"会话"日志?

鉴于在我的应用程序上,我有一个产品组的下拉列表。

非常感谢您帮助像我这样的初学者。 :)

可能是在查询下方工作,以根据内容 ID 显示网站的网址和产品

从会话中选择sessions.content_id,网络名称,P.名称 会话,网站网站,产品P,attached_product_groups PG其中 sessions.content_id=网络。id 和 p.id=pg.product_group_id