Thursday, January 11, 2018

SQL

DROP TABLE IF EXISTS emp;
CREATE TABLE emp(eid integer,ename varchar(20),sal integer,ecountry varchar(200));
INSERT INTO emp VALUES (1,'XYZ',20000,'INDIA');
INSERT INTO emp VALUES (2,'XYZ1',2000,'ENGLAND');
INSERT INTO emp VALUES (3,'XYZ2',2000,'INDIA');
INSERT INTO emp VALUES (4,'XYZ3',20000,'ENGLAND');
INSERT INTO emp VALUES (5,'XYZ4',20000 ,'RUSSIA');
INSERT INTO emp VALUES (6,'XYZ5',20000 ,'SRI LANKA');

SELECT * FROM emp;
SELECT * FROM emp WHERE eid=1;
SELECT * FROM emp WHERE ename='XYZ5';
SELECT eid,ename FROM emp;
SELECT * FROM emp WHERE sal<10000;
SELECT DISTINCT ecountry FROM emp;
SELECT DISTINCT ename FROM emp;
SELECT COUNT(DISTINCT ecountry) FROM emp;
SELECT COUNT(DISTINCT ename) FROM emp;
SELECT * FROM emp WHERE ecountry='INDIA';
DROP TABLE IF EXISTS emp;
CREATE TABLE emp(eid integer,ename varchar(20),sal integer,ecountry varchar(200));
INSERT INTO emp VALUES (1,'XYZ',20000,'INDIA');
INSERT INTO emp VALUES (2,'XYZ1',2000,'ENGLAND');
INSERT INTO emp VALUES (3,'XYZ2',2000,'INDIA');
INSERT INTO emp VALUES (4,'XYZ3',20000,'ENGLAND');
INSERT INTO emp VALUES (5,'XYZ4',20000 ,'RUSSIA');
INSERT INTO emp VALUES (6,'XYZ5',20000 ,'SRI LANKA');

SELECT * FROM emp;
SELECT * FROM emp WHERE eid=1;
SELECT * FROM emp WHERE ename='XYZ5';
SELECT eid,ename FROM emp;
SELECT * FROM emp WHERE sal<10000;
SELECT DISTINCT ecountry FROM emp;
SELECT DISTINCT ename FROM emp;
SELECT COUNT(DISTINCT ecountry) FROM emp;
SELECT COUNT(DISTINCT ename) FROM emp;
SELECT * FROM emp WHERE ecountry='INDIA';



OUTPUT:
eidenamesalecountry
1XYZ20000INDIA
2XYZ12000ENGLAND
3XYZ22000INDIA
4XYZ320000ENGLAND
5XYZ420000RUSSIA
6XYZ520000SRI LANKA
eidenamesalecountry
1XYZ20000INDIA
eidenamesalecountry
6XYZ520000SRI LANKA
eidename
1XYZ
2XYZ1
3XYZ2
4XYZ3
5XYZ4
6XYZ5
eidenamesalecountry
2XYZ12000ENGLAND
3XYZ22000INDIA
ecountry
INDIA
ENGLAND
RUSSIA
SRI LANKA
ename
XYZ
XYZ1
XYZ2
XYZ3
XYZ4
XYZ5
COUNT(DISTINCT ecountry)
4
COUNT(DISTINCT ename)
6
eidenamesalecountry
1XYZ20000INDIA
3XYZ22000INDIA

No comments:

Post a Comment