0% found this document useful (0 votes)
41 views10 pages

DBMS Record

The document contains SQL queries and results from multiple database schemas: 1) The first section queries a library database, retrieving book, author, and copy information, and creating views. 2) The second section queries an orders database, retrieving customer and salesperson data, creating another view, and deleting a salesperson record. 3) Additional sections query movie, rating, and college databases, retrieving and updating related data. The document demonstrates various SQL queries across different database schemas.

Uploaded by

VIGHNESHA V
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)
41 views10 pages

DBMS Record

The document contains SQL queries and results from multiple database schemas: 1) The first section queries a library database, retrieving book, author, and copy information, and creating views. 2) The second section queries an orders database, retrieving customer and salesperson data, creating another view, and deleting a salesperson record. 3) Additional sections query movie, rating, and college databases, retrieving and updating related data. The document demonstrates various SQL queries across different database schemas.

Uploaded by

VIGHNESHA V
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/ 10

LIBRARY DATABASE

MariaDB [library]> SELECT B.BOOK_ID, B.TITLE, B.PUB_NAME,


A.AUTHOR_NAME,C.NO_OF_COPIES,L.PROGRAMME_ID
-> FROM BOOK B, BOOK_AUTHORS A, BOOK_COPIES C, LIBRARY_PROGRAMME L
-> WHERE B.BOOK_ID=A.BOOK_ID
-> AND B.BOOK_ID=C.BOOK_ID
-> AND L.PROGRAMME_ID=C.PROGRAMME_ID;
+---------+---------------------+----------+-------------+--------------
+--------------+
| BOOK_ID | TITLE | PUB_NAME | AUTHOR_NAME | NO_OF_COPIES |
PROGRAMME_ID |
+---------+---------------------+----------+-------------+--------------
+--------------+
| 1 | BASICS OF EXCEL | SAPNA | SRI DEVI | 10 |
100 |
| 1 | BASICS OF EXCEL | SAPNA | SRI DEVI | 16 |
101 |
| 2 | PROGRAMMING MINDSET | PLANETZ | DEEPAK | 20 |
102 |
| 2 | PROGRAMMING MINDSET | PLANETZ | DEEPAK | 6 |
103 |
| 3 | BASICS OF SQL | PEARSON | PRAMOD | 4 |
104 |
| 4 | DBMS FOR BEGINNERS | PLANETZ | SWATHI | 3 |
101 |
| 5 | WEB SERVICES | OZONE | PRATHIMA | 7 |
100 |
+---------+---------------------+----------+-------------+--------------
+--------------+
7 rows in set (0.001 sec)

MariaDB [library]> SELECT CARD_NO


-> FROM BOOK_LENDING
-> WHERE DATE_OUT BETWEEN '2017-01-01' AND '2017-06-01'
-> GROUP BY CARD_NO
-> HAVING COUNT(*)>3;
+---------+
| CARD_NO |
+---------+
| 501 |
+---------+
1 row in set (0.006 sec)

MariaDB [library]> DELETE FROM BOOK


-> WHERE BOOK_ID=3;
Query OK, 1 row affected (0.019 sec)

MariaDB [library]>
MariaDB [library]> SELECT * FROM BOOK;
+---------+---------------------+----------+----------+
| BOOK_ID | TITLE | PUB_YEAR | PUB_NAME |
+---------+---------------------+----------+----------+
| 1 | BASICS OF EXCEL | JAN-2017 | SAPNA |
| 2 | PROGRAMMING MINDSET | JUN-2018 | PLANETZ |
| 4 | DBMS FOR BEGINNERS | SEP-2015 | PLANETZ |
| 5 | WEB SERVICES | MAY-2017 | OZONE |
+---------+---------------------+----------+----------+
4 rows in set (0.001 sec)
MariaDB [library]>
MariaDB [library]> CREATE VIEW V_PUBLICATION AS SELECT
-> PUB_YEAR
-> FROM BOOK;
Query OK, 0 rows affected (0.010 sec)

MariaDB [library]>
MariaDB [library]> SELECT * FROM V_PUBLICATION;
+----------+
| PUB_YEAR |
+----------+
| JAN-2017 |
| JUN-2018 |
| SEP-2015 |
| MAY-2017 |
+----------+
4 rows in set (0.001 sec)

