0% found this document useful (0 votes)
15 views3 pages

201126

The document contains examples of SQL queries being run on various databases including counts, sums, averages, maximums, minimums and groups being selected with filters on tables like staff, propertyforrent, viewing, and branch.

Uploaded by

achalaHM
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)
15 views3 pages

201126

The document contains examples of SQL queries being run on various databases including counts, sums, averages, maximums, minimums and groups being selected with filters on tables like staff, propertyforrent, viewing, and branch.

Uploaded by

achalaHM
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/ 3

1)

mysql> select count(comment) from viewing;


+----------------+
| count(comment) |
+----------------+
| 4 |
+----------------+
1 row in set (0.00 sec)

2)

mysql> select count(branchNo) from branch where city="London";


+-----------------+
| count(branchNo) |
+-----------------+
| 2 |
+-----------------+
1 row in set (0.05 sec)

3)

mysql> select count(staffNo)from staff where sex="F" and position ="Assistant";


+----------------+
| count(staffNo) |
+----------------+
| 2 |
+----------------+
1 row in set (0.05 sec)

4)

mysql> select min(salary) from staff where position = "Assistant";


+-------------+
| min(salary) |
+-------------+
| 9000 |
+-------------+
1 row in set (0.03 sec)

5)mysql> select max(rent) from propertyforrent where type = "Flat" and city =
"Glasgow";
+-----------+
| max(rent) |
+-----------+
| 450 |
+-----------+
1 row in set (0.00 sec)

6)

mysql> select avg(salary) from staff where position like "Manager";


+-------------+
| avg(salary) |
+-------------+
| 16000.0000 |
+-------------+
1 row in set (0.05 sec)
7)

mysql> select sum(rent*12) as "Annual income" from propertyforrent;


+---------------+
| Annual income |
+---------------+
| 33900 |
+---------------+
1 row in set (0.00 sec)

8)

mysql> select sum(salary) as "Monthly Cost",sum(salary*12) as "Annual Cost" from


staff;
+--------------+-------------+
| Monthly Cost | Annual Cost |
+--------------+-------------+
| 87000 | 1044000 |
+--------------+-------------+
1 row in set (0.00 sec)

9)

mysql> select count(type),sum(rent) as "Monthly income" from propertyforrent where


type like "Flat";
+-------------+----------------+
| count(type) | Monthly income |
+-------------+----------------+
| 4 | 1575 |
+-------------+----------------+
1 row in set (0.00 sec)

10)

mysql> select min(salary),max(salary),avg(salary) from staff where position like


"Assistant";
+-------------+-------------+-------------+
| min(salary) | max(salary) | avg(salary) |
+-------------+-------------+-------------+
| 9000 | 12000 | 10500.0000 |
+-------------+-------------+-------------+
1 row in set (0.00 sec)

11)
mysql> select count(staffNo),position from staff group by position;
+----------------+------------+
| count(staffNo) | position |
+----------------+------------+
| 2 | Assistant |
| 3 | Manager |
| 1 | Supervisor |
+----------------+------------+
3 rows in set (0.08 sec)

12)

mysql> select count(propertyNo),branchNo from propertyforrent group by branchNo


order by branchNo asc;
+-------------------+----------+
| count(propertyNo) | branchNo |
+-------------------+----------+
| 4 | B003 |
| 1 | B005 |
| 1 | B007 |
+-------------------+----------+
3 rows in set (0.01 sec)

13)

mysql> select count(type),type,max(rent),min(rent)from propertyforrent group by


type,city having city ="Glasgow";
+-------------+-------+-----------+-----------+
| count(type) | type | max(rent) | min(rent) |
+-------------+-------+-----------+-----------+
| 3 | Flat | 450 | 350 |
| 1 | House | 600 | 600 |
+-------------+-------+-----------+-----------+
2 rows in set (0.03 sec)

14)

mysql> select propertyNo,count(viewDate) from viewing where month(viewDate)=5 and


year(viewDate)="2004" group by propertyNo having count(viewDAte)>1;
+------------+-----------------+
| propertyNo | count(viewDate) |
+------------+-----------------+
| PA14 | 2 |
+------------+-----------------+
1 row in set (0.03 sec)

15)

mysql> select avg(salary), position from staff having avg(salary) > 18000;
Empty set (0.00 sec)

16)mysql> select city,branchNo from branch group by city having count(branchNo) =


1;
+----------+----------+
| city | branchNo |
+----------+----------+
| Aberdeen | B007 |
| Bristol | B004 |
| Glasgow | B003 |
+----------+----------+
3 rows in set (0.00 sec)

You might also like