日期:2014-05-16  浏览次数:20768 次

求一个SQL,对你来说很简单的,thanks
我使用以下查询SQL得到以下结果,


SELECT   o.submitid,c.paystatus
FROM   orderdetailsubmit   o   RIGHT   JOIN   customercard   c   ON   c.submitid=o.submitid;

+---------------+-----------+
|   submitid             |   paystatus   |
+---------------+-----------+
|   1181870193984   |   2                   |
|   1181870193984   |   3                   |
+---------------+-----------+

以下是我想得到的结果,就是submitid重复的情况,要把paystatus   的值连接起来
+---------------+-----------+
|   submitid             |   paystatus   |
+---------------+-----------+
|   1181870193984   |   2   ,3               |
+---------------+-----------+

------解决方案--------------------
SELECT o.submitid,concat(c.paystatus, ', ',p.paystatus)
FROM orderdetailsubmit o RIGHT JOIN customercard c ON c.submitid=o.submitid left join orderdetailsubmit p on o.submitid = p.submitid.