我有兩個表,銷售和電話如下:組通過日期
**Sales**
CUST_ID INT primary key,
CUST_NM Varchar(40),
Sale_date Datetime2,
SALES Money);
CUST_ID CUST_NM Sale_date SALES
1 Dom 2015-01-01 15:00:02.3000000 10.00
2 Brian 2015-01-02 15:00:02.3000000 12.00
3 Stu 2015-01-03 15:00:02.3000000 21.00
4 John 2015-01-04 15:00:02.3000000 41.00
5 Jack 2015-01-05 15:00:02.3000000 51.00
6 Jill 2015-01-05 15:00:02.3000000 61.00
7 Steve 2015-01-04 15:00:02.3000000 16.00
8 Stacey 2015-01-03 15:00:02.3000000 19.00
9 Lacey 2015-01-03 15:00:02.3000000 30.00
呼叫
NAME Varchar(40),
CALL_DATE Date,
TOTAL_CALLS INT
NAME CALL_DATE TOTAL_CALLS
Dom 2015-01-01 2
Brian 2015-01-02 4
Stu 2015-01-03 3
John 2015-01-04 5
Jack 2015-01-05 6
Jill 2015-01-05 10
Steve 2015-01-04 8
Stacey 2015-01-03 7
Lacey 2015-01-03 9
我想寫的SELECT語句帶回日期,銷售總額,以及來自銷售和呼叫的全部呼叫,並在日期加入。
這是我寫的,我認爲它應該是正確的,但不知何故,我沒有得到正確的輸出。
select Calls.CALL_DATE, sum(Sales.SALES) as gross_sale, sum(Calls.TOTAL_CALLS) as gross_total_calls
from Sales
join
Calls
on convert (date,sales.Sale_date)=calls.CALL_DATE
group by Calls.CALL_DATE
order by Calls.CALL_DATE
我得到的輸出是
CALL_DATE gross_sale gross_total_calls
2015-01-01 10.00 2
2015-01-02 12.00 4
2015-01-03 210.00 57
2015-01-04 114.00 26
2015-01-05 224.00 32
我要去哪裏錯了?
感謝您編輯問題@john Cappelletti – Gompu