當前位置:首頁 » 編程語言 » 銷售額的sql
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

銷售額的sql

發布時間: 2022-04-28 00:50:18

㈠ 求一句按月匯總銷售額的sql語句

select substr(to_char(訂單日期,'yyyymmdd'),0,6),sum(銷售額) from 表 group by substr(to_char(訂單日期,'yyyymmdd'),0,6);

㈡ sql 查詢問題(根據銷售人去統計銷售金額)

SELECT 銷售ID,銷售人, 銷售時間,SUM( 銷售金額) FROM 銷售表 GROUP BY 銷售人

㈢ sql--按照季度統計銷售額 怎麼寫

倆方法

selectyear(訂單.訂購日期)年份,
sum(casewhenmonth(訂單.訂購日期)between1and3then訂單明細.單價*訂單明細.數量else0end)一季度銷售金額,
sum(casewhenmonth(訂單.訂購日期)between4and6then訂單明細.單價*訂單明細.數量else0end)二季度銷售金額,
sum(casewhenmonth(訂單.訂購日期)between7and9then訂單明細.單價*訂單明細.數量else0end)三季度銷售金額,
sum(casewhenmonth(訂單.訂購日期)between10and12then訂單明細.單價*訂單明細.數量else0end)四季度銷售金額
from訂單,訂單明細
where訂單.訂單ID=訂單明細.訂單IDandyear(訂單.訂購日期)between1996and1998
groupbyyear(訂單.訂購日期)


selectyear(訂單.訂購日期)年份,
casewhenmonth(訂單.訂購日期)between1and3then'一季度'
whenmonth(訂單.訂購日期)between4and6then'二季度'
whenmonth(訂單.訂購日期)between7and9then'三季度'
whenmonth(訂單.訂購日期)between10and12then'四季度'end季度,
sum(訂單明細.單價*訂單明細.數量)金額
from訂單,訂單明細
where訂單.訂單ID=訂單明細.訂單IDandyear(訂單.訂購日期)between1996and1998
groupbyyear(訂單.訂購日期),
casewhenmonth(訂單.訂購日期)between1and3then'一季度'
whenmonth(訂單.訂購日期)between4and6then'二季度'
whenmonth(訂單.訂購日期)between7and9then'三季度'
whenmonth(訂單.訂購日期)between10and12then'四季度'end



你看你要用哪個

㈣ sql查詢 :銷售額

1.select 銷售價格*銷售數據量 as 銷售額 from 表名
2.select sum(銷售價格*銷售數據量) as 銷售額 from 表名
-----
1.多條 2。一條。

㈤ 用SQL統計每種商品的銷售總額

你寫的基本差不多了,不過表連接的順序最好按用到的前後來連接,不然影響效率
select P.ProctName, sum(OD.UnitPrice*OD.Quantity) total_sales
from Orders O
join OrderDetails OD on OD.OrderID=O.OrderID
join Procts P on P.ProctID=OD.ProctID

where OD.OrderDate>='2007-1-1'and OD.OrderDate < '2007-12-1'
group by P.ProctName
order by total_sales desc

㈥ SQL如何統計某段時間某業務員銷售總額、指定商品銷售額及該商品佔比

select
業務員,銷售總量,A產品銷售數量,(A產品銷售數量/銷售總量,)
as
A產品佔比
from
(select
業務員,sum(銷售數量)
as
銷售總量,(select
sum(銷售數量)
from
tablename
where
a.業務員=業務員
and
產品='A'
group
by
業務員)
as
A產品銷售數量
from
tablename
a
where
業務員='張三'
group
by
業務員)
a

㈦ sql如何一次查詢得出十二個月中每個月的銷售額一列顯示。

