Informatics Practices
Given 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 ;
SQL Queries
3 Likes
Answer
(i) SELECT UPPER(Title) FROM Library WHERE Price < 150 ;
+---------------------+
| UPPER(Title) |
+---------------------+
| COMPUTER STUDIES |
| DBASE DUMMIES |
| MASTERING FOXPRO |
| BASIC FOR BEGINNERS |
+---------------------+
Working
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 |
+----------------------+
Working
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 |
+-------------+
Working
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.
Answered By
3 Likes
Related Questions
Predict the output of the following queries based on the table CAR_SALES given below :
NUMBER SEGMENT FUEL QT1 QT2 1 Compact HatchBack Petrol 56000 70000 2 Compact HatchBack Diesel 34000 40000 3 MUV Petrol 33000 35000 4 MUV Diesel 14000 15000 5 SUV Petrol 27000 54000 6 SUV Diesel 18000 30000 7 Sedan Petrol 8000 10000 8 Sedan Diesel 1000 5000 (i) SELECT LEFT(SEGMENT, 2) FROM CAR_SALES WHERE FUEL= "PETROL";
(ii) SELECT (QT2-QT1)/2 "AVG SALE" FROM CAR_SALES WHERE SEGMENT= "SUV";
(iii) SELECT SUM(QT1) "TOT SALE" FROM CAR_SALES WHERE FUEL= "DIESEL";
Given the following table :
Table : STUDENT1
No. Name Stipend Stream AvgMark Grade Class 1 Karan 400.00 Medical 78.5 B 12B 2 Divakar 450.00 Commerce 89.2 A 11C 3 Divya 300.00 Commerce 68.6 C 12C 4 Arun 350.00 Humanities 73.1 B 12C 5 Sabina 500.00 Nonmedical 90.6 A 11A 6 John 400.00 Medical 75.4 B 12B 7 Robert 250.00 Humanities 64.4 C 11A 8 Rubina 450.00 Nonmedical 88.5 A 12A 9 Vikas 500.00 Nonmedical 92.0 A 12A 10 Mohan 300.00 Commerce 67.5 C 12C Give the output of following SQL statement :
(i) SELECT TRUNCATE(AvgMark) FROM Student1 WHERE AvgMark < 75 ;
(ii) SELECT ROUND(AvgMark) FROM Student1 WHERE Grade = 'B' ;
(iii) SELECT CONCAT(Name, Stream) FROM Student1 WHERE Class = '12A' ;
(iv) SELECT RIGHT(Stream, 2) FROM Student1 ;
Write a query to show the current date and time.
Perform the following question based on these tables :
table PAYDAY (contains one column only) CycleDate DATE table ADDRESS ( contains following eight columns) LastName VARCHAR(25), FirstName VARCHAR(25), Street VARCHAR(50), City VARCHAR(25) State CHAR(2), Zip NUMBER, Phone VARCHAR(12), Ext VARCHAR(5)
Write a query to show the city of user with first name as 'MARK'.