MariaDB [library]> CREATE VIEW V_BOOKS AS


-> SELECT B.BOOK_ID, B.TITLE, C.NO_OF_COPIES
-> FROM
-> BOOK B, BOOK_COPIES C, LIBRARY_PROGRAMME L
-> WHERE B.BOOK_ID=C.BOOK_ID
-> AND C.PROGRAMME_ID=L.PROGRAMME_ID;
Query OK, 0 rows affected (0.009 sec)

MariaDB [library]>
MariaDB [library]> SELECT * FROM V_BOOKS;
+---------+---------------------+--------------+
| BOOK_ID | TITLE | NO_OF_COPIES |
+---------+---------------------+--------------+
| 1 | BASICS OF EXCEL | 10 |
| 1 | BASICS OF EXCEL | 16 |
| 2 | PROGRAMMING MINDSET | 20 |
| 2 | PROGRAMMING MINDSET | 6 |
| 4 | DBMS FOR BEGINNERS | 3 |
| 5 | WEB SERVICES | 7 |
+---------+---------------------+--------------+
6 rows in set (0.001 sec)

Sales_Order Database

MariaDB [ORDERS]> SELECT GRADE,COUNT(DISTINCT CUSTOMER_ID)


-> FROM CUSTOMER
-> GROUP BY GRADE
-> HAVING GRADE>(SELECT AVG(GRADE)
-> FROM CUSTOMER
-> WHERE CITY='BANGALORE');
+-------+-----------------------------+
| GRADE | COUNT(DISTINCT CUSTOMER_ID) |
+-------+-----------------------------+
| 300 | 1 |
| 400 | 2 |
+-------+-----------------------------+
2 rows in set (0.004 sec)

MariaDB [ORDERS]> SELECT SALESMAN_ID, NAME


-> FROM SALESMAN S
-> WHERE (SELECT COUNT(*)
-> FROM CUSTOMER C
-> WHERE C.SALESMAN_ID=S.SALESMAN_ID) > 1;
+-------------+--------+
| SALESMAN_ID | NAME |
+-------------+--------+
| 1000 | RAHUL |
| 2000 | ANKITA |
+-------------+--------+
2 rows in set (0.002 sec)

MariaDB [ORDERS]> SELECT S.SALESMAN_ID, S.NAME, C.CUST_NAME, S.COMMISSION


-> FROM SALESMAN S, CUSTOMER C
-> WHERE S.CITY=C.CITY
-> UNION
-> SELECT S.SALESMAN_ID,S.NAME,'NO MATCH',S.COMMISSION
-> FROM SALESMAN S
-> WHERE CITY NOT IN
-> (SELECT CITY
-> FROM CUSTOMER)
-> ORDER BY 1 ASC;
+-------------+--------+-----------+------------+
| SALESMAN_ID | NAME | CUST_NAME | COMMISSION |
+-------------+--------+-----------+------------+
| 1000 | RAHUL | ADYA | 20% |
| 1000 | RAHUL | DANISH | 20% |
| 1000 | RAHUL | ESHA | 20% |
| 2000 | ANKITA | ADYA | 25% |
| 2000 | ANKITA | DANISH | 25% |
| 2000 | ANKITA | ESHA | 25% |
| 3000 | SHARMA | NO MATCH | 30% |
| 4000 | ANJALI | NO MATCH | 15% |
| 5000 | RAJ | NO MATCH | 15% |
+-------------+--------+-----------+------------+
9 rows in set (0.001 sec)

MariaDB [ORDERS]> CREATE VIEW V_SALESMAN AS


-> SELECT O.ORDER_DATE, S.SALESMAN_ID, S.NAME
-> FROM SALESMAN S,ORDERS O
-> WHERE S.SALESMAN_ID = O.SALESMAN_ID
-> AND O.PURCHASE_AMOUNT= (SELECT MAX(PURCHASE_AMOUNT)
-> FROM ORDERS C
-> WHERE C.ORDER_DATE=O.ORDER_DATE);
Query OK, 0 rows affected (0.006 sec)

