我正试图找到特定用户的录像记录。
下面是三个相关表格:
CREATE TABLE `userprofile_userprofile` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`full_name` varchar(100) NOT NULL,
...
)
CREATE TABLE `userprofile_videoinfo` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(256) NOT NULL,
`uploaded_by_id` int(11) NOT NULL,
...
KEY `userprofile_videoinfo_e43a31e7` (`uploaded_by_id`),
CONSTRAINT `uploaded_by_id_refs_id_492ba9396be0968c` FOREIGN KEY (`uploaded_by_id`) REFERENCES `userprofile_userprofile` (`id`)
)
CREATE TABLE `userprofile_videocredit` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`video_id` int(11) NOT NULL,
`profile_id` int(11) DEFAULT NULL,
KEY `userprofile_videocredit_fa26288c` (`video_id`),
KEY `userprofile_videocredit_141c6eec` (`profile_id`),
CONSTRAINT `profile_id_refs_id_31fc4a6405dffd9f` FOREIGN KEY (`profile_id`) REFERENCES `userprofile_userprofile` (`id`),
CONSTRAINT `video_id_refs_id_4dcff2eeed362a80` FOREIGN KEY (`video_id`) REFERENCES `userprofile_videoinfo` (`id`)
)
www.un.org/Depts/DGACM/index_french.htm 表格是当用户上载录像时,他会收到“上载”清单。 www.un.org/Depts/DGACM/index_french.htm 表格是某一影片的所有信用额。 它完全独立于上载电影(即,一个用户可以在不自信的情况下上载录像,一个用户可以被录入他未上载的录像)。
在试图找到视频会议时,一个用户被记在册,我想发现:
# videos a user has uploaded + # of non duplicate-video credits uploaded by others
举例来说:如果用户上载5个录像带:
VideoME1, VideoME2, VideoME3, VideoME4, and VideoME5
(total = 5 videos [`videoinfo.uploaded_by_id`])
并且有以下录像:
VideoME1 (4 credits - director, writer, editor, choreographer)
VideoME2 (1 credit)
VideoOTHER1 (2 credits - writer, editor)
VideoOTHER2 (1 credit - writer)
(total = 8 video credits [`videocredit.profile_id`])
COUNT应为5(上载的图像)+2(由他人上载的非复制视频分录)=7. 如果用户没有录像分录,它应=0(即)。 LEFT OU JOIN
。
我已能够看到每个上载/认证的UNTS,但能够说明如何将这两者合并起来并清除重复。 我需要做些什么? 谢谢。
顺便提一下,这是我目前对每个(个人)委员会的看法:
mysql> SELECT full_name, v.video_id, COUNT(DISTINCT v.video_id) as cnt
-> FROM userprofile_userprofile u LEFT OUTER JOIN userprofile_videocredit v
-> ON u.id = V.profile_id
-> GROUP BY full_name
-> ORDER BY cnt DESC;
mysql> SELECT full_name, v.id, COUNT(v.uploaded_by_id) as cnt
-> FROM userprofile_userprofile u LEFT OUTER JOIN userprofile_videoinfo v
-> ON u.id = v.uploaded_by_id
-> GROUP BY full_name
-> ORDER BY cnt DESC;