λ¨Όμ μμκ°κΈ°!
- μ§μ μ΄λ‘μμΌλ‘ μμ± λ λΆλΆμ μλ΅ κ°λ₯ν λΆλΆμ λλ€.
- νΉμ μμ± λ³λ‘ ꡬλΆνκ³ μ ν λ(=GROUP BY μ κ°μ λμμ μν€κ³ μΆμ λ) PARTITION BYλ₯Ό μ¬μ©ν©λλ€.
SUM OVER
λμ ν©κ³λ₯Ό ꡬν©λλ€.
sum(λμ) over (partition by λμ, order by λμ)
μμ 1 ) PANAME ν μ΄λΈμ μ‘°ννμ¬ μ νμ½λ, ν맀μ , ν맀λ μ§, ν맀λ, ν맀κΈμ‘κ³Ό μ ν μ½λ λ³ κ° μ€ν μ΄μ ν©κ³ μΆλ ₯
select P_CODE,
P_STORE,
P_DATE,
P_QTY,
P_TOTAL,
sum(P_TOTAL) over (partition by P_CODE, P_STORE order by P_DATE, P_TOTAL) "TOTAL"
from PANMAE;
μμ 2 ) ν맀 λΉμ¨ ꡬνκΈ°
select P_CODE, P_STORE, P_QTY, sum(P_QTY) over ( ) "TOTAL", round((P_QTY / sum(P_QTY) over ( )) * 100, 2) "QTY_%"
from PANMAE
where P_CODE = 100;
-- * * OR * *
select P_CODE,
P_STORE,
P_QTY,
sum(P_QTY) over ( ) "TOTAL",
round(ratio_to_report(sum(P_QTY)) over () * 100, 2) "QTY_%2"
from PANMAE
where P_CODE = 100
group by P_CODE, P_STORE, P_QTY;
'Database' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
MySQL * κΆν λͺκ°μ§ μ 리 (0) | 2021.06.13 |
---|---|
β solved * MySQL: ERROR 1418 (HY000): ... (0) | 2021.06.13 |
SQL μμν¨μ: RANK, DENSE_RANK, ROW_NUMBER, NTILE (0) | 2021.03.23 |
SQL Oracle * LAG/LEAD: μ΄μ /μ΄ν λ‘μ° κ° λ°ν (0) | 2021.03.23 |
SQL 볡μν ν¨μ: GROUP ν¨μμ μ’ λ₯ (0) | 2021.03.16 |