select
地區
, sum(case when 月=1月 then 銷售額 else 0 end ) as sum_1
,sum(case when 月=2月 then 銷售額 else 0 end ) as sum_2
,sum(case when 月=3月 then 銷售額 else 0 end ) as sum_3
,sum(case when 月=4月 then 銷售額 else 0 end ) as sum_4
,sum(case when 月=5月 then 銷售額 else 0 end ) as sum_5
,sum(case when 月=6月 then 銷售額 else 0 end ) as sum_6
,sum(case when 月=7月 then 銷售額 else 0 end ) as sum_7
,sum(case when 月=8月 then 銷售額 else 0 end ) as sum_8
,sum(case when 月=9月 then 銷售額 else 0 end ) as sum_9
,sum(case when 月=10月 then 銷售額 else 0 end ) as sum_10
,sum(case when 月=11月 then 銷售額 else 0 end ) as 搜索sum_11
,sum(case when 月=12月 then 銷售額 else 0 end ) as sum_12
from 表
group by 地區

㈧ 請問 sqlserver 各個商品各月銷售額統計 sql語句怎麼寫

可以完成,思路如下:

通過pid 商品編碼分組,得到銷售日期的每個月列,後用sum(caseFact_mWHEN月份 then數量end)來操作即可.

--年度售額:
selectpid商品編碼
,isnull(convert(dec(18,2),sum(caseFact_mWHEN'01'thencCostend)),0)'countCost_1'
,isnull(convert(dec(18,2),sum(caseFact_mWHEN'02'thencCostend)),0)'countCost_2'
,isnull(convert(dec(18,2),sum(caseFact_mWHEN'03'thencCostend)),0)'countCost_3'
,isnull(convert(dec(18,2),sum(caseFact_mWHEN'04'thencCostend)),0)'countCost_4'
,isnull(convert(dec(18,2),sum(caseFact_mWHEN'05'thencCostend)),0)'countCost_5'
,isnull(convert(dec(18,2),sum(caseFact_mWHEN'06'thencCostend)),0)'countCost_6'
,isnull(convert(dec(18,2),sum(caseFact_mWHEN'07'thencCostend)),0)'countCost_7'
,isnull(convert(dec(18,2),sum(caseFact_mWHEN'08'thencCostend)),0)'countCost_8'
,isnull(convert(dec(18,2),sum(caseFact_mWHEN'09'thencCostend)),0)'countCost_9'
,isnull(convert(dec(18,2),sum(caseFact_mWHEN'10'thencCostend)),0)'countCost_10'
,isnull(convert(dec(18,2),sum(caseFact_mWHEN'11'thencCostend)),0)'countCost_11'
,isnull(convert(dec(18,2),sum(caseFact_mWHEN'12'thencCostend)),0)'countCost_12'
,isnull(convert(dec(18,2),sum(cCost)))'countTotal'
fromTabgroupbypid
--Fact_m指的就是銷售日期[月],最後還有一列為年度總計

希望能幫到你!

㈨ SQL語句統計每天、每月、每年的銷售總額

1、每年
select
year(ordertime)
年,
sum(Total)
銷售合計
from
訂單表
group
by
year(ordertime)
2、每月
select
year(ordertime)
年,
month(ordertime)
月,
sum(Total)
銷售合計
from
訂單表
group
by
year(ordertime),
month(ordertime
3、每日
select
year(ordertime)
年,
month(ordertime)
月,
day(ordertime)
日,
sum(Total)
銷售合計
from
訂單表
group
by
year(ordertime),
month(ordertime),
day(ordertime)
另外每日也可以這樣:
select
convert(char(8),ordertime,112)
dt,
sum(Total)
銷售合計
from
訂單表
group
by
convert(char(8),ordertime,112)
如果需要增加查詢條件,在from後加where
即可。

㈩ SQL按年度統計銷售額 怎麼寫

缺欄位,你倆表必須有個訂單id關聯,你自己查一下


如果存在這個訂單id的話


比如查2013年的

selectyear(訂單.訂購日期)年份,sum(訂單明細.單價*訂單明細.數量)銷售金額
from訂單,訂單明細where訂單,訂單id=訂單明細.訂單id
whereyear(訂單.訂購日期)=2013
groupbyyear(訂單.訂購日期)