weixin_43078650 2021-06-26 23:32 采纳率: 0%
浏览 17

sql union有点长,怎么才能优化一下呢?

select r.id,
       r.pid,
       r.article_id,
       r.content,
       r.user_id,
       r.user_name,
       r.create_time,
       r2.id      bellow_id,
       r2.content bellow_content,
       null       likes_num,
       'sonreply' op_type
from cms_article_comment r
         left join cms_article_comment r2 on r.pid = r2.id
where r.pid is not null
  and r.pid != ''
union
select r.id, r.pid, r.article_id, r.content,
    r.user_id, r.user_name, r.create_time,
    p.id bellow_id, p.title bellow_content,
    (select count (*) from cms_comment_like where comment_id=r.id) likes_num,
    'articlereply' op_type
from cms_article_comment r
    left join cms_article p
on r.article_id=p.id
where r.pid is null or r.pid = ''
  • 写回答

1条回答 默认 最新

  • 饺子大魔王12138 优质创作者: 编程框架技术领域 2022-07-29 13:05
    关注

    不需要优化

    评论

报告相同问题?