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

sql 同一张表查询不同数据合并之后关联查询的更多相关文章

  1. sql语句-如何在SQL以一个表中的数据为条件据查询另一个表中的数据

    select *from 表2where 姓名 in (select 姓名from 表1where 条件) 这个就是用一个表的查询结果当作条件去查询另一个表的数据

  2. SQL两张表筛选相同数据和不同数据

    原文链接:http://www.cnblogs.com/onesmail/p/6148979.html 方法一: select distinct A.ID from A where A.ID not ...

  3. Sql server中如何将表A和表B的数据合并(乘积方式)

    sql server中如何将表A 和表B的数据合并成乘积方式,也就是说表A有2条数据,表B有3条数据,乘积后有6条数据, 这就要用到sql中的笛卡尔积方式了 1.什么是笛卡尔积 笛卡尔积在SQL中的实 ...

  4. mysql结构相同的三张表查询一条记录\将一张表中的数据插入另外一张表

    将一张表中的数据插入另外一张表 1.两张表结构相同 insert into 表1名称 select * from 表2名称 2.两张结构不相同的表 insert into 表1名称(列名1,列名2,列 ...

  5. SQLServer两张表筛选相同数据和不同数据

    概述 项目中经常会对两张数据库表的数据进行比较,选出相同的数据或者不同的数据.在SQL SERVER 2000中只能用Exists来判断,到了SQL SERVER 2005以后可以采用EXCEPT和I ...

  6. sql之将一个表中的数据注入另一个表中

    sql之将一个表中的数据注入另一个表中 需求:现有两张表t1,t2,现需要将t2的数据通过XZQHBM相同对应放入t1表中 t1: t2: 思路:left join 语句: select * from ...

  7. EF Core中,通过实体类向SQL Server数据库表中插入数据后,实体对象是如何得到数据库表中的默认值的

    我们使用EF Core的实体类向SQL Server数据库表中插入数据后,如果数据库表中有自增列或默认值列,那么EF Core的实体对象也会返回插入到数据库表中的默认值. 下面我们通过例子来展示,EF ...

  8. MYSQL基础操作之数据约束与关联查询

    一.MYSQL约束 1.默认值约束,当字段没有插入值的时候,mysql自动给该字段分配默认值. 默认值的字段允许为空. 对默认值字段也可以插入null. CREATE TABLE STUDENT( I ...

  9. 使用resultMap定义查询结果集,实现关联查询

    接下来介绍resultMap定义查询结果集,实现关联查询 1 首先在接口中定义操作的方法 public interface EmployeeMapperPlus { public Employee g ...

随机推荐

  1. FFmpeg里面的时间单位

    pts单位:1/90 ms(每个单位代表1/90 ms)  RTP包头有个STAMP 对于视频 STAMP/90 就是 PTS (毫秒) 对于音频 STAMP/samplerate * 1000 才是 ...

  2. spring cloud EurekaClient 多网卡 ip 配置 和 源码分析(转)

    https://blog.csdn.net/qq_30062125/article/details/83856655 1.前言对于spring cloud,各个服务实例需要注册到Eureka注册中心. ...

  3. golang在linux后台执行的方法

    go build ./index.go 会生成一个index的运行文件 nohup index & 后台运行index文件 killall index 你可能还要关闭index set GOA ...

  4. RobHess的SIFT代码解析之kd树

    平台:win10 x64 +VS 2015专业版 +opencv-2.4.11 + gtk_-bundle_2.24.10_win32 主要参考:1.代码:RobHess的SIFT源码:SIFT+KD ...

  5. Visual Studio中使用GitHub

    一.简介 GitHub被微软收购后免费开放了私人仓库,这对个人或小型团队来说简直是福音.GitHub高效免费,无论是团队代码管理还是DevOps都不再话下,特别是对于想要开放研究成果提高知名度的团队或 ...

  6. Redis主从、哨兵、集群

    主从 命名设置:>6380 slaveof 127.0.0.01 6379 slaveof on one----------配置:-- 注意一点: 一定开启rdb,不能使用aof从节点配置:主节 ...

  7. 实用: 将程序的内容写出到excel中

    pom <!-- 读取excel文件 --><dependency> <groupId>org.apache.poi</groupId> <art ...

  8. Python3学习笔记36-PEP8代码规范

    在使用PyCharm时,最右边会有波浪线警告提示代码不符合PEP8代码规范.记录一下犯的错和解决方式 PEP8是风格错误,而不是编码错误.只是为了让代码更具有阅读性. 1)block comment ...

  9. python模块 加密服务hashlib,hmac

    https://docs.python.org/zh-cn/3/library/hashlib.html hashlib --安全hash和消息摘要digest hmac -- keyed-Hashi ...

  10. Spring入门篇——第5章 Spring AOP基本概念

    第5章 Spring AOP基本概念 本章介绍Spring中AOP的基本概念和应用. 5-1 AOP基本概念及特点 5-2 配置切面aspect ref:引用另外一个Bean 5-3 配置切入点Poi ...