๐งท ์๋ฌธ์ ๋๋ฌธ์๋ก ๋ฐํํ๋ ํจ์
mysql> SELECT UCASE('This is ucase Test.');
+------------------------------+
| UCASE('This is ucase Test.') |
+------------------------------+
| THIS IS UCASE TEST. |
+------------------------------+
1 row in set (0.15 sec)
mysql> SELECT UCASE(menu)
-> FROM sandwich
-> WHERE price > 15;
+----------------------------------+
| UCASE(menu) |
+----------------------------------+
| BLT |
| FRIED BOLOGNA |
| WOODLAND MUSHROOM |
| ROAST BEEF |
| PB&L |
| BELGIAN CHICKEN CURRY SALAD |
| LOBSTER ROLL |
| SMOKED SALMON SALAD |
| ATOMICA CEMITAS |
| GRILLED LAUGHING BIRD SHRIMP AND |
| HAM AND RACLETTE PANINO |
| THE HAWKEYE |
| CHICKEN DIP |
| WILD BOAR SLOPPY JOE |
| MEATBALL SUB |
| CORNED BEEF |
| TURKEY CLUB |
| FALAFEL |
| CRAB CAKE |
| CHICKEN SCHNITZEL |
| TOASTED PIMIENTO CHEESE |
| VEGETARIAN PANINO |
| PASTRAMI |
| SMOKED HAM |
| JIBARITO |
| SHAVED PRIME RIB |
| TUNA SALAD |
| PARAMOUNT REUBEN |
| THE ISTANBUL |
| B.A.D. |
| DUCK CONFIT AND MOZZARELLA |
| CROQUE MONSIEUR |
| GREEN GARBANZO |
| TUSCAN CHICKEN |
| THE MARTY |
| WHITEFISH |
| CAULIFLOWER MELT |
| CUBANA |
| KUFTA |
| DEBBIEโS EGG SALAD |
| BEEF CURRY |
| LE VรGรTARIEN |
| THE GATSBY |
+----------------------------------+
43 rows in set (0.15 sec)
๐งท ์๋ฌธ์ ์๋ฌธ์๋ก ๋ฐํํ๋ ํจ์
mysql> SELECT LCASE('This is LCASE Test.');
+------------------------------+
| LCASE('This is LCASE Test.') |
+------------------------------+
| this is lcase test. |
+------------------------------+
1 row in set (0.14 sec)
mysql> SELECT LCASE(menu), price
-> FROM sandwich
-> WHERE price < 5;
+--------------+-------+
| LCASE(menu) | price |
+--------------+-------+
| meatball sub | 4.5 |
+--------------+-------+
1 row in set (0.15 sec)
๐งท ๋ฌธ์์ด ๋ถ๋ถ์ ๋ฐํํ๋ ํจ์
mysql> SELECT MID('This is MID Test.',1,4);
+------------------------------+
| MID('This is MID Test.',1,4) |
+------------------------------+
| This |
+------------------------------+
1 row in set (0.15 sec)
mysql> SELECT MID('This is MID Test.', 6,5);
+-------------------------------+
| MID('This is MID Test.', 6,5) |
+-------------------------------+
| is MI |
+-------------------------------+
1 row in set (0.17 sec)
mysql> SELECT MID('This is MID Test.',-4,4);
+-------------------------------+
| MID('This is MID Test.',-4,4) |
+-------------------------------+
| est. |
+-------------------------------+
1 row in set (0.16 sec)
mysql> Select MID('This is MID Test.',-8,3);
+-------------------------------+
| MID('This is MID Test.',-8,3) |
+-------------------------------+
| ID |
+-------------------------------+
1 row in set (0.15 sec)
mysql> SELECT cafe
-> FROM sandwich
-> WHERE ranking = 11;
+-----------+
| cafe |
+-----------+
| Lula Cafe |
+-----------+
1 row in set (0.15 sec)
mysql> SELECT MID(cafe, 6,4)
-> FROM sandwich
-> WHERE ranking = 11;
+----------------+
| MID(cafe, 6,4) |
+----------------+
| Cafe |
+----------------+
1 row in set (0.15 sec)
๐งท ๋ฌธ์์ด ๊ธธ์ด๋ฅผ ๋ฐํํ๋ ํจ์
mysql> SELECT LENGTH('This is len test');
+----------------------------+
| LENGTH('This is len test') |
+----------------------------+
| 16 |
+----------------------------+
1 row in set (0.15 sec)
#๋ฌธ์๊ฐ ์์๊ฒฝ์ฐ 0
mysql> SELECT LENGTH('');
+------------+
| LENGTH('') |
+------------+
| 0 |
+------------+
1 row in set (0.15 sec)
#๊ณต๋ฐฑ๋ ๋ฌธ์์ด๋ฏ๋ก 1
mysql> SELECT LENGTH(' ');
+-------------+
| LENGTH(' ') |
+-------------+
| 1 |
+-------------+
1 row in set (0.14 sec)
#null์ ๊ธธ์ด๊ฐ ์์
mysql> SELECT LENGTH(null);
+--------------+
| LENGTH(null) |
+--------------+
| NULL |
+--------------+
1 row in set (0.15 sec)
mysql> SELECT LENGTH(address)
-> FROM sandwich
-> WHERE ranking <= 3;
+-----------------+
| LENGTH(address) |
+-----------------+
| 19 |
| 18 |
| 16 |
+-----------------+
3 rows in set (0.15 sec)
๐งท ์ง์ ํ ์๋ฆฌ์์ ์ซ์๋ฅผ ๋ฐ์ฌ๋ฆผํ๋ ํจ์
๐ ์์น ๋ฏธ๊ธฐ์ฌ ์ default 0 (์์์ ์๋ฆฌ 0์์ ๋ฐ์ฌ๋ฆผ)
์ผ๋จ์ ์์น๋ -1 / ์ญ๋จ์ ์์น๋ -2
mysql> SELECT ROUND(315.625);
+----------------+
| ROUND(315.625) |
+----------------+
| 316 |
+----------------+
1 row in set (0.15 sec)
mysql> SELECT ROUND(315.625,0);
+------------------+
| ROUND(315.625,0) |
+------------------+
| 316 |
+------------------+
1 row in set (0.15 sec)
mysql> SELECT ranking, price, ROUND(price,0)
-> FROM sandwich
-> ORDER BY ranking DESC
-> LIMIT 3;
+---------+-------+----------------+
| ranking | price | ROUND(price,0) |
+---------+-------+----------------+
| 50 | 6.85 | 7 |
| 49 | 8.75 | 9 |
| 48 | 7.5 | 8 |
+---------+-------+----------------+
3 rows in set (0.14 sec)
๐งท ํ์ฌ ๋ ์ง ๋ฐ ์๊ฐ์ ๋ฐํํ๋ ํจ์
mysql> SELECT NOW();
+---------------------+
| NOW() |
+---------------------+
| 2024-01-25 05:44:30 |
+---------------------+
1 row in set (0.15 sec)
๐งท ์ซ์๋ฅผ ์ฒ๋จ์ ์ฝค๋ง๊ฐ ์๋ ํ์์ผ๋ก ๋ฐํํ๋ ํจ์ (๋ฐ์ฌ๋ฆผ๊น์ง)
๐ round์ ๋ง์ฐฌ๊ฐ์ง๋ก ํ์ํ ์๋ฆฌ์์ ์ซ์๋ฅผ ์ ์ด์ฃผ๋ฉด๋จ
์ผ์์๋ฆฌ -1 / ์ญ์์๋ฆฌ -2 ..
mysql> SELECT FORMAT(12345.6789,0);
+----------------------+
| FORMAT(12345.6789,0) |
+----------------------+
| 12,346 |
+----------------------+
1 row in set (0.15 sec)
mysql> SELECT FORMAT(12345.6789,2);
+----------------------+
| FORMAT(12345.6789,2) |
+----------------------+
| 12,345.68 |
+----------------------+
1 row in set (0.15 sec)
mysql> SELECT FORMAT(12345.6789,10);
+-----------------------+
| FORMAT(12345.6789,10) |
+-----------------------+
| 12,345.6789000000 |
+-----------------------+
1 row in set (0.15 sec)
mysql> SELECT FORMAT(๊ฐ๊ฒฉ,0)
-> FROM oil_price
-> WHERE ROUND(๊ฐ๊ฒฉ, -3) >= 2000 ;
+------------------+
| FORMAT(๊ฐ๊ฒฉ,0) |
+------------------+
| 1,509 |
| 1,598 |
| 1,635 |
| 2,160 |
+------------------+
4 rows in set (0.01 sec)
mysql> use zerobase
Database changed
mysql> select UCASE(cafe), LCASE(menu)
-> from sandwich;
+---------------------------------+----------------------------------+
| UCASE(cafe) | LCASE(menu) |
+---------------------------------+----------------------------------+
| OLD OAK TAP | blt |
| AU CHEVAL | fried bologna |
| XOCO | woodland mushroom |
| ALโS DELI | roast beef |
| PUBLICAN QUALITY MEATS | pb&l |
| HENDRICKX BELGIAN BREAD CRAFTER | belgian chicken curry salad |
| ACADIA | lobster roll |
| BIRCHWOOD KITCHEN | smoked salmon salad |
| CEMITAS PUEBLA | atomica cemitas |
| NANA | grilled laughing bird shrimp and |
| LULA CAFE | ham and raclette panino |
| RICOBENEโS | breaded steak |
| FROG N SNAIL | the hawkeye |
| CROSBYโS KITCHEN | chicken dip |
| LONGMAN & EAGLE | wild boar sloppy joe |
| BARI | meatball sub |
| MANNYโS | corned beef |
| EGGYโS | turkey club |
| OLD JERUSALEM | falafel |
| MINDYโS HOTCHOCOLATE | crab cake |
| OLGAโS DELICATESSEN | chicken schnitzel |
| DAWALI MEDITERRANEAN KITCHEN | shawarma |
| BIG JONES | toasted pimiento cheese |
| LA PANE | vegetarian panino |
| PASTORAL | cali chรจvre |
| MAXโS DELI | pastrami |
| LUCKYโS SANDWICH CO. | the fredo |
| CITY PROVISIONS | smoked ham |
| PAPAโS CACHE SABROSO | jibarito |
| BAVETTEโS BAR & BOEUF | shaved prime rib |
| HANNAHโS BRETZEL | serrano ham and manchego cheese |
| LA FOURNETTE | tuna salad |
| PARAMOUNT ROOM | paramount reuben |
| MELT SANDWICH SHOPPE | the istanbul |
| FLORIOLE CAFE & BAKERY | b.a.d. |
| FIRST SLICE PIE CAFร | duck confit and mozzarella |
| TROQUET | croque monsieur |
| GRAHAMWICH | green garbanzo |
| SAIGON SISTERS | the hen house |
| ROSALIAโS DELI | tuscan chicken |
| Z&H MARKETCAFE | the marty |
| MARKET HOUSE ON THE SQUARE | whitefish |
| ELAINEโS COFFEE CALL | oat bread, pecan butter, and fru |
| MARION STREET CHEESE MARKET | cauliflower melt |
| CAFECITO | cubana |
| CHICKPEA | kufta |
| THE GODDESS AND GROCER | debbieโs egg salad |
| ZENWICH | beef curry |
| TONI PATISSERIE | le vรฉgรฉtarien |
| PHOEBEโS BAKERY | the gatsby |
+---------------------------------+----------------------------------+
50 rows in set (0.15 sec)
mysql> SELECT menu
-> FROM sandwich
-> WHERE ranking = 10;
+----------------------------------+
| menu |
+----------------------------------+
| Grilled Laughing Bird Shrimp and |
+----------------------------------+
1 row in set (0.15 sec)
mysql> SELECT MID(menu, -3,3)
-> FROM sandwich
-> WHERE ranking = 10;
+-----------------+
| MID(menu, -3,3) |
+-----------------+
| and |
+-----------------+
1 row in set (0.21 sec)
mysql> SELECT AVG ( LENGTH(menu) )
-> FROM sandwich;
+----------------------+
| AVG ( LENGTH(menu) ) |
+----------------------+
| 13.9600 |
+----------------------+
1 row in set (0.15 sec)
mysql> SELECT FORMAT(๊ฐ๊ฒฉ,-1)
-> FROM oil_price;
+-------------------+
| FORMAT(๊ฐ๊ฒฉ,-1) |
+-------------------+
| 1,484 |
| 1,485 |
| 1,498 |
| 1,498 |
| 1,509 |
| 1,598 |
| 1,635 |
| 2,160 |
| 1,498 |
+-------------------+
9 rows in set (0.00 sec)
mysql> SELECT FORMAT(๊ฐ๊ฒฉ,0)
-> FROM oil_price
-> WHERE ROUND(๊ฐ๊ฒฉ,-2) >= 2000;
+------------------+
| FORMAT(๊ฐ๊ฒฉ,0) |
+------------------+
| 2,160 |
+------------------+
1 row in set (0.00 sec)