0% found this document useful (0 votes)
34 views2 pages

Assignment 5

The document discusses relational and logical operators through examples of SQL queries. It shows 6 examples of queries using operators like >, <, =, AND, OR and NOT to filter records based on conditions. The output for each query is also displayed.

Uploaded by

meghana mahajan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views2 pages

Assignment 5

The document discusses relational and logical operators through examples of SQL queries. It shows 6 examples of queries using operators like >, <, =, AND, OR and NOT to filter records based on conditions. The output for each query is also displayed.

Uploaded by

meghana mahajan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Assignment –5

Relational and Logical Operators.


=================================

1) Write a query that will give you all orders for more than Rs. 1,000.
==>select * from orders where amt>1000;
+------+---------+------------+------+------+
| Onum | Amt | Odate | Cnum | Snum |
+------+---------+------------+------+------+
| 3002 | 1900.10 | 1990-10-03 | 2007 | 1004 |
| 3005 | 5160.45 | 1990-10-03 | 2003 | 1002 |
| 3006 | 1098.16 | 1990-10-03 | 2008 | 1007 |
| 3009 | 1713.23 | 1990-10-04 | 2002 | 1003 |
| 3008 | 4723.00 | 1990-10-05 | 2006 | 1001 |
| 3010 | 1309.95 | 1990-10-06 | 2004 | 1002 |
| 3011 | 9891.88 | 1990-10-06 | 2006 | 1001 |
+------+---------+------------+------+------+
7 rows in set (0.00 sec)
-----------------------------------------------------------------------------------

2) Write a query that will give you the names and cities of all salespeople in
London with a commission above .10.
==> select sname,city from sales where city="london" AND comm>0.10;
+--------+--------+
| sname | city |
+--------+--------+
| Peel | London |
| Motika | London |
+--------+--------+
2 rows in set (0.00 sec)
-----------------------------------------------------------------------------------
-

3) Write a query on the Customers table whose output will exclude all customers
with a rating <= 100, unless they are located in Rome.
==> select * from customers where rating<=100 or city="rome";
+------+----------+--------+--------+------+
| Cnum | Cname | City | Rating | Snum |
+------+----------+--------+--------+------+
| 2001 | Hoffman | London | 100 | 1001 |
| 2002 | Giovanni | Rome | 200 | 1003 |
| 2006 | Clemens | London | 100 | 1001 |
| 2007 | Pereira | Rome | 100 | 1004 |
+------+----------+--------+--------+------+
4 rows in set (0.00 sec)
-----------------------------------------------------------------------------------
-

4) What will be the output from the following query?

Select * from Orders


where (amt < 1000 OR NOT (odate = ‘1990-10-03’ AND cnum > 2003));
==>
SELECT *
FROM Orders
WHERE (amt < 1000
OR NOT (odate = "1990-10-03"AND cnum > 2003));
+------+---------+------------+------+------+
| Onum | Amt | Odate | Cnum | Snum |
+------+---------+------------+------+------+
| 3001 | 18.69 | 1990-10-03 | 2008 | 1007 |
| 3003 | 767.19 | 1990-10-03 | 2001 | 1001 |
| 3005 | 5160.45 | 1990-10-03 | 2003 | 1002 |
| 3009 | 1713.23 | 1990-10-04 | 2002 | 1003 |
| 3007 | 75.75 | 1990-10-04 | 2004 | 1002 |
| 3008 | 4723.00 | 1990-10-05 | 2006 | 1001 |
| 3010 | 1309.95 | 1990-10-06 | 2004 | 1002 |
| 3011 | 9891.88 | 1990-10-06 | 2006 | 1001 |
+------+---------+------------+------+------+
8 rows in set (0.01 sec)

----------------------------------------------------------------
5) What will be the output of the following query?

Select * from Orders


where NOT ((odate = "1990-10-03" OR snum >1006) AND amt >= 1500);
==>
+------+---------+------------+------+------+
| Onum | Amt | Odate | Cnum | Snum |
+------+---------+------------+------+------+
| 3001 | 18.69 | 1990-10-03 | 2008 | 1007 |
| 3003 | 767.19 | 1990-10-03 | 2001 | 1001 |
| 3006 | 1098.16 | 1990-10-03 | 2008 | 1007 |
| 3009 | 1713.23 | 1990-10-04 | 2002 | 1003 |
| 3007 | 75.75 | 1990-10-04 | 2004 | 1002 |
| 3008 | 4723.00 | 1990-10-05 | 2006 | 1001 |
| 3010 | 1309.95 | 1990-10-06 | 2004 | 1002 |
| 3011 | 9891.88 | 1990-10-06 | 2006 | 1001 |
+------+---------+------------+------+------+
8 rows in set (0.00 sec)

---------------------------------------------------------------------------
6) What is a simpler way to write this query?

Select snum, sname, city, comm From Sales


where (comm > .12 OR comm <.14 );
==> Select snum, sname, city, comm From Sales
where comm=0.13;

+------+--------+----------+------+
| snum | sname | city | comm |
+------+--------+----------+------+
| 1002 | Serres | San Jose | 0.13 |
+------+--------+----------+------+
1 row in set (0.00 sec)

==================================================================================

=============================================================================

You might also like