Question

Consider the table "Grocer "and write SQL queries for the tasks that follow:

Table: Charity

Item_Id ItemName UnitPrice Quantity (kg) Date_Purchase
1 Rice 52.50 80 2010-02-01
2 Wheat 25.40 50 2010-03-09
3 Corn 50.80 100 2010-03-11
4 Semolina 28.90 50 2010-01-15

(Unit Price is per kg. price)

(i) Display Item name, unit price along with Date of purchase for all the Items.

(ii) Display Item name along with Month (in number) when it was purchased for all the items.

(iii) Display Item name along with year in which it was purchased for all the items.

(iv) Display Item Id, Date of Purchase and day name of week (e.g. Monday) on which it was purchased for all the items.

(v) Display names of all the items that were purchased on Mondays or Tuesdays.

(vi) Display the day name of the week on which Rice was purchased.

(vii) Display the Item name and unit price truncated to integer value (no decimal digits) of all the items.

(viii) Display current date.

Answer

Get the step-by-step solution for this question inside the Vidyadip app.

Get the answer in the app

Need a full question paper?

Generate a complete, print-ready paper with questions like this in minutes — across 16+ boards, with answer keys.

Start Generating Free

Similar questions

Web Server is an uncommon PC framework running on HTTP through website pages. The page is a medium to convey information starting with one PC framework then onto the next. The working of the webserver begins from the customer or client. The client sends their request through the web browser to the webserver. Web server takes this request, processes it, and then sends back processed data to the client. The server gathers all of our web page information and sends it to the user, which we see on our Computer System n the form of a web pag(e) When the client sends a request for processing to the web server, a domain name and IP address are important to the webserver. The domain name and IP address are used to identify the user on a large network.

(a) A piece of icon or image on a web page associated with another webpage is called ______

(i)URL (ii) Hyperlink(iii)Plugin(iv)Extension

(b) Web servers are:

(i)IP addresses

(ii)Computer systems

(iii)Webpages of a site

(iv)A medium to carry data from one computer to another.

(c) The _______ translates internet domain and host names to IP address.

(i)Domain name system

(ii)Routing information protocol

(iii)Google

(iv)Networktime protocol

(d) What does the webserver need to send back information to the user?

(i)Home address

(ii) Domain name

(iii)IP address

(iv)Both (ii) and (iii)

(e) What is the full form of HTTP?

(i)Hypertext Transfer Protocol

(ii)Hypertext Transfer Procedure

(iii)Hyperlink Transfer Protocol

(iv)Hyperlink Transfer Procedure

Write SQL queries for (i) to (iv) and find outputs for SQL queries (v) to (vii), which are based on the tables. [CBSE Sample Paper 2018]

Table: Trainer

TID Tname City HireDate Salary
101 Sunaina Mumbai 1998-10-15 90000
102 Anamika Delhi 1994-12-24 80000
103 Deepti Chandigarh 2001-12-21 82000
104 Meenakshi Delhi 2002-12-25 78000
105 Richa Mumbai 1996-01-12 95000
106 Maniprabha Chennai 2001-12-12 69000

Table: Course

CID CNAME FEES STARTDATE TID
C201 AGDCA 12000 2018-07-02 101
C202 ADCA 15000 2018-07-15 103
C203 DCA 10000 2018-10-01 102
C203 DDTP 9000 2018-09-15 104
C205 DHN 20000 2018-08-01 101
C206 O LEVEL 18000 2018-07-25 105

(a) Display the Trainer Name, City and Salary in descending order of their hire date.

(b) To display the TNAME and CITY of Trainer of joined the institute in the month of December 2001.

(c) To display TNAME, HIREDATE,CNAME, STARTDATE from tables TRAINER and COURSE whose FEES is less than or equal to 10000

(d) To display number of trainer from each city (e) select tid, tname,from trainer where city not in(‘delhi’,’mumbai’);

(f) select distinct tid from course;

(g) select tid , count (*), min(fees) from course group by tid having count(*)>1;

(h) Select count(*),sum(fees) from course where startdate <’2018-09-15’;

Answer the following questions.

Vehicle

Challan

Offence

(a) Based on these tables write SQL statements for the following queries:

(i) Display the dates of first registration and last registration from the table Vehicle.

(ii) Display the number of challans issued on each date.

(iii) Display the total number of challans issued for each offence.

(iv) Display the total number of vehicles for which the 3rd and 4th characters of RegNo are '6C'.

(v) Display the total value of challans issued for which the Off_Desc is 'Driving without License'.

(vi) Display details of the challans issued on '2010-04-03' along with Off_Desc for each challan.

(vii) Display the RegNo of all vehicles which have been challaned more than once.

