好的伙计们,很抱歉,因为我看到了一些mysql JOIN示例,但我似乎无法让它工作。mysql + JOIN查询的问题
“销售”
----------------------
idcustomer | datecode
----------------------
1 | 20120503
1 | 20120503
1 | 20120503
2 | 20120503
3 | 20120503
我想知道谁是最大买家....在多少次客户从我这里买走的东西在especific天方面(是的,我用一些奇怪的格式日期我知道,请不要介意说)......,所以我做的:
SELECT idcustomer, COUNT(idcustomer) FROM sales WHERE datecode = 20120503 GROUP BY idcustomer ORDER BY COUNT(idcustomer) DESC
,我也得到:
-----------------------------
idcustomer | Count(idcustomer)
-----------------------------
1 | 3
2 | 1
3 | 1
的问题是... SI NCE我也有表:
“客户”
----------------------
| name | id_customer |
----------------------
Jess | 1
Matt | 2
Perry | 3
及以下就是我想达到什么样的....怎么办呢?
---------------------------------------------
customer.name | idcustomer | Count(idcustomer)
---------------------------------------------
Jess | 1 | 3
Matt | 2 | 1
Perry | 3 | 1
按日期代码添加分组 –