博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
sql 同一张表查询不同数据合并之后关联查询
阅读量:4489 次
发布时间:2019-06-08

本文共 4507 字,大约阅读时间需要 15 分钟。

SELECT    t.articleId articleId,    comments.`comments` parentComment,    t.commentId commentsId,    comments.`id` parentId,    comments.`parent_name` parentName,    t.userId userId,    comments.`group_id` groupId,    t.thisComment comments,    comments.`prase_num` praseNum,    comments.`create_time` createTime,    comments.`update_time` updateTime,    comments.`user_image` userImage,    comments.`recommend`,    comments.`user_type` userType,    t.userName userName,    article.`title`,    article.`plain_txt` plainTxt,    article.`coefficient_original` coefficientOriginal,    article.`first_issue` firstIssue,    article.`grade_id` gradeId,    article.`author`,    article.`status`,    article.`share_status` shareStatus,    article.`cover_sort` coverSort,    article.`cover_img_url` coverImgUrl,    article.`is_show` isShow,    article.`timing_publish_time` timingPublishTime,    article.`note`,    article.`settop_type` settopType,    article.`top_begin_time` topBeginTime,    article.`top_end_time` topEndTime,    article.`published_type` publishedType,    article.`review_time` reviewTime,    article.`submit_time` submitTime,    bussinessAmount.id 'bussinessId',    ifnull( bussinessAmount.reading_amount_in, 0 ) 'readingAmountIn',    ifnull( bussinessAmount.reading_amount_out, 0 ) 'readingAmountOut',    ifnull( bussinessAmount.comment_amount, 0 ) 'commentAmount' FROM                            (                            SELECT                                nideshop_comments.`parent_id` parentId,                                nideshop_comments.`id` commentId,                                nideshop_comments.`article_id` articleId,                                nideshop_comments.`comments` thisComment,                                nideshop_comments.`user_id` userId,                                nideshop_comments.`user_name` userName                            FROM                                nideshop_comments                             WHERE                                1 = 1                                  AND nideshop_comments.`user_id` =   544                                AND nideshop_comments.`STATUS` = 1                         Union All                             SELECT                                nideshop_comments.`parent_id` parentId,                                nideshop_comments.`id` commentId,                                nideshop_comments.`article_id` articleId,                                nideshop_comments.`comments` thisComment,                                nideshop_comments.`user_id` userId,                                nideshop_comments.`user_name` userName                            FROM                                nideshop_comments                             WHERE                                1 = 1                                  AND nideshop_comments.`STATUS` = 1                                 AND nideshop_comments.`parent_id` in (                                                                                                             SELECT                                                                                                                nideshop_comments.`id` commentId                                                                                                            FROM                                                                                                                nideshop_comments                                                                                                             WHERE                                                                                                                1 = 1                                                                                                                  AND nideshop_comments.`user_id` =   544                                                                                                                AND nideshop_comments.`STATUS` = 1                                                                                                             )                                                               ) t    INNER JOIN nideshop_comments comments ON t.parentId = comments.`id`    LEFT JOIN nideshop_article article ON article.id = t.articleId    LEFT JOIN nideshop_article_bussiness_amount bussinessAmount ON article.id = bussinessAmount.article_id WHERE    comments.`STATUS` = 1 ORDER BY    comments.create_time DESC

 

转载于:https://www.cnblogs.com/xiaoshen666/p/10773929.html

你可能感兴趣的文章
《Windows核心编程》第十一章——线程池
查看>>
内存优化
查看>>
数据结构:单链表
查看>>
Go socket
查看>>
无法连接asp.net development server
查看>>
BETTER SUPPORT FOR FUNCTIONAL PROGRAMMING IN ANGULAR 2
查看>>
微信小程序tab栏切换
查看>>
windows pm2 开机启动
查看>>
Flask - 特殊装饰器 和 Flask工作结构模式(FBV, CBV)
查看>>
node.js环境搭建以及入门级hello程序
查看>>
LightOJ1282 - Leading and Trailing(快速幂+数学)
查看>>
【mysql】关于checkpoint机制
查看>>
nginx总结
查看>>
如何设定ASH buffer大小
查看>>
改变调用函数的this指针方向
查看>>
【转】mq
查看>>
Java基础知识学习07-抽象类、接口、多态
查看>>
Oracle学习笔记之七(用户管理、角色与权限、导入导出等)
查看>>
linux如何挂载windows下的共享文件
查看>>
常用正则表达式
查看>>