gpt4 book ai didi

mysql - 如何在 SQL 中显示每个类别属于某个类别的数字或行

转载 作者:行者123 更新时间:2023-11-30 01:13:20 28 4
gpt4 key购买 nike

我有一个视频类别表和一个视频录制表。视频类别中的列是 id 和 cname,视频录制中有一个类别列。我想显示每个类别有多少视频录制。

我已经尝试过

select vc.cname, count(*) as catcount
from video_categories vc, video_recordings vr
where vc.cname = vr.category
group by vc.id

但这仅返回 id 为 0 的第一个类别的录音数量。我需要它们来显示所有内容。

我创建了这样的表格

Video_Recordings (
recording_id,
director,
title,
category,
image_name,
duration,
rating,
year_released,
price,
stock_count
);

Video_Categories (
id,
name
);

Video_Actors (
id,
name,
recording_id
);

使用正确的数据类型,然后我加载它们

Load Data local Infile
' D:/files...' into table
video_recodrings fields terminated by '\t' lines terminated by '\n';

当我这样做并检查表格时,表格是正确的。

最佳答案

您必须按 vc.name 将它们分组

选择 vc.cname, count(*) 作为 catcount
来自 video_categories 作为 vc,video_recordings 作为 vr
其中 vc.cname = vr.category
按 vc.name 分组

关于mysql - 如何在 SQL 中显示每个类别属于某个类别的数字或行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19289433/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com