SQL Tutorial 7 Group by Clause

preview_player
Показать описание


Follow on Facebook:

Subscribe to our other channel:
Telusko Hindi :
Рекомендации по теме
Комментарии
Автор

Create and Insert Scripts, Good Luck :-

create table emp
(eno int,
ename varchar(40),
desg varchar(30),
sal int,
mgr int,
deptno int
);

create table dept
(
dname varchar(40),
loc varchar(30),
deptno int
);

insert into dept values ('sales', 'mumbai', 10);
insert into dept values ('hr', 'delhi', 20);
insert into dept values ('accounts', 'chennai', 30);
insert into dept values ('production', 'bangalore', 40);

insert into emp values (1, 'aaa', 'salesman', 7000, 2, 10);
insert into emp values (2, 'bbb', 'mgr', 17000, 3, 10);
insert into emp values (3, 'ccc', 'president', 40000, null, 30);
insert into emp values (4, 'ddd', 'clerk', 5000, 5, 20);
insert into emp values (5, 'eee', 'mgr', 20000, 3, 20);

visheshpahuja
Автор

I am using MySQL and queries are according to it...
1) create table emp and insert data into it-
CREATE TABLE emp
(
eno INT,
ename VARCHAR(10),
designation VARCHAR(20),
sal INT,
mgr INT,
deptno INT
);

INSERT INTO emp VALUES(1, 'aaa', 'salesman', 7000, 2, 10);

INSERT INTO emp VALUES(2, 'bbb', 'manager', 17000, 3, 10);

INSERT INTO emp VALUES(3, 'ccc', 'president', 40000, null, 30);

INSERT INTO emp VALUES(4, 'ddd', 'clerk', 5000, 5, 20);

INSERT INTO emp VALUES(5, 'eee', 'manager', 20000, 3, 20);

2) create table dept and insert data into it-
CREATE TABLE dept
(
deptno INT,
dname VARCHAR(20),
loc VARCHAR(20)
);

INSERT INTO dept VALUES (10, 'sales', 'mumbai');

INSERT INTO dept VALUES (20, 'hr', 'delhi');

INSERT INTO dept VALUES (30, 'accounts', 'chennai');

INSERT INTO dept VALUES (40, 'production', 'bengaluru');

nileshpadmagiriwar
Автор

Where are the SQL scripts in description ???

rajul
Автор

emp table
create table emp
(
eno number,
ename varchar2(5),
designation varchar2(10),
sal number,
mgr number,
deptno number
);

bobin
Автор

Very nice explaination sir thank you so much sir

mohammedsuhailbasha
Автор

there is no description regarding sql scripts u r telling sir for emp and dept table

ankittiwary
Автор

how to get correct answer for last query?

AnitaPatole
Автор

Good but lack of providing exact information

calliart
Автор

I don't know if it's the simplest answer for the last query but it works:


select A.designation, count(B.eno)
from emp A
LEFT JOIN emp B
on A.eno=B.eno and B.sal>10000
group by A.designation

ProfesorBruno
Автор

where are the files, men ? didnt find any files

AmitKumar-pwln
Автор

CREATE TABLE emp
(
eno INT NOT NULL,
ename VARCHAR(20),
designation VARCHAR(20),
sal INT,
mgr VARCHAR(20),
deptno INT,
PRIMARY KEY(eno)
);

CREATE TABLE dept
(
deptno INT,
dname VARCHAR(20),
loc VARCHAR(20),
PRIMARY KEY(deptno)
);

ALTER TABLE emp
ADD CONSTRAINT fk_deptno FOREIGN KEY(deptno) REFERENCES dept(deptno);

INSERT INTO dept
VALUES (10,
'sales',
'mumbai');

INSERT INTO dept
VALUES (20,
'hr',
'delhi');

INSERT INTO dept
VALUES (30,
'accounts',
'chennai');

INSERT INTO dept
VALUES (40,
'production',
'bengaluru');

INSERT INTO emp
VALUES (1,
'aaa',
'salesman',
7000,
'2',
10);

INSERT INTO emp
VALUES (2,
'bbb',
'manager',
17000,
'3',
10);

INSERT INTO emp
VALUES (3,
'ccc',
'president',
40000,
'',
30);

INSERT INTO emp
VALUES (4,
'ddd',
'clerk',
5000,
'5',
20);

INSERT INTO emp
VALUES (5,
'eee',
'manager',
20000,
'3',
20);

balakumars