Вы находитесь на странице: 1из 5

Hardik Choudhary

N212 ,70471118013
PART B
Q.1 Write the following simple SQL Queries on the University Schema
a. Find the names of all the students whose total credits are greater than 100

b. Find the course id and grades of all courses taken by any student named 'Tanaka'

c. Find the ID and name of instructors who have taught a course in the Comp. Sci. department, even
if they are themselves not from the Comp. Sci. department. To test this query, make sure you add
appropriate data, and include the corresponding insert statements along with your query.

d. Find the courses which are offered in both 'Fall' and 'Spring' semester (not necessarily in the same
year).
e. Find the names of all the instructors from Comp. Sci. department

f. Find the course id and titles of all courses taught by an instructor named 'Srinivasan'

g. Find names of instructors who have taught at least one course in Spring 2009
Q.3 Write the following Queries for Railway Schema
Find pairs of stations (station codes) that have a track (direct connection) with distance less than 20Kms
between them

a. Find the IDs of all the trains which have a stop at THANE

b. Find the names of all trains that start at MUMBAI.


c. List all the stations in order of visit by the train 'CST-AMR_LOCAL'.

d. Find the name of the trains which have stop at Thane, before the 6th station in the route of the
train.

1.       Explain the use of % and _ in pattern matching with suitable examples.
 
% (percent sign) allows you to match any string of any length (including zero
length)
_ (underscore) allows you to match on a single character.
 

2.       Explain the use of extract function with suitable examples.


LIKE Syntax
SELECT column1, column2, ...
FROM table_name
WHERE columnN LIKE pattern;
Tip: You can also combine any number of conditions using AND or OR operators.
 
Here are some examples showing different LIKE operators with '%' and '_'
wildcards:
 
LIKE Operator    Description
WHERE CustomerName LIKE 'a%'      Finds any values that start with "a"
WHERE CustomerName LIKE '%a'      Finds any values that end with "a"
WHERE CustomerName LIKE '%or%' Finds any values that have "or" in any
position
WHERE CustomerName LIKE '_r%'    Finds any values that have "r" in the second
position
WHERE CustomerName LIKE 'a__%'  Finds any values that start with "a" and are
at least 3 characters in length
WHERE ContactName LIKE 'a%o'       Finds any values that start with "a" and ends
with "o"

3.       Does WHERE clause work with aggregate functions?


 
                   You cannot use aggregate functions in a WHERE clause or in a JOIN condition. However, a
SELECT statement with aggregate functions in its select list often includes a WHERE clause that
restricts the rows to which the aggregate is applied
 
 
4.       What is the alternative of in operator?
5.        SELECT userID,
6.                     Memberid
7.              FROM   Member
8.                     INNER JOIN [USER]
9.                       ON UserMemberID = MemberiD
10.           WHERE  EXISTS  (SELECT *
11.                          FROM   @dtUserIds a where [user].userId = a.Uniqueid)

Вам также может понравиться