我如何利用MySQL来计算一个LEFT JOIN?
我有两张表格,有时评级表没有照片的评级,因此我认为需要LEFT JOIN,但我还有一份COUNT声明。
<>光线>
id name src
1 car bmw.jpg
2 bike baracuda.jpg
<>Loves (picid is foreign key withphos id)
id picid ratersip
4 1 81.0.0.0
6 1 84.0.0.0
7 2 81.0.0.0
这里,用户只能把自己的图像与知识产权相加。
我想按照最高评级合并两个表格。 新表格
<><>Combined
id name src picid
1 car bmw.jpg 1
2 bike baracuda.jpg 2
(bmw)
MySQL代码:
SELECT * FROM photos
LEFT JOIN ON photos.id=loves.picid
ORDER BY COUNT (picid);
www.un.org/Depts/DGACM/index_spanish.htm 我的《公共卫生法》:。
$sqlcount = "SELECT p . *
FROM `pics` p
LEFT JOIN (
SELECT `loves`.`picid`, count( 1 ) AS piccount
FROM `loves`
GROUP BY `loves`.`picid`
)l ON p.`id` = l.`picid`
ORDER BY coalesce( l.piccount, 0 ) DESC";
$pics = mysql_query($sqlcount);