如何分组两列?
我当前的查询:
SELECT
MIN(DATE_FORMAT(t.date_booked, '%Y-%m-%d')) as date,
MIN(DATE_FORMAT(i.inv_date, '%Y-%m-%d')) as invdate,
FROM Hours as t
LEFT JOIN Proj as p
ON t.pid = p.id
LEFT JOIN inv_c as c
ON t.pid = c.pid
LEFT JOIN inv as i
ON c.pid = i.id
WHERE t.pid = "2005"
GROUP BY MONTH(t.date_booked), MONTH(i.inv_date)
ORDER BY t.date_booked, i.inv_date ASC
这是
的输出| date | invdate |
| 2015-01-02 | 2015-02-10 |
| 2015-01-02 | 2015-02-15 |
| 2015-01-05 | 2015-02-10 |
| 2015-01-05 | 2015-02-15 |
.....
这应该是它应该做的吗?因为它看起来只是对invdate列进行分组,
我还尝试添加' AND'在分组GROUP BY MONTH(t.date_booked) AND MONTH(i.inv_date)
但它只输出第一行
| date | invdate |
| 2015-01-02 | 2015-02-10 |
我想要的输出是这样的:
| date | invdate |
| 2015-01-02 | 2015-02-10 |
| 2015-01-05 | 2015-02-15 |
最好的方法是什么?