Informatics Practices
Write suitable SQL query for the following :
(i) Display 7 characters extracted from 7th left character onwards from the string 'INDIA SHINING'.
(ii) Display the position of occurrence of string 'COME' in the string 'WELCOME WORLD'.
(iii) Round off the value 23.78 to one decimal place.
(iv) Display the remainder of 100 divided by 9.
(v) Remove all the expected leading and trailing spaces from a column userid of the table 'USERS'.
SQL Queries
5 Likes
Answer
(i)
SELECT SUBSTR('INDIA SHINING', 7, 7);
Output
+-------------------------------+
| SUBSTR('INDIA SHINING', 7, 7) |
+-------------------------------+
| SHINING |
+-------------------------------+
(ii)
SELECT INSTR('WELCOME WORLD', 'COME');
Output
+--------------------------------+
| INSTR('WELCOME WORLD', 'COME') |
+--------------------------------+
| 4 |
+--------------------------------+
(iii)
SELECT ROUND(23.78, 1);
Output
+-----------------+
| ROUND(23.78, 1) |
+-----------------+
| 23.8 |
+-----------------+
(iv)
SELECT MOD(100, 9);
Output
+-------------+
| MOD(100, 9) |
+-------------+
| 1 |
+-------------+
(v)
SELECT TRIM(userid) FROM USERS;
Answered By
3 Likes
Related Questions
Find the output of the following SQL Query :
SELECT MOD(ROUND (13.9, 0), 3);
Write the SQL functions which will perform the following operations :
(i) To display the name of the month of the current date.
(ii) To remove spaces from the beginning and end of a string, "Panorama".
(iii) To display the name of the day e.g., Friday or Sunday from your date of birth, dob.
(iv) To display the starting position of your first name(fname) from your whole name (name).
(v) To compute the remainder of division between two numbers, n1 and n2.
Based on the SQL table CAR_SALES, write suitable queries for the following :
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) Display fuel wise average sales in the first quarter.
(ii) Display segment wise highest sales in the second quarter.
(iii) Display the records in the descending order of sales in the second quarter.
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";