我有3個表數據庫:SQL查詢到組日期按月
mothlist([number],[name])
temp_subs([sub_id],[date_created],[expiry_date])
temp_orders([order_id],[sub_id],[order_date])
我想編寫一個查詢來獲得總統計當月按月分組的到期日和訂單。
查詢我現在是:
SELECT
monthlist.name 'Month',
count(temp_subs.expiry_date) 'Expiry Date',
count(temp_orders.order_date) 'Order Date'
FROM
monthlist
FULL JOIN temp_subs
on
monthlist.number = datepart(month, temp_subs.expiry_date) and
datepart(year, temp_subs.expiry_date) = year(getdate())
FULL JOIN temp_orders
on
monthlist.number = datepart(month, temp_orders.order_date) and
datepart(year, temp_orders.order_date) = year(getdate())
GROUP BY monthlist.number ,monthlist.name
ORDER BY monthlist.number
如果有人能告訴我我是什麼洞錯在這裏我將非常感激。
現在出現了什麼問題?行數太多? – gbn
你得到什麼錯誤? – SuganR