(viii) Display details of each challan alongwith vehicle details, Off_desc, and Challan_Amt.

(b) Identify the Foreign Keys (if any) of these tables. Justify your choices.

(c) Should any of these tables have some more column(s)? Think, discuss in peer groups, and discuss with your teacher.

Answer the following questions on the basis of given data set:

index date duration item month network network_type
0 0 15/10/14 06:58 34.429 data 2014-11 data data
1 1 15/10/14 06:58 13.000 call 2014-11 Vodafone mobile
2 2 15/10/14 14:46 23.000 call 2014-11 Airtel mobile
3 3 15/10/14 14:48 4.000 call 2014-11 data mobile
4 4 15/10/14 17:27 4.000 call 2014-11 Airtel mobile
5 5 15/10/14 18:55 4.000 call 2014-11 Airtel mobile
6 6 16/10/14 06:58 34.429 call 2014-11 data data
7 7 16/10/14 15:01 602.000 call 2014-11 Vodafone mobile
8 8 16/10/14 15:12 1050.000 call 2014-11 Airtel mobile
9 9 16/10/14 15:30 19.000 call 2014-11 voicemail voicemail
10 10 16/10/14 16:21 1183.000 call 2014-11 Vodafone mobile
11 11 16/10/14 22:18 1.000 sms 2014-11 Airtel mobile
12 12 16/10/14 22:21 1.000 sms 2014-11 Vodafone mobile
13 13 17/10/14 06:58 34.429 data 2014-11 data data

(i) To count the rows in the dataset

(ii) What was the longest phone call / data entry?

(iii) How many seconds of phone calls are recorded in total?

(iv) How many entries are there for each month?

(v) To print the group key

(vi) To count the group keys

(vii) Get the first entry for each month

(viii) Get the sum of the durations per month

(ix) Get the number of dates / entries in each month

(x) What is the sum of durations, for calls only, to each network

(xi) How many calls, sms, and data entries are in each month?

(xii) How many calls, texts, and data are sent per month, split by network_type?

(xiii) Group the data frame by month and item and extract a number of stats from each group

(xiv) Group the data frame by month and item and extract a number of stats from each group

Answer the questions given below based on the given dataset:

(i) To print the name of the libraries required.

(ii) To create the data frame for the above data.

(iii) To Display a summary of the basic information about this DataFrame and its data.

(iv) To display first 3 rows of the DataFramedf.

(v) Select just the 'animal' and 'age' columns from the DataFramedf

(vi) Select the data in rows [3, 4, 8] and in columns ['animal', 'age'].

(vii) Select only the rows where the number of visits is greater than 3.

(viii) Select the rows where the age is missing, i.e. is NaN.

(ix) Select the rows where the animal is a cat and the age is less than 3.

(x) Select the rows the age is between 2 and 4 (inclusive).

(xi) Change the age in row 'f' to 1.5.

(xii) Append a new row 'k' to df with your choice of values for each column. Then delete that row to return the original DataFrame.

(xiii) In the 'animal' column, change the 'snake' entries to 'python'.

On the basis of given dataframe answer the following questions:

Account Name Rep Manager Product Quantity Price Status
0 714466 Tata Saryu Abhishek CPU 1 30000 presented
1 714466 Tata Saryu Abhishek Software 1 10000 presented
2 714466 Tata Saryu Abhishek Maintenance 2 5000 pending
3 737550 Infosys Saryu Abhishek CPU 1 35000 declined
4 146832 Sapient Taneja Abhishek CPU 2 65000 won
5 218895 IBM Taneja Abhishek CPU 2 40000 pending
6 218895 IBM Taneja Abhishek Software 1 10000 presented
7 412290 Oracle Joe Abhishek Maintenance 2 5000 pending
8 740150 Flipkart Joe Abhishek CPU 1 35000 declined
9 141962 Byju Charu Arush CPU 2 65000 won
10 163416 Gradup Charu Arush CPU 1 30000 presented
11 239344 Funtoot Charu Arush Maintenance 1 5000 pending
12 239344 Funtoot Charu Arush Software 1 10000 presented
13 307599 SQL Naveen Arush Maintenance 3 7000 won
14 688981 PiE Naveen Arush CPU 5 100000 won
15 729833 Amazon Naveen Arush CPU 2 65000 declined
16 729833 Amazon Naveen Arush Monitor 2 5000 presented

(i) To print the complete dataframe Name wise.

(ii) To print the dataframe Name wise, Rep waise and Manage wise.

(iii) To print the data frame Manager and Rep wise.

(iv) To print the data frame Manager and Rep price wise

(v) To print the sum of the price, manager and rep wise.

(vi) To print the mean and count of the price which belong to each manager and rep.

