gpt4 book ai didi

mysql - 加入四张 table

转载 作者:行者123 更新时间:2023-11-29 02:11:16 27 4
gpt4 key购买 nike

我查看并尝试了各种示例,但仍然没有得到我需要的结果。

有一个名为“item”的表,其中包含有关媒体(书籍、视频、mp3 等)的元数据

和一个包含视频 URL 的表“item_format”

和带有“类别”的表格

和一个名为“categories_item”的关系

我想找到按类别分类的 YouTube 视频中的所有记录。因此,如果您查找“育儿”,我们会列出一个 YouTube 列表和标题。

parenting   https://youtube/v/K8cJKirMo-A     Love is The Tey  
https://youtube/v/uodqINpEC_w Discipline
https://youtube/v/Ko-ZboCzR64 Become Her Friend

等等,列出所有分配的类别

item.media-type LIKE '%video%'

 item
===============
item_id media_type title
1 video/teachings Discipline
2 video/news December Update
3 video/landscape Quad Copter Noni Field

item_format
=================
item_format_id item_id format
1 2 https://youtube/v/K8cJKirMo-A
2 4 https://youtube/v/uodqINpEC_w

category
=================
category_id item_id name
1 2 parenting
2 4 ethics

category_item # the bridging table between item/category
=================
category_item_id category_id item_id
1 2 2
2 4 3

我尝试过这样的事情但出现错误,坦率地说我的深度

select item.title, item_format.format
from item i
left join item_format if
on i.item_id = if.item_id
left join category_item ci
on i.item_id = ci.item_id
left join category c
on ci.category_id = category_id
where i.media_type LIKE '%video5'
order by c.name

我无法到达一垒

“字段列表”#line 1 中的未知列“item.title”

最佳答案

您的查询没问题,但需要稍做改动。您使用表别名。在第一行只使用表别名而不是表名

select i.title, if.format,c.name
from item i
left join item_format if on (i.item_id = if.item_id)
left join category_item ci on (i.item_id = ci.item_id)
left join category c on (ci.category_id = c.category_id)
where i.media_type LIKE '%video5'
order by c.name

关于mysql - 加入四张 table ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51869429/

27 4 0