Advertisements
Advertisements
प्रश्न
Write the output of the queries (i) to (iv) based on the table, WORKER given below:
TABLE: WORKER
W_ID | F_NAME | L_NAME | CITY | STATE |
102 | SAHIL | KHAN | KANPUR | UTTAR PRADESH |
104 | SAMEER | PARIKH | ROOP NAGAR | PUNJAB |
105 | MARY | JONES | DELHI | DELHI |
106 | MAHIR | SHARMA | SONIPAT | HARYANA |
107 | ATHARVA | BHARDWAJ | DELHI | DELHI |
108 | VEDA | SHARMA | KANPUR | UTTAR PRADESH |
SELECT F_NAME, CITY FROM WORKER ORDER BY STATE DESC;
SELECT DISTINCT (CITY) FROM WORKER;
SELECT F_NAME, STATE FROM WORKER WHERE L_NAME LIKE '_HA%';
SELECT CITY, COUNT(*) FROM WORKER GROUP BY CITY;
उत्तर
F_Name City MARY DELHI ATHARVA DELHI MAHIR SONIPAT SAMEER ROOP NAGAR SAHIL KANPUR VEDA KANPUR - DISTINCT(CITY)
KANPUR
ROOP NAGAR
DELHI
SONIPAT
F_Name STATE SAHIL UTTAR PRADESH MAHIR HARYANA ATHARVA DELHI VEDA UTTAR PRADESH
CITY COUNT(*) KANPUR 2 DELHI 1 ROOP NAGAR 2 SONIPAT 1
APPEARS IN
संबंधित प्रश्न
Which of the following is not a comparison query?
Consider the following SQL.
SELECT ______ FROM Employee WHERE Dept= 'Printing';
Which of the following should be used to find the mean of the salary?
Which of the following is not a constraint?
Which constraint ensures that all the values in a column are distinct/unique?
How will you retrieve all details of employee_detail table?
Activity table is related to student table and every student has been asked to enroll for minimum 2 activities. While checking the records select student id from activity; lots of duplicate entries were found as students are enrolling for more than one activity. It is becoming difficult to understand who all have still not enrolled for any activity. We can use ______ clause with student_id to resolve the issue.
Consider the following MOVIE table and write the SQL query based on it.
MovieID | MovieName | Category | ReleaseDate | ProductionCost | BusinessCost |
001 | Hindi_Movie | Musical | 2018-04-23 | 124500 | 130000 |
002 | Tamil_Movie | Action | 2016-05-17 | 112000 | 118000 |
003 | English_Movie | Horror | 2017-08-06 | 245000 | 360000 |
004 | Bengali_Movie | Adventure | 2017-01-04 | 72000 | 100000 |
005 | Telugu_Movie | Action | - | 100000 | - |
006 | Punjabi_Movie | Comedy | - | 30500 | - |
- Display all the information from the Movie table.
- List business is done by the movies showing only MovieID, MovieName, and Total_Earning. Total_ Earning to be calculated as the sum of ProductionCost and BusinessCost.
- List the different categories of movies.
- Find the net profit of each movie showing its MovieID, MovieName, and NetProfit. Net Profit is to be calculated as the difference between Business Cost and Production Cost.
- List MovieID, MovieName, and Cost for all movies with ProductionCost greater than 10,000 and less than 1,00,000.
- List details of all movies which fall in the category of comedy or action.
- List details of all movies which have not been released yet.
Consider the following MOVIE table and write the SQL query based on it.
MovieID | MovieName | Category | ReleaseDate | ProductionCost | BusinessCost |
001 | Hindi_Movie | Musical | 2018-04-23 | 124500 | 130000 |
002 | Tamil_Movie | Action | 2016-05-17 | 112000 | 118000 |
003 | English_Movie | Horror | 2017-08-06 | 245000 | 360000 |
004 | Bengali_Movie | Adventure | 2017-01-04 | 72000 | 100000 |
005 | Telugu_Movie | Action | - | 100000 | - |
006 | Punjabi_Movie | Comedy | - | 30500 | - |
List MovieID, MovieName, and Cost for all movies with ProductionCost greater than 10,000 and less than 1,00,000.
Consider the following MOVIE table and write the SQL query based on it.
MovieID | MovieName | Category | ReleaseDate | ProductionCost | BusinessCost |
001 | Hindi_Movie | Musical | 2018-04-23 | 124500 | 130000 |
002 | Tamil_Movie | Action | 2016-05-17 | 112000 | 118000 |
003 | English_Movie | Horror | 2017-08-06 | 245000 | 360000 |
004 | Bengali_Movie | Adventure | 2017-01-04 | 72000 | 100000 |
005 | Telugu_Movie | Action | - | 100000 | - |
006 | Punjabi_Movie | Comedy | - | 30500 | - |
List details of all movies which fall in the category of comedy or action.
Consider the following MOVIE table and write the SQL query based on it.
MovieID | MovieName | Category | ReleaseDate | ProductionCost | BusinessCost |
001 | Hindi_Movie | Musical | 2018-04-23 | 124500 | 130000 |
002 | Tamil_Movie | Action | 2016-05-17 | 112000 | 118000 |
003 | English_Movie | Horror | 2017-08-06 | 245000 | 360000 |
004 | Bengali_Movie | Adventure | 2017-01-04 | 72000 | 100000 |
005 | Telugu_Movie | Action | - | 100000 | - |
006 | Punjabi_Movie | Comedy | - | 30500 | - |
List details of all movies which have not been released yet.
Consider the following tables – Bank_Account and Branch:
Table: Bank_Account
ACode | Name | Type |
A01 | Amrita | Savings |
A02 | Parthodas | Current |
A03 | Miraben | Current |
Table: Branch
ACode | City |
A01 | Delhi |
A02 | Mumbai |
A01 | Nagpur |
What will be the output of the following statement?
SELECT * FROM Bank_Account NATURAL JOIN Branch;
Write the outputs of the SQL queries (i) to (iv) based on the relations COMPUTER and SALES given below:
Table: COMPUTER | ||||
PROD_ID | PROD_NAME | PRICE | COMPANY | TYPE |
P001 | MOUSE | 200 | LOGITECH | INPUT |
P002 | LASER PRINTER | 4000 | CANON | OUTPUT |
P003 | KEYBOARD | 500 | LOGITECH | INPUT |
P004 | JOYSTICK | 1000 | IBALL | INPUT |
P005 | SPEAKER | 1200 | CREATIVE | OUTPUT |
P006 | DESKET PRINTER | 4300 | CANON | OUTPUT |
Table: SALES | ||
PROD_ID | QTY_SOLD | QUARTER |
P002 | 4 | 1 |
P003 | 2 | 2 |
P001 | 3 | 2 |
P004 | 2 | 1 |
SELECT MIN(PRICE), MAX(PRICE) FROM COMPUTER;
SELECT COMPANY, COUNT(*) FROM COMPUTER GROUP BY COMPANY HAVING COUNT(COMPANY) > 1;
SELECT PROD_NAME, QTY_SOLD FROM COMPUTER C, SALES S WHERE C.PROD_ID=S.PROD_ID AND TYPE = 'INPUT';
SELECT PROD_NAME, COMPANY, QUARTER FROM COMPUTER C, SALES S WHERE C.PROD_ID=S.PROD_ID;
The code given below reads the following records from the table employee and displays only those records that have employees coming from the city 'Delhi':
E_code
- StringE_name
- StringSal
- IntegerCity
- String
Note the following to establish connectivity between Python and MySQL:
- Username is
root
- Password is
root
- The table exists in a MySQL database named
emp
. - The details
(E_code,E_name,Sal,City)
are the attributes of the table.
Write the following statements to complete the code:
Statement 1 - to import the desired library.
Statement 2 - to execute the query that fetches records of the employees/coming from the city ‘Delhi’.
Statement 3 - to read the complete data of the query (rows whose city is Delhi) into the object named details, from the table employee in the database.
import ____________ as mysql #Statement 1
def display():
mydb=mysql.connect(host="localhost",user="root"
passwd="root", database=" emp")
mycursor=mydb.cursor()
____________ #Statement 2
details = ____________ # Statement 3
for i in details:
print (i)
Consider the tables PRODUCT and BRAND given below:
Table: PRODUCT | ||||
PCode | PName | UPrice | Rating | BID |
P01 | Shampoo | 120 | 6 | M03 |
P02 | Toothpaste | 54 | 8 | M02 |
P03 | Soap | 25 | 7 | M03 |
P04 | Toothpaste | 65 | 4 | M04 |
P05 | Soap | 38 | 5 | M05 |
P06 | Shampoo | 245 | 6 | M05 |
Table: BRAND | |
BID | BName |
M02 | Dant Kanti |
M03 | Medimix |
M04 | Pepsodent |
M05 | Dove |
Write SQL queries for the following:
- Display product name and brand name from the tables PRODUCT and BRAND.
- Display the structure of the table PRODUCT.
- Display the average rating of Medimix and Dove brands.
- Display the name, price, and rating of products in descending order of rating.