MariaDB [ORDERS]>
MariaDB [ORDERS]> SELECT * FROM V_SALESMAN;
+------------+-------------+--------+
| ORDER_DATE | SALESMAN_ID | NAME |
+------------+-------------+--------+
| 2020-06-02 | 1000 | RAHUL |
| 2020-04-09 | 2000 | ANKITA |
| 2020-03-15 | 2000 | ANKITA |
| 2020-07-09 | 3000 | SHARMA |
| 2020-05-05 | 2000 | ANKITA |
+------------+-------------+--------+
5 rows in set (0.010 sec)

MariaDB [ORDERS]> DELETE FROM SALESMAN


-> WHERE SALESMAN_ID=1000;
Query OK, 1 row affected (0.003 sec)

MariaDB [ORDERS]>
MariaDB [ORDERS]> SELECT * FROM SALESMAN;
+-------------+--------+-----------+------------+
| SALESMAN_ID | NAME | CITY | COMMISSION |
+-------------+--------+-----------+------------+
| 2000 | ANKITA | BANGALORE | 25% |
| 3000 | SHARMA | MYSORE | 30% |
| 4000 | ANJALI | DELHI | 15% |
| 5000 | RAJ | HYDERABAD | 15% |
+-------------+--------+-----------+------------+
4 rows in set (0.003 sec)

MariaDB [ORDERS]>
MariaDB [ORDERS]> SELECT * FROM ORDERS;
+----------+-----------------+------------+-------------+-------------+
| ORDER_NO | PURCHASE_AMOUNT | ORDER_DATE | CUSTOMER_ID | SALESMAN_ID |
+----------+-----------------+------------+-------------+-------------+
| 202 | 450.00 | 2020-04-09 | 1 | 2000 |
| 203 | 1000.00 | 2020-03-15 | 3 | 2000 |
| 204 | 3500.00 | 2020-07-09 | 4 | 3000 |
| 205 | 550.00 | 2020-05-05 | 2 | 2000 |
+----------+-----------------+------------+-------------+-------------+
4 rows in set (0.000 sec)

MOVIE DATABASE

MariaDB [movie]> SELECT MOV_TITLE


-> FROM MOVIES
-> WHERE DIR_ID = (SELECT DIR_ID
-> FROM DIRECTOR
-> WHERE DIR_NAME='HITCHCOCK');
+-----------+
| MOV_TITLE |
+-----------+
| AAKASHAM |
+-----------+
1 row in set (0.000 sec)

MariaDB [movie]> SELECT MOV_TITLE


-> FROM MOVIES M,MOVIE_CAST MC
-> WHERE M.MOV_ID=MC.MOV_ID AND ACT_ID IN (SELECT ACT_ID
-> FROM MOVIE_CAST GROUP BY ACT_ID
-> HAVING COUNT(ACT_ID)>1)
-> GROUP BY MOV_TITLE
-> HAVING COUNT(*)>1;
+-----------+
| MOV_TITLE |
+-----------+
| AAKASHAM |
+-----------+
1 row in set (0.005 sec)

MariaDB [movie]> SELECT ACT_NAME


-> FROM ACTOR A
-> JOIN MOVIE_CAST C
-> ON A.ACT_ID=C.ACT_ID
-> JOIN MOVIES M
-> ON C.MOV_ID=M.MOV_ID
-> WHERE M.MOV_YEAR NOT BETWEEN 2000 AND 2015;
+----------+
| ACT_NAME |
+----------+
| RAHUL |
+----------+
1 row in set (0.000 sec)

MariaDB [movie]> SELECT MOV_TITLE,MAX(REV_STARS)


-> FROM MOVIES
-> INNER JOIN RATING USING (MOV_ID)
-> GROUP BY MOV_TITLE
-> HAVING MAX(REV_STARS)>0
-> ORDER BY MOV_TITLE;
+-----------+----------------+
| MOV_TITLE | MAX(REV_STARS) |
+-----------+----------------+
| AAKASHAM | 2 |
| HOME | 3 |
| KALIYONA | 5 |
| MANASU | 4 |
| WAR HORSE | 4 |
+-----------+----------------+
5 rows in set (0.003 sec)

MariaDB [movie]> UPDATE RATING


