MySQL Functions — Question 4
Back to all questionsGiven the table LIBRARY :
| No | Title | Author | Type | Pub | Qty | Price |
|---|---|---|---|---|---|---|
| 1 | Data Structure | Lipschutz | DS | McGraw | 4 | 217 |
| 2 | Computer Studies | French | FND | Galgotia | 2 | 75 |
| 3 | Advanced Pascal | Schildt | PROG | McGraw | 4 | 350 |
| 4 | Dbase dummies | Palmer | DBMS | PustakM | 5 | 130 |
| 5 | Mastering C + + | Gurewich | PROG | BPB | 3 | 295 |
| 6 | Guide Network | Freed | NET | ZPress | 3 | 200 |
| 7 | Mastering Foxpro | Seigal | DBMS | BPB | 2 | 135 |
| 8 | DOS guide | Norton | OS | PHI | 3 | 175 |
| 9 | Basic for Beginners | Morton | PROG | BPB | 3 | 40 |
| 10 | Mastering Window | Cowart | OS | BPB | 1 | 225 |
Give the output of following SQL commands on the basis of table Library.
(i) SELECT UPPER(Title) FROM Library WHERE Price < 150 ;
(ii) SELECT CONCAT(Author, Type) FROM Library WHERE Qty < 3 ;
(iii) SELECT MOD(Qty, 4) FROM Library ;
(i) SELECT UPPER(Title) FROM Library WHERE Price < 150 ;
+---------------------+
| UPPER(Title) |
+---------------------+
| COMPUTER STUDIES |
| DBASE DUMMIES |
| MASTERING FOXPRO |
| BASIC FOR BEGINNERS |
+---------------------+
The SQL query SELECT UPPER(Title) FROM Library WHERE Price < 150; returns the uppercase version of the Title column for all rows in the LIBRARY table where the Price column is less than 150.
(ii) SELECT CONCAT(Author, Type) FROM Library WHERE Qty < 3 ;
+----------------------+
| CONCAT(Author, Type) |
+----------------------+
| FrenchFND |
| SeigalDBMS |
| CowartOS |
+----------------------+
The query SELECT CONCAT(Author, Type) FROM Library WHERE Qty < 3; concatenates the Author and Type columns using the CONCAT() function from the LIBRARY table for books that have a quantity less than 3.
(iii) SELECT MOD(Qty, 4) FROM Library ;
+-------------+
| MOD(Qty, 4) |
+-------------+
| 0 |
| 2 |
| 0 |
| 1 |
| 3 |
| 3 |
| 2 |
| 3 |
| 3 |
| 1 |
+-------------+
The SQL query SELECT MOD(Qty, 4) FROM Library; calculates the remainder when each book's quantity (Qty) in the LIBRARY table is divided by 4 using the MOD() function.