Adobe Scan 02-Dec-2024
Adobe Scan 02-Dec-2024
Adobe Scan 02-Dec-2024
sql> SELECT Count(e11pid) as 'No . Of Records' fl'OII EMPLOYEE where city is not NULL;
---···········--+
I !<o. Of Records I
···············-+
10 I
..................
1 row in set (0.00 sec)
sql> SELECT Count(DISTINCT city) as '!<o. Of cities' fro. EMPLOYEE where city is not NULL;
.................
I !<o. Of cities I
. ................
I sI
""'
ALLAHABAD ''
'
II '.P Type hereto search i:::li e 26-C Haze A ~Kl ~ '3~) ,.i: 4 ~ 1 13:17
',P Typeheretosearch
P Type here to search
IITI S.,o,cl:Command Prompt- rny,;ql -u rool -p
ERROR 1052. (2.3000): Colu1>n 'deptid' in field list is a1>biguous
sql> SELECT dep_ na1>e , count(empid) from EMPLOYEE,DEPART1'1ENT where EMPLOYEE.deptid-DEPARTM.ENT . deptid GROJP BY dep_name;
------ ------ ----+ -------------+
dep_ name count(eo,pid) I
Purchase 4
Sales 2.
Marketing 3
Finance 1
Human Resource 2.
. . . . . . . . . . . . . . .... --+
5 rows in set (0.00 5e,c)
ysql> SELECT dep_name , count(empid) from EMPLOYEE,DEPARTMHIT where EMPLOYEE.deptid • DEPARTMENT.deptid GROJP BY dep_name ORO!:R BY count(empid);
............... ·+·-------------+
I dep_name I count(empid) I
............... ·+·. ·------· ... ·+
I Finance I 1 I
!Sales I 2 1
I Human Resource I 2 I
I Marketing I 3I
I Purchase I 4I
+· •••••••••••••• ·+· ...•.••..... ·+
S rows in set {0.00 sec)
sql> SELECT dep_na .. e , AVG(Salary) from EMPLOYEE,OEPARTMENT where EMPLOYEE.deptid•OEPARTMENT.deptid & salary>20000 GROJP BY dep_name HAVING AVG(SALARY)>39000;
Empty set, 156 warnings (0.00 sec)
ysql> SELECT dep_na'"e , AVG(Salary) from EMPLOYEE,OEPARTMENT where EMPLOYEE.deptid•OEPARTMENT.deptlD GROUP BY dep_na,..-, HAVING AVG(SALARY)>39000 & salary>2000B;
ERROR 1054 (42522): Unknown column 'salary' in 'having clause'
ysql> SELECT dep_na,ae , AVG(Salary) from EMPLOYfE , OEPARTMENT where salary>2000 & E/o\l'LOYfLdeptid • DEPARTMENT .deptlD GROUP BY dep_name HAVING AVG(5ALAIIY)>39000 ;
Empty set, 19 warnings (0.06 sec)
sql>
ype ' help;' or "\h' for help . Type '\c' to clear the current input statement .
. -"
Ravi Trivedi Kanpur 2819-05 Java
"' Gupta "" NULL 2819-07-18 " Python I
"'
"' Kunal Sharma
Devesh Singh "" Lucknow
NULL
2019-07-18
2019-10-15
Java
Java
,"'
"' Su11it Singh
Diya llerma " NULL
Agra
Kanpur
2020-02-20
2020-03-05
Python
HTML
Nutan Ku,oar Lucknow 2020-0S-10 Python
"' Arti Soni "" Agra 2018-09-02
"'
"' Mohit Suri
Hari Dubet
NULL Kannoj
Kushi
2019-10-04
2020-02-20
"'
"'
Python
+· ••••••'"·+· ............ ·+· ...." ·+· .......
10 rows in set {8.13 sec)
·+· ••••• ----. ·+· ...... ·+
"' Android
•' "'"
Kapil
.
18000 Some sh Tiwai
"' "' HTML
'' '"' Riddhi11a
,"'
"' "' Java
"'' 15000
Sumit Sansal
Raveesh Thakur
"' Python
•' 9000 Rohit Kumar
ysql> SELECT count (Re giNo) as ' Total numb e r o-f students· from STUDHIT;
- - - - - - - - - - ------------- - - - +
Total numbe r of students
- - - - - - - - - ---------------- - +
- - - - - - --------------------+
1 row i n set {0.00 sec)
"
P Type hereto search i:::li • 26-C Haze A ~Kl ~ '31)) a: 4, IN6
IITI Command Pmmpt- mysql -u root -p
sql> SELECT CNAM.E,count(RegiNo) as 'NO. of Student · ,FEES,count(RegiNo)*FEES as 'Fees Collected' from STIJDENT,COORSE where COORSE.CNAME-STIJDENT.Course group by CNAME;
------ - -+- ---------------+------+ -------+
Cw.ME I NO. of Student I FEES I Fees Collected
Java
Python
,,,
"™'
--------+ ---------------+ ---- -+ ---------------+
rows in set (0.32 sec )
sql> SELECT CNAME,count(Regi!<o) as 'NO. of Student" from STIJDENT,COURSE where COORSE.CNAME • STIJDENT.Course group by (NAME;
········+········--------+
I Cw.ME I NO. of Student I
········+············----+
Java l
Python 4
HTML 1
SQL 2
+········+··············-·+
rows in set (0.88 sec)
ysql> SELECT Sname fr0<11 STUOENT,COURSE where COORSE.Ctul.'\E•STUOENT.Course &8 COORSE.Instructor•'Anadi Singh' group by CtJAME;
ERROR 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'anu.STLOENT.Sna01e' which is not functionally dependent on
columns in GROUP BY clause; this is inconrpatible with sql_OIOde•only_full_group_by
ysql> SELECT Sname froa, STUOENT,COURSE where COURSE.CNA'IE•5TUOENT.Course && COURSE.Instructor•'Anadi Singh' j
············+
I Sname
············+
I Arti Soni I
I Mohit Suri I
------------+
2 rows in set, 1 warning (0 03 sec)
sql> SELECT count(RegiNo) as 'No. of students with age above 25' from STIJDEITT where Age>25;
- - - - - - - - - - - - -----------------------+
No. of students with age above 25
----- - - - - - - ------------------------+
'
i:::li • 26-C Haze
IITI Command Prompt- mysql -u root -p
sql> SELECT Sname f...,. ST\JDENT,COURSE where COURSE.(Nl!ME-STI.OENT.Course && COURSE.Instructor-"Anadi Singh";
Sname
-------- - ---+
Arti Soni I
Mohit Suri J
------------+
2 rows in set, 1 warning (9.03 sec)
sql> SELECT count(RegiNo) as "Uo. of students with age abo,,e 2S" from STI.OENT where Age>2'i;
-· ........... ··--------------------+
I Uo. of students with age abo,,e 25 I
-· .. ....... ... ·--------------------+
, I
............ .... ·------------------+
1 row in set (9 . 06 sec)
sql> SELECT count(Reg1No) as 'Uo. of student not entering city' from STI..OENT where city.isNUL();
ERROR 1305 (42000 ): FUNCTION city.isNUL does not exist
ysql> SELECT count(RegiNo) as ' No. of student not entering city' f rom STI.OENT where city is NUL L;
................ ------------------+
I Ito. of student not entering city I
.... ......... ---------------------+
' I
sql> SELECT CID,CNN!f ff'OII STUOENT ,COORSE where STI.OENT .Course•' Kanpur';
Empty set (0 . 00 sec)
sqb SELECT dty,count(Regu.lo) as ' No. of sudents ' f ro. STUDENT GROUP BY city ;
---------+- ---------------+
I city I No . of sudents I
- - - - - - - - -+- - - - - - - ---------+
Kanpu r 2
NULL 2
Lucknow 2
Agra 2
Kannoj 1
Kushi 1
---- -----+- ---------------+
6 rows in set (0.00 sec)
sql> •
sql> SELECT ename , sala r y,dep_ name from EMPLOYEE,DEPARTMENT where EMPLOYEE.deptidzDEPARTMENT.deptid and salary>30000;
I ename
················•··· -----• ---··· ··········•
KAILASH KHER 32500 Purchase
SIJMITA ARORA 52080 Purchase
HARRY 39000 Sales
AMIT GUPTA 36000 Sa l es
GOVINO JAISWAL 43008 Marke ti ng
RAVI TIWARI 32080 Market i ng
SIJMIT srnGH 4 3008 Market i ng
BRIJESH SHUKLA 105000 Human Resource
SlJl,ltTA ARORA 52888 kuman Resource
+· •••••••••••••• · +· •••••• · +· .............. · +
9 rows in set (0.00 sec)
sql> SELECT dep_name, AVG(salary) from EMPLOYEE,OEPARTI-IENT where EMP LOYEE.deptid•DEPARTI-IEIH.deptid GROUP BY dep_na""';
················• ·············+
I dep_ name I AVG(salary) I
............. .. ·• · .. ··········+
Purchase 31625.0000
Sales 37500.0000
Marketing 39333.3333
Finance 21000.0000
Human Resource 78500 . 0000
---------------- + ------------+
S rows in set {0.00 sec)