-> SET REV_STARS=5
-> WHERE MOV_ID IN (SELECT MOV_ID FROM MOVIES
-> WHERE DIR_ID IN (SELECT DIR_ID
-> FROM DIRECTOR
-> WHERE DIR_NAME='STEVEN SPIELBERG'));
Query OK, 1 row affected (0.005 sec)
Rows matched: 1 Changed: 1 Warnings: 0

MariaDB [movie]> SELECT *FROM RATING;


+--------+-----------+
| MOV_ID | REV_STARS |
+--------+-----------+
| 1001 | 4 |
| 1002 | 2 |
| 1003 | 5 |
| 1004 | 5 |
| 1005 | 3 |
+--------+-----------+
5 rows in set (0.000 sec)

College Database

MariaDB [college]> SELECT S.*, SS.SEM, SS.SEC


-> FROM STUDENT S, SEMSEC SS, CLASS C
-> WHERE S.USN = C.USN AND
-> SS.SSID = C.SSID AND
-> SS.SEM = 4 AND SS.SEC='C';
+------------+--------+-----------+--------+--------+------+------+
| USN | SNAME | ADDRESS | PHONE | GENDER | SEM | SEC |
+------------+--------+-----------+--------+--------+------+------+
| 1BI15CS091 | MALINI | MANGALURU | 235464 | F | 4 | C |
+------------+--------+-----------+--------+--------+------+------+
1 row in set (0.002 sec)

MariaDB [college]> SELECT SS.SEM, SS.SEC, S.GENDER, COUNT(S.GENDER) AS COUNT


-> FROM STUDENT S, SEMSEC SS, CLASS C
-> WHERE S.USN = C.USN AND
-> SS.SSID = C.SSID
-> GROUP BY SS.SEM, SS.SEC, S.GENDER
-> ORDER BY SEM;
+------+------+--------+-------+
| SEM | SEC | GENDER | COUNT |
+------+------+--------+-------+
| 3 | A | M | 1 |
| 3 | B | M | 1 |
| 3 | C | F | 1 |
| 4 | A | F | 1 |
| 4 | A | M | 1 |
| 4 | B | F | 1 |
| 4 | C | F | 1 |
| 7 | A | F | 1 |
| 7 | A | M | 2 |
| 8 | A | F | 1 |
| 8 | A | M | 1 |
| 8 | B | F | 1 |
| 8 | C | M | 1 |
+------+------+--------+-------+
13 rows in set (0.001 sec)

MariaDB [college]> CREATE VIEW STUDENT_TEST1_MARKS_V


-> AS
-> SELECT TEST1, SUBCODE
-> FROM IAMARKS
-> WHERE USN = '1BI15CS101';
Query OK, 0 rows affected (0.006 sec)

MariaDB [college]>
MariaDB [college]> SELECT * FROM STUDENT_TEST1_MARKS_V;
+-------+---------+
| TEST1 | SUBCODE |
+-------+---------+
| 15 | 10CS81 |
| 12 | 10CS82 |
| 19 | 10CS83 |
| 20 | 10CS84 |
| 15 | 10CS85 |
+-------+---------+
5 rows in set (0.001 sec)

MariaDB [college]> CREATE PROCEDURE AVG_MARKS()


