使用内部选择从3个表联接数据

时间:2019-03-04 14:32:24

标签: mysql sql

我有以下查询:

sudo xcode-select --reset 
sudo xcodebuild -license

我的问题是语法。 没有第二个选择

SELECT *, CONCAT('/uploads/profiles/', user_uuid, '.jpg') as profile_pic, (select count(*) from `good_reads_comments` b where a.id=b.parent_id) as child_post_count FROM `good_reads_comments` a, (select count(*) from `comment_likes` c where a.id=c.comment_id) as post_like_count FROM `comment_likes` a WHERE good_read_uuid='123456789' AND parent_id=0 ORDER BY d_date 查询工作正常。

请帮助

2 个答案:

答案 0 :(得分:1)

我认为您需要以下

 SELECT *, CONCAT('/uploads/profiles/', user_uuid, '.jpg') as profile_pic,
 (select count(*) from `good_reads_comments` b where a.id=b.parent_id) as 
child_post_count,
(select count(*) from `comment_likes` c where a.id=c.comment_id) as  post_like_count    
    FROM `comment_likes` a           
    WHERE good_read_uuid='123456789' 
    AND parent_id=0 
    ORDER BY d_date

答案 1 :(得分:1)

尝试

SELECT *, 
   CONCAT('/uploads/profiles/', user_uuid, '.jpg') as profile_pic, 
   count(b.parent_id) as child_post_count, 
   count(c.comment_id) from comment_likes as post_like_count 
FROM good_reads_comments a 
JOIN good_reads_comments b on a.id = b.parent_id 
JOIN comment_likes on a.id = c.comment_id 
WHERE good_read_uuid='123456789' 
   AND parent_id=0 
ORDER BY d_date