λ°μν
μ νλ₯Ό 보면 codetypeμ fruitμ΄ μκ³ codekeyμλ κ³ΌμΌμ μ’ λ₯κ° μ νμλ€.
κ·Έλ¦¬κ³ κ°κ° κ³ΌμΌμ λν μ’ λ₯μ μ΄λ¦μ΄ λμμλ€.
νμ¬ ν¬λλ 4κ°, μ¬κ³Όλ 2κ°, μ€λ μ§λ 3κ°, λ°°λ 0κ°μΈλ°
ν¬λ, μ¬κ³Ό, μ€λ μ§, λ°° λ³λ‘ κ°μλ₯Ό μΈλ 쿼리문μ λ§λ€κ³ μΆμλ€.
νλͺ©μ μλ 건 μ μΈνκ³ count νκΈ°
select B.codekey, count(A.codekey)
from (select * from fruit where codetype like 'fruit') B
join fruit A
on A.codetype = B.codekey
group by B.codekey;
νλͺ©μ μλ κ²λ count νκΈ°
λ°°λ 0κ°μΈλ° 0κ°λ μΆλ ₯νκ³ μΆλ€!
left joinμ μ¬μ©νμ¬ λ§λ€μλ€.
select B.codekey, count(A.codekey)
from (select * from fruit where codetype like 'fruit') B
left join fruit A
on A.codetype = B.codekey
group by B.codekey;
λ°μν
'π³π°ππ°π±π°ππ΄' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[SQL] μ’μ 쿼리 μμ±λ² (0) | 2024.04.29 |
---|---|
PostgreSQL μλμ° windowsμ μ€μΉ (0) | 2024.04.22 |
λ°μ΄ν°λ² μ΄μ€ λ²€λλ? Database Vendor (0) | 2024.04.01 |
[PostgreSQL] λμλ¬Έμ κ΅¬λΆ μμ΄ κ²μνκΈ° ILIKE (0) | 2023.12.21 |
[postgreSQL] desc ν μ΄λΈλͺ ; μ λ¨..! (0) | 2023.12.10 |