-> BEGIN
-> DECLARE C_A INTEGER;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MariaDB server version for the right syntax to use near '' at
line 3
MariaDB [college]> DECLARE C_B INTEGER;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MariaDB server version for the right syntax to use near
'DECLARE C_B INTEGER' at line 1
MariaDB [college]> DECLARE C_C INTEGER;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MariaDB server version for the right syntax to use near
'DECLARE C_C INTEGER' at line 1
MariaDB [college]> DECLARE C_SUM INTEGER;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MariaDB server version for the right syntax to use near
'DECLARE C_SUM INTEGER' at line 1
MariaDB [college]> DECLARE C_AVG INTEGER;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MariaDB server version for the right syntax to use near
'DECLARE C_AVG INTEGER' at line 1
MariaDB [college]> DECLARE C_USN VARCHAR(10);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MariaDB server version for the right syntax to use near
'DECLARE C_USN VARCHAR(10)' at line 1
MariaDB [college]> DECLARE C_SUBCODE VARCHAR(8);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MariaDB server version for the right syntax to use near
'DECLARE C_SUBCODE VARCHAR(8)' at line 1
MariaDB [college]> DECLARE C_SSID VARCHAR(5);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MariaDB server version for the right syntax to use near
'DECLARE C_SSID VARCHAR(5)' at line 1
MariaDB [college]>
MariaDB [college]> DECLARE C_IAMARKS CURSOR FOR
-> SELECT GREATEST(TEST1,TEST2) AS A, GREATEST(TEST1,TEST3) AS B,
GREATEST(TEST3,TEST2) AS C, USN, SUBCODE, SSID
-> FROM IAMARKS
-> WHERE FINALIA IS NULL
-> FOR UPDATE;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MariaDB server version for the right syntax to use near
'DECLARE C_IAMARKS CURSOR FOR
SELECT GREATEST(TEST1,TEST2) AS A, GREATEST(TEST...' at line 1
MariaDB [college]>
MariaDB [college]> OPEN C_IAMARKS;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MariaDB server version for the right syntax to use near 'OPEN
C_IAMARKS' at line 1
MariaDB [college]> LOOP
->
-> FETCH C_IAMARKS INTO C_A, C_B, C_C, C_USN, C_SUBCODE, C_SSID;
ERROR 1324 (42000): Undefined CURSOR: C_IAMARKS
MariaDB [college]>
MariaDB [college]> IF (C_A != C_B) THEN
-> SET C_SUM=C_A+C_B;
ERROR 1327 (42000): Undeclared variable: C_A
MariaDB [college]> ELSE
-> SET C_SUM=C_A+C_C;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MariaDB server version for the right syntax to use near 'ELSE
SET C_SUM=C_A+C_C' at line 1
MariaDB [college]> END IF;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MariaDB server version for the right syntax to use near 'END
IF' at line 1
MariaDB [college]>
MariaDB [college]> SET C_AVG=C_SUM/2;
ERROR 1193 (HY000): Unknown system variable 'C_AVG'
MariaDB [college]>
MariaDB [college]> UPDATE IAMARKS SET FINALIA = C_AVG
-> WHERE USN = C_USN AND SUBCODE = C_SUBCODE AND SSID = C_SSID;
ERROR 1054 (42S22): Unknown column 'C_USN' in 'where clause'
MariaDB [college]>
MariaDB [college]> END LOOP;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MariaDB server version for the right syntax to use near 'END
LOOP' at line 1
MariaDB [college]> CLOSE C_IAMARKS;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MariaDB server version for the right syntax to use near 'CLOSE
C_IAMARKS' at line 1
MariaDB [college]> END;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MariaDB server version for the right syntax to use near 'END'
at line 1
MariaDB [college]> //
->
->
-> CALL AVG_MARKS();
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MariaDB server version for the right syntax to use near '//

CALL AVG_MARKS()' at line 1


MariaDB [college]>
MariaDB [college]> SELECT * FROM IAMARKS;
+------------+---------+-------+-------+-------+-------+---------+
| USN | SUBCODE | SSID | TEST1 | TEST2 | TEST3 | FINALIA |
+------------+---------+-------+-------+-------+-------+---------+
| 1BI15CS101 | 10CS81 | CSE8C | 15 | 16 | 18 | NULL |
| 1BI15CS101 | 10CS82 | CSE8C | 12 | 19 | 14 | NULL |
| 1BI15CS101 | 10CS83 | CSE8C | 19 | 15 | 20 | NULL |
| 1BI15CS101 | 10CS84 | CSE8C | 20 | 16 | 19 | NULL |
| 1BI15CS101 | 10CS85 | CSE8C | 15 | 15 | 12 | NULL |
+------------+---------+-------+-------+-------+-------+---------+
5 rows in set (0.000 sec)

MariaDB [college]> SELECT S.USN,S.SNAME,S.ADDRESS,S.PHONE,S.GENDER, IA.SUBCODE,


-> (CASE
-> WHEN IA.FINALIA BETWEEN 17 AND 20 THEN 'OUTSTANDING'
-> WHEN IA.FINALIA BETWEEN 12 AND 16 THEN 'AVERAGE'
-> ELSE 'WEAK'
-> END) AS CAT
-> FROM STUDENT S, SEMSEC SS, IAMARKS IA, SUBJECT SUB
-> WHERE S.USN = IA.USN AND
-> SS.SSID = IA.SSID AND
-> SUB.SUBCODE = IA.SUBCODE AND
-> SUB.SEM = 8;
+------------+---------+-----------+--------+--------+---------+------+
| USN | SNAME | ADDRESS | PHONE | GENDER | SUBCODE | CAT |
+------------+---------+-----------+--------+--------+---------+------+
| 1BI15CS101 | CHETHAN | BENGALURU | 534234 | M | 10CS81 | WEAK |
| 1BI15CS101 | CHETHAN | BENGALURU | 534234 | M | 10CS82 | WEAK |
| 1BI15CS101 | CHETHAN | BENGALURU | 534234 | M | 10CS83 | WEAK |
| 1BI15CS101 | CHETHAN | BENGALURU | 534234 | M | 10CS84 | WEAK |
| 1BI15CS101 | CHETHAN | BENGALURU | 534234 | M | 10CS85 | WEAK |
+------------+---------+-----------+--------+--------+---------+------+
5 rows in set (0.001 sec)

Company Database

MariaDB [company]> SELECT DISTINCT P.PNO


-> FROM PROJECT P, DEPARTMENT D, EMPLOYEE E
-> WHERE E.DNO=D.DNO
-> AND D.MGR_SSN=E.SSN
-> AND E.NAME LIKE '%SCOTT'
-> UNION
-> SELECT DISTINCT P1.PNO
-> FROM PROJECT P1, WORKS_ON W, EMPLOYEE E1
-> WHERE P1.PNO=W.PNO
-> AND E1.SSN=W.SSN
-> AND E1.NAME LIKE '%SCOTT';
+------+
| PNO |
+------+
| 1004 |
| 1005 |
| 1007 |
| 1003 |
| 1006 |
| 1000 |
| 1001 |
| 1002 |
+------+
8 rows in set (0.003 sec)

MariaDB [company]> SELECT E.NAME, 1.1*E.SALARY AS INCR_SAL


-> FROM EMPLOYEE E, WORKS_ON W, PROJECT P
-> WHERE E.SSN=W.SSN
-> AND W.PNO=P.PNO
-> AND P.PNAME='IOT';
+-------------+----------+
| NAME | INCR_SAL |
+-------------+----------+
| HARRY SMITH | 550000.0 |
| LEAN BAKER | 770000.0 |
| RAVAN HEGDE | 715000.0 |
+-------------+----------+
3 rows in set (0.005 sec)

MariaDB [company]> SELECT SUM(E.SALARY), MAX(E.SALARY), MIN(E.SALARY),


AVG(E.SALARY)
-> FROM EMPLOYEE E, DEPARTMENT D
-> WHERE E.DNO=D.DNO
-> AND D.DNAME='ACCOUNTS';
+---------------+---------------+---------------+---------------+
| SUM(E.SALARY) | MAX(E.SALARY) | MIN(E.SALARY) | AVG(E.SALARY) |
+---------------+---------------+---------------+---------------+
| 650000 | 350000 | 300000 | 325000.0000 |
+---------------+---------------+---------------+---------------+
1 row in set (0.001 sec)
MariaDB [company]> SELECT E.NAME
-> FROM EMPLOYEE E
-> WHERE NOT EXISTS(SELECT PNO FROM PROJECT WHERE DNO='5' AND PNO NOT IN
(SELECT
-> PNO FROM WORKS_ON
-> WHERE E.SSN=SSN));
+-------------+
| NAME |
+-------------+
| HARRY SMITH |
+-------------+
1 row in set (0.001 sec)

MariaDB [company]> SELECT D.DNO, COUNT(*)


-> FROM DEPARTMENT D, EMPLOYEE E
-> WHERE D.DNO=E.DNO
-> AND E.SALARY > 600000
-> AND D.DNO IN (SELECT E1.DNO
-> FROM EMPLOYEE E1
-> GROUP BY E1.DNO
-> HAVING COUNT(*)>5)
-> GROUP BY D.DNO;
+-----+----------+
| DNO | COUNT(*) |
+-----+----------+
| 5 | 3 |
+-----+----------+
1 row in set (0.001 sec)

You might also like