0
下面是這種情況:表連接和group by ID的MySQL
- 我想從表客戶名稱1
- 通過ID
- 加入表2從表中選擇所有付款日期2
- 按年分組
只是爲了解釋,代碼和名稱鍵屬於Table1 paymentDate和數量鍵在Table2上,但它們共享外鍵uniqueId密鑰。
預期的結果最終應該是這樣的:
[{
"code": 1011,
"name": "Customer1",
"amount": 5000,
"paymentDate": "2016-10-20T04:00:00.000Z"
"paymentDate": "2016-11-20T04:00:00.000Z"
"paymentDate": "2016-12-20T04:00:00.000Z"
},
{
"code": 1012,
"name": "Customer2",
"amount": 5000,
"paymentDate": "2016-03-20T05:00:00.000Z"
"paymentDate": "2016-04-20T05:00:00.000Z"
"paymentDate": "2016-05-20T05:00:00.000Z"
"paymentDate": "2016-06-20T05:00:00.000Z"
},
{
"code": 1013,
"name": "Customer3",
"amount": 5000,
"paymentDate": "2016-01-20T05:00:00.000Z"
"paymentDate": "2016-02-20T05:00:00.000Z"
}]
到目前爲止,我有這樣的:
SELECT coreObjects.code,
coreObjects.name,
lateobjectpayments.amount,
lateobjectpayments.paymentDate
FROM coreObjects
JOIN lateobjectpayments
ON coreObjects.uniqueId=lateobjectpayments.uniqueId
GROUP BY YEAR(lateobjectpayments.paymentDate)
看來我需要多選擇附近的加入,但沒有我想的那麼遠。如果有人能幫助我,我將不勝感激。
我在你的例子中沒有看到你在哪裏按年進行分組。這是你所困擾的問題嗎? –
實際上查詢中缺少按年份分組,但仍然沒有; t給我我想要的值 – itismelito
目前的輸出是什麼? –