mysql语句group concat 语句,以及连接排序

SELECT
  p_result.id,
  p_result.username,
  p_result.userid,
  p_result.nc,
  p_result.icon,
  p_result.time,
  p_result.content,
  i.small_pics,
  i.big_pics,
  IF(
    ag_table.ag_count IS NULL,
    0,
    ag_table.ag_count
  ) AS dianz,
  agreements_table.dianz_userids AS dianz_userids,
  agreements_table.dianz_users AS dianz_users,
  IF(
    c_table.c_count IS NULL,
    0,
    c_table.c_count
  ) AS pinglun,
  IF(
    re_table.re_count IS NULL,
    0,
    re_table.re_count
  ) AS zhuanfa,
  comments_table.comments,
  p_result.evaluation,
  p_result.explosure,
  p_result.status
FROM
  (SELECT
    p.id,
    p.content AS content,
    p.create_time AS TIME,
    u.id AS userid,
    u.username,
    u.nicheng AS nc,
    CONCAT(
      'http://192.168.15.64:8090/epservice/image/',
      u.photo_path,
      '.144x144.jpg'
    ) AS icon,
    p.evaluation,
    p.explosure,
    p.status
  FROM
    epimap.ep_living_posts p,
    epimap.ep_user_info u
  WHERE p.userid = u.id
    AND p.province = '河南省'
    AND p.city = '郑州') AS p_result
  LEFT JOIN
    (SELECT
      id,
      postid,
      GROUP_CONCAT(
        CONCAT(
          'http://192.168.15.64:8090/epservice/',
          path
        ) SEPARATOR '#'
      ) AS big_pics,
      GROUP_CONCAT(
        CONCAT(
          'http://192.168.15.64:8090/epservice/',
          path,
          '.240x240.jpg'
        ) SEPARATOR '#'
      ) AS small_pics
    FROM
      ep_living_images
    GROUP BY postid) AS i
    ON i.postid = p_result.id
  LEFT JOIN
    (SELECT
      postid,
      COUNT(*) AS c_count
    FROM
      epimap.ep_living_comments c
    GROUP BY postid) AS c_table
    ON p_result.id = c_table.postid
  LEFT JOIN
    (SELECT
      postid,
      COUNT(*) AS re_count
    FROM
      epimap.ep_living_reposts re
    GROUP BY postid) AS re_table
    ON p_result.id = re_table.postid
  LEFT JOIN
    (SELECT
      postid,
      COUNT(*) AS ag_count
    FROM
      epimap.ep_living_agreements ag
    GROUP BY postid) AS ag_table
    ON p_result.id = ag_table.postid
  LEFT JOIN
    (SELECT
      postid,
      GROUP_CONCAT(ep_user_info.id SEPARATOR '#') AS dianz_userids,
      GROUP_CONCAT(username SEPARATOR '#') AS dianz_users
    FROM
      ep_living_agreements,
      ep_user_info
    WHERE ep_living_agreements.userid = ep_user_info.id
    GROUP BY postid
    ORDER BY ep_living_agreements.`agreetime` DESC) AS agreements_table
    ON agreements_table.postid = p_result.id
  LEFT JOIN
    (SELECT
      postid,
      username,
      GROUP_CONCAT(
        CONCAT(
          ep_user_info.id,
          '#',
          ep_living_comments.id,
          '#',
          username,
          '#',
          ep_living_comments.create_time,
          '#',
          content
        ) ORDER BY ep_living_comments.id DESC SEPARATOR '╬'
      ) AS comments
    FROM
      ep_living_comments,
      ep_user_info
    WHERE ep_living_comments.userid = ep_user_info.id
    GROUP BY postid
    ORDER BY ep_living_comments.`create_time` DESC) AS comments_table
    ON comments_table.postid = p_result.id
ORDER BY p_result.time DESC

LIMIT 0, 6



评论列值为:

393#864#wantingting#2014-06-23 14:48#排序成功╬393#863#wantingting#2014-06-23 14:48#排序2╬393#862#wantingting#2014-06-23 14:47#排序1

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值