Browse Source

优化查询

liujunchi 2 years ago
parent
commit
539d23b843

+ 4 - 5
cooleshow-user/user-biz/src/main/resources/config/mybatis/MusicAlbumMapper.xml

@@ -44,15 +44,14 @@
             where find_in_set(mt.id_,t.album_tag_) and mt.del_flag_ = 0 and mt.state_ = 1) as musicTagNames
             where find_in_set(mt.id_,t.album_tag_) and mt.del_flag_ = 0 and mt.state_ = 1) as musicTagNames
         ,(select group_concat(s.name_) from subject s
         ,(select group_concat(s.name_) from subject s
         where find_in_set(s.id_,t.subject_id_) and s.del_flag_ = 0 ) as subjectNames
         where find_in_set(s.id_,t.subject_id_) and s.del_flag_ = 0 ) as subjectNames
-        , t1.num as musicSheetCount
-        ,t2.num as albumFavoriteCount
-        from music_album t
-        left join (select count(1) as num,amr.album_id_
+        ,(select count(1) as num
             from album_music_relate amr
             from album_music_relate amr
             join music_sheet ms on amr.music_sheet_id_ = ms.id_
             join music_sheet ms on amr.music_sheet_id_ = ms.id_
             left join sys_user su on su.id_ = ms.user_id_
             left join sys_user su on su.id_ = ms.user_id_
             where ms.del_flag_ = 0 and ms.state_ = 1 and ms.audit_status_ = 'PASS' and su.del_flag_ = 0
             where ms.del_flag_ = 0 and ms.state_ = 1 and ms.audit_status_ = 'PASS' and su.del_flag_ = 0
-        group by amr.album_id_) t1 on t1.album_id_ = t.id_
+            and amr.album_id_ = t.id_) as musicSheetCount
+        ,t2.num as albumFavoriteCount
+        from music_album t
         left join (select count(1) as num,af.album_id_ from album_favorite af
         left join (select count(1) as num,af.album_id_ from album_favorite af
             left join sys_user su on af.user_id_ = su.id_
             left join sys_user su on af.user_id_ = su.id_
             where su.del_flag_ = 0 group by af.album_id_
             where su.del_flag_ = 0 group by af.album_id_