๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿ“š ์ „๊ณต ๊ณต๋ถ€/DB๊ธฐ์ดˆ

[SQL] mysql ๋‚ด์žฅํ•จ์ˆ˜ ์ •๋ฆฌ

728x90

๋ฌธ์ž์—ด ํ•จ์ˆ˜

  • CONCAT(): 2๊ฐœ ์ด์ƒ์˜ ๋ฌธ์ž์—ด์„ ์—ฐ๊ฒฐํ•ฉ๋‹ˆ๋‹ค.
     
    SELECT CONCAT('Hello', 'World'); -- Output: HelloWorld
     
  • SUBSTR(): ๋ฌธ์ž์—ด์—์„œ ํ•˜์œ„ ๋ฌธ์ž์—ด์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
     
    SELECT SUBSTR('Hello World', 7); -- Output: World
     
  • UPPER(): ๋ฌธ์ž์—ด์„ ๋Œ€๋ฌธ์ž๋กœ ๋ณ€ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
     
    SELECT UPPER('Hello World'); -- Output: HELLO WORLD
     
  • LOWER(): ๋ฌธ์ž์—ด์„ ์†Œ๋ฌธ์ž๋กœ ๋ณ€ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
     
    SELECT LOWER('Hello World'); -- Output: hello world
     
  • LENGTH(): ๋ฌธ์ž์—ด ๊ธธ์ด๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
     
    SELECT LENGTH('Hello World'); -- Output: 11
     

์ˆซ์ž ํ•จ์ˆ˜

  • ABS(): ์ˆซ์ž์˜ ์ ˆ๋Œ€๊ฐ’์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
     
    SELECT ABS(-10); -- Output: 10
     
  • ROUND(): ์ง€์ •๋œ ์†Œ์ˆ˜ ์ž๋ฆฟ์ˆ˜๋กœ ์ˆซ์ž๋ฅผ ๋ฐ˜์˜ฌ๋ฆผํ•ฉ๋‹ˆ๋‹ค.
     
    SELECT ROUND(3.14159, 2); -- Output: 3.14
     
  • CEIL(): ์ˆซ์ž ์ด์ƒ์˜ ์ตœ์†Œ ์ •์ˆ˜๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
     
    SELECT CEIL(3.5); -- Output: 4
     
  • FLOOR(): ์ˆซ์ž ์ดํ•˜์˜ ์ตœ๋Œ€ ์ •์ˆ˜๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
     
    SELECT FLOOR(3.5); -- Output: 3
     

๋‚ ์งœ ๋ฐ ์‹œ๊ฐ„ ํ•จ์ˆ˜

  • NOW(): ํ˜„์žฌ ๋‚ ์งœ์™€ ์‹œ๊ฐ„์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
     
    SELECT NOW(); -- Output: 2023-03-03 11:45:22
     
  • DATE(): ๋‚ ์งœ ๋˜๋Š” ๋‚ ์งœ์‹์˜ ๋‚ ์งœ ๋ถ€๋ถ„์„ ์ถ”์ถœํ•ฉ๋‹ˆ๋‹ค.
     
    SELECT DATE('2023-03-03 11:45:22'); -- Output: 2023-03-03
     
  • YEAR(): ๋‚ ์งœ ๋˜๋Š” ๋‚ ์งœ ์‹์—์„œ ์—ฐ๋„๋ฅผ ์ถ”์ถœํ•ฉ๋‹ˆ๋‹ค.
     
    SELECT YEAR('2023-03-03'); -- Output: 2023
     
  • MONTH(): ๋‚ ์งœ ๋˜๋Š” ๋‚ ์งœ ์‹์—์„œ ์›”์„ ์ถ”์ถœํ•ฉ๋‹ˆ๋‹ค.
     
    SELECT MONTH('2023-03-03'); -- Output: 3
     
  • DAY(): ๋‚ ์งœ ์‹ ๋˜๋Š” ๋‚ ์งœ ์‹์—์„œ ๋‚ ์งœ๋ฅผ ์ถ”์ถœํ•ฉ๋‹ˆ๋‹ค.
     
    SELECT DAY('2023-03-03'); -- Output: 3
     

์ง‘์•ฝ ํ•จ์ˆ˜

  • COUNT(): ์ง€์ •ํ•œ ์กฐ๊ฑด๊ณผ ์ผ์น˜ํ•˜๋Š” ํ–‰ ์ˆ˜๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
     
    SELECT COUNT(*) FROM orders; -- Output: 100
     
  • SUM(): ์ˆซ์ž ์—ด์˜ ํ•ฉ๊ณ„๋ฅผ ๊ณ„์‚ฐํ•ฉ๋‹ˆ๋‹ค.
     
    SELECT SUM(amount) FROM orders; -- Output: 10000.00
     
  • AVG(): ์ˆซ์ž ์—ด์˜ ํ‰๊ท ์„ ๊ณ„์‚ฐํ•ฉ๋‹ˆ๋‹ค.
     
    SELECT AVG(amount) FROM orders; -- Output: 100.00
     
  • MAX(): ์—ด์˜ ์ตœ๋Œ€๊ฐ’์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
     
    SELECT MAX(amount) FROM orders; -- Output: 100.00
     
  • MIN(): ์—ด์˜ ์ตœ์†Œ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
     
    SELECT MIN(amount) FROM orders; -- Output: 50.00

 

 

์ด๋Š” MySQL์—์„œ ์ œ๊ณตํ•˜๋Š” ๋งŽ์€ ๋‚ด์žฅ ๊ธฐ๋Šฅ ์ค‘ ์ผ๋ถ€์— ๋ถˆ๊ณผํ•ฉ๋‹ˆ๋‹ค.

 

๋ผ๊ณ  chatGPT๊ฐ€ ์•Œ๋ ค์คŒ ^-^

๊ณ ๋งˆ์›Œ gpt์•ผ~~~

 

 

728x90