(vii) To print the sum of the price which belong to each manager and rep.

(viii) To print the sum of the price which belong to each manager and rep along with Product belongs to them. Fill the NaN with 0.

With reference to the given data frame answer the questions given below:

id name host_id host_name neighbourhood_group neighbourhood latitude longitude
0 2539 Clean & quiet apt
home by the park
2787 John Brooklyn Kensignton 40.64749 -73.97237
1 2595 Skylit Midtown
Castle
2845 Jennifer Manhattan Midtown 40.75362 -73.98377
2 3647 The Village
Of Harlem ...
New York !
4632 Elisabeth Manhattan Harlem 40.80902 -73.94190
3 3831 Cozy Entire Floor
of Brownstone
4869 LisaRoxanne Brooklyn Clinton Hill 40.68514 -73,95976
4 5022 Entire Apt:
Spacious Studio/
Loft by central park
7192 Laura Manhattan East Harlem 40.79851 -73.94399
5 5099 Large Cozy 1BR
Apartment in
Midtown East
7322 Chris Manhattan Murray Hill 40.74767 -73.97500
6 5121 BlissArtsSpace! 7356 Garon Brooklyn Bedford-Stuyvesant 40.68688 -7395596
7 5178 Large Furnished
Room Near Bway
8967 Shunichi Manhattan Hell’s Kitchen 40.76489 -73.98493

Assuming that other file is stored in CSV format named “nysc.csv” Import pandas as pd

(i) To create the Data frame of the above data.

(ii) To print the first 10 records

(iii) To display the name and Id.

Answer the question below based on given dataset:

DataFrame: dfzoo

animal uniq_id water_need
0 Elephant 1001 500
1 Elephant 1002 600
2 Elephant 1003 550
3 Tiger 1004 300
4 Tiger 1005 320
5 Tiger 1006 330
6 Tiger 1007 290
7 Tiger 1008 310
8 Zebra 1009 200
9 Zebra 1010 220
10 Zebra 1011 240
11 Zebra 1012 230
12 Zebra 1013 220
13 Zebra 1013 100
14 Zebra 1014 80
15 Lion 1015 420
16 Lion 1016 600
17 Lion 1017 500
18 Lion 1018 390
19 Kangaroo 1019 410
20 Kangaroo 1020 430
21 Kangaroo 1021 410

(i) Counting all the animals

(ii) Count the number of animals in zoo

(iii) To print the sum of the water need of an animals.

(iv) To print the sum of all values.

(v) To print the sum of only numeric values.

(vi) To print the minimum values of water need.

(vii) To print the mean values of water need.

(viii) To print the median values of water need.

(ix) To print the animal wise means value.

(x) To print the mean value water need of an each animal.

Mr. Mathew is a programmer, who has recently joined the company and given a task to write a python code to perform update operation in binary file (stud.dat) which contain admno (Admission No) and fee(Fee paid by student).

He has succeeded in writing partial code and has missed out certain statements, You as an expert of Python have to provide the missing statements.

(a)

Mr. Sharma is working with an IT company and he was provided with some data. On which he wants to do some operations but he is facing some problem, help him in resolving:

Amit Ram Sam Roja Monan
Maths 90 92 89 81 94
Science 91 81 91 71 95
Hindi 97 96 88 67 99

(a) He wants to add a new column with name of student ‘Prem’ in above data frame choose the right command to do so:

(b) He wants to set all the values to zero in data frame, choose the right command to do so:

Amit Ram Sam Roja Monan Prem
Maths 0 0 0 0 0 0
Science 0 0 0 0 0 0
Hindi 0 0 0 0 0 0

(i) DF=0 (ii) DF[]=0

(iii) DF[:]=0 (iv) DF[:]==0

(c) He want to delete the row of Science marks:

(i) DF.drop(‘Science’, axis=1)

(ii) Dfdrop(‘Science’, axis=0)

(iii) dfdrop(‘Science’, axis=-1)

(iv) dfdrop(‘Science’, axis==0)

(d) What will be the output of the given command?

DFindex=[‘A’,’B’,’C’]

(iv) Error, Index already exist cannot be overwrite

Amit Ram Sam Roja Manan
A 90 92 89 81 94
B 91 81 91 71 95
C 97 96 88 67 99

(e) The given code is to create another data frame, which he want to add to existing Data Frame choose the right command to do so:

Sheet1={

‘Aaradhya’: pdSeries([90, 91, 97],

index=[‘Maths’,’Science’,’Hindi’])}

S1=pdDataFrame(Sheet1)

(i) Df.append(S1,axis=0)

(ii) Df.append(S1)

(iii) Df.insert(S1)

(iv) Df.join(S1)