๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ’๊ณต๋ถ€/ORACLE

[ORACLE] DATE๋กœ ํ˜•๋ณ€ํ™˜, ์ค‘๋ณต ์ œ๊ฑฐ DISTINCT

by rindev 2021. 6. 9.

ORACLE... ์ด๊ฒŒ ๋ ˆ๋ฒจ2๋ฉด ๋ ˆ๋ฒจ3์€....๐Ÿค”

 

๐Ÿ’ DATETIME ํ˜•๋ณ€ํ™˜

์„ ๊นŒ๋จน๋Š” ์‚ฌ๋žŒ๐Ÿ™‹‍โ™€๏ธ

  • YYYY : 2021
  • YY : 21
  • MM : 06 (๋‘ ์ž๋ฆฌ ์›”)
  • DD : 09  (๋‘ ์ž๋ฆฌ ์ผ)
  • HH24 : 13 (12์‹œ๊ฐ„์œผ๋กœ ๋ฐ”๊พธ๊ณ  ์‹ถ์œผ๋ฉด HH12)
  • MI : 34 (๋ถ„)
  • SS : 56 (์ดˆ)
TO_CHAR(DATETIME, 'YYYY-MM-DD') /* 2021-06-09 */
TO_CHAR(DATETIME, 'YY-MM-DD') /* 21-06-09 */
TO_CHAR(DATETIME, 'HH24') /* 13 */
TO_CHAR(DATETIME, 'HH12') /* 01 */

TO_DATE(SYSDATE, 'YYYY/MM/DD:HH24:MI:SS') /* 2021/06/09:02:34:56 */
TO_DATE(SYSDATE, 'DAY Mon YY') /* ์ˆ˜์š”์ผ 6์›” 9 */

 

๐Ÿ’์ค‘๋ณต ์ œ๊ฑฐ (DISTINCT)

  • DISTINCT ์ปฌ๋Ÿผ์ด 1๊ฐœ์ธ ๊ฒฝ์šฐ
SELECT DISTINCT [์ถœ๋ ฅํ•  ์ปฌ๋Ÿผ]
FROM [ํ…Œ์ด๋ธ”๋ช…];

SELECT COUNT( DISTINCT [์ถœ๋ ฅํ•  ์ปฌ๋Ÿผ] )
FROM [ํ…Œ์ด๋ธ”๋ช…];

 

  • DISTINCT ์ปฌ๋Ÿผ์ด ์—ฌ๋Ÿฌ๊ฐœ์ธ ๊ฒฝ์šฐ
SELECT DISTINCT [์ปฌ๋Ÿผ1], [์ปฌ๋Ÿผ2]
FROM [ํ…Œ์ด๋ธ”๋ช…]
ORDER BY [์ปฌ๋Ÿผ1];

์ด๋Ÿฐ ์ฟผ๋ฆฌ๊ฐ€ ์žˆ๋‹ค๊ณ  ํ•˜๋ฉด!

์ปฌ๋Ÿผ1 ์ปฌ๋Ÿผ2
A 100
A 200
B 150
C 250
D 100

์ปฌ๋Ÿผ1์— A๊ฐ€ 2๊ฐœ๊ฐ€ ์žˆ๊ณ , ์ปฌ๋Ÿผ2์—๋Š” 100์ด 2๊ฐœ ์žˆ๋Š”๋ฐ ์™œ ์ค‘๋ณต ์ œ๊ฑฐ๊ฐ€ ์•ˆ๋œ๊ฑฐ์ง€?! ๋ผ๊ณ  ์ƒ๊ฐํ•  ์ˆ˜ ๋„ ์žˆ์ง€๋งŒ!

A-100, A-200, B-150, C-250, D-100 ์ด๋ ‡๊ฒŒ ์ง์ง€์–ด์ง„ ๊ฒƒ์˜ ์ค‘๋ณต๋งŒ ์ œ๊ฑฐ๋˜๋ฏ€๋กœ ์ €๋ ‡๊ฒŒ ๋‚˜์˜ค๋Š”๊ฒŒ ๋งž๋‹ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค๐Ÿ˜ต

SELECT COUNT(*)
FROM (
		SELECT DISTINCT [์ปฌ๋Ÿผ1], [์ปฌ๋Ÿผ2]
        FROM [ํ…Œ์ด๋ธ”๋ช…]
     )
;

์ด ๊ฐฏ์ˆ˜๋ฅผ ๊ตฌํ•  ๋•Œ์—๋Š” ์ด๋ ‡๊ฒŒ! 

 

 

'๐Ÿ’๊ณต๋ถ€ > ORACLE' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[ORACLE] GROUP BY, LIKE, LOWER  (0) 2021.05.31

๋Œ“๊ธ€