select sum(t1.CU_order_amount) as 金額,
t3.CU_name as 地區
from CU_order t1
inner join CU_cust_info t2 on t1.CU_cust_id = t2.CU_cust_id
inner join CU_city t3 on t2.CU_city_id = t3.CU_city_id
where t1.BillDate between '20160101' and '20171231'
group by t3.CU_name
※ 引述《nd5287 (Mike)》之銘言:
: 資料庫名稱:
: 資料庫版本:sql 2014
: 內容/問題描述:
: 我下了 以下的語法查詢出的結果如下
: select DISTINCT B.CU_order_amount "金額",D.CU_name as "地區",
: B.BillDate as "日期" from CU_order B
: join CU_cust_info C on B.CU_cust_id=C.CU_cust_id
: join CU_city D on C.CU_city_id = D.CU_Id
: where B.CU_cust_id in
: (select CU_cust_id from CU_cust_info C where CU_city_id in (select CU_city_id
: from CU_city ))
: and B.BillDate Between '20160101' and '20171231'
: order by B.CU_order_amount desc
: 金額 地區 日期
: