All SQL Queries - Python For Xi CS PDF
All SQL Queries - Python For Xi CS PDF
All SQL Queries - Python For Xi CS PDF
TABLE STRUCTURE
RECORDS
/
DEPARTMENT TABLE
TABLE STRUCTURE
RECORDS
S. QUESTION ANSWER
O.
DISPLAY ALL THE RECORDS (ALL COLUMNS ) 1 SELECT *
FROM TABLE EMP. 2 FROM EMP ;
DISPLAY EMPNO AND ENAME OF ALL 1 SELECT EMPNO, ENAME
EMPLOYEES FROM TABLE EMP. 2 FROM EMP ;
DISPLAY ENAME,SAL AND SAL ADDED WITH 1 SELECT ENAME, SAL, SAL+COMM "TOTAL SALARY"
COMM FROM TABLE EMP 2 FROM EMP ;
DISPLAY ENAME JOINED WITH JOB WITH 1 SELECT ENAME ||JOB "EMPLOYEE", SAL*12 "TOTAL
HEADING “EMPLOYEE”, SAL *12 AS “TOTAL SALARY"
SALARY FROM TABLE EMP 2 FROM EMP
DISPLAY DISTINCT SAL OF EMPLOYEES FROM SELECT DISTINCT SAL FROM EMP ;
TABLE EMP
/
S. QUESTION ANSWER
O.
SHOW THE STRUCTURE OF TABLE DEPT DESCRIBE DEPT ;
OR
DESC DEPT ;
WRITE A QUERY TO DISPLAY ENAME AND SAL 1 SELECT ENAME, SAL
OF EMPLOYEES WHOSE SALARY IS GREATER 2 FROM EMP
THAN OR EQUAL TO 3000 FORM TABLE EMP 3 WHERE SAL >=3000 ;
WRITE A QUERY TO DISPLAY EMPLOYEE NAME, 1 SELECT *
SALARY AND DEPARTMENT NUMBER WHO ARE 2 FROM EMP
NOT GETTING COMMISSION FROM TABLE EMP 3 WHERE COMM IS NULL ;
WRITE A QUERY TO DISPLAY EMPLOYEE 1 SELECT EMPNO, ENAME, SAL, SAL*12 "ANNUAL
NUMBER, NAME, SAL AND SAL*12 AS “ANNUAL SALARY"
SALARY “ WHOE COMMISSION IS NOT NULL 2 FROM EMP
FROM TABLE EMP 3 WHERE COMM IS NOT NULL ;
WRITE A QUERY TO DISPLAY EMPLOYEE NAME 1 SELECT ENAME, SAL
AND SALARY OF THOSE EMPLOYEE WHO DON’T 2 FROM EMP WHERE SAL NOT BETWEEN 1500 AND
HAVE THERE SALARY IN RANGE OF 1500 TO 2500
2000
WAQ TO DISPLAY NAME, JOB, SALARY AND 1 SELECT ENAME, JOB, SAL, HIREDATE
HIREDATE OF EMPLOYEES WHO ARE HIRED 2 FROM EMP
BETWEEN FEB 20, 1981 AND MAY 1, 1981, 3 WHERE HIREDATE BETWEEN '20-FEB-1981' AND
ORDER OFDER THE QUERY IN ASCENDING '01-MAY-1981'
ORDER OF HIREDATE 4 ORDER BY HIREDATE ASC
WAQ TO DISPLAY NAME, JOB, SALARY OF 1 SELECT ENAME, HIREDATE
THOSE EMPLOYEE WHO ARE HIRED IN 1981 2 FROM EMP
3 WHERE TO_CHAR(HIREDATE, 'YYYY') = '1982' ;
WRITE A QUERY TO DISPLAY NAME, JOB TITLE 1 SELECT ENAME, JOB, SAL
AND SALARY WHO DO NOT HAVE MANAGER 2 FROM EMP
3 WHERE MGR IS NULL
WRITE A QUERY TO DISPLAY THE NAME OF 1 SELECT ENAME
EMPLOYEE WHOSE NAME CONTAINS ‘A’ AS 2 FROM EMP
THIRD ALPHABET . 3 WHERE ENAME LIKE '_ _A%' ;
WRITE A QUERY TO DISPLAY THE NAME OF 1 SELECT ENAME
EMPLOYEE WHOSE NAME CONTAINS ‘T’ AS THE 2 FROM EMP
LAST ALPHABE. 3 WHERE ENAME LIKE '%T' ;
WRITE A QUERY TO DISPLAY THE NAME OF 1 SELECT ENAME
EMP EMPLOYEE WHOSE NAME CONTANS ‘M’ 2 FROM EMP
AS FIRST ALPHABET ‘L’ AS THIRD ALPHABET 3 WHERE ENAME LIKE 'M%L' ; /
S. QUESTION ANSWER
O.
WRITE A QUERY TO DISPLAY THE NAME OF 1 SELECT ENAME
EMPLOYEE WHO IS HAVING ‘L’ AS ANY 2 FROM EMP
ALPHABET OF THE NAME 3 WHERE ENAME LIKE '%L%'
WRITE A QUERY TO DISPLAY THE CURRENT 1 SELECT SYSDATE
SYSTEM DATE 2 FROM DUAL ;
WRITE A QUERY TO DISPLAY EMPLOYEE 1 SELECT EMPNO, ENAME, SAL, SAL+SAL*.15 "NEW
NUMBER, NAME, SALARY , SALARY INCREASE SALARY"
BY 15% EXPRESSED AS A WHOLE NUMBER. 2 FROM EMP ;
LABEL THE COLUMN AS NEW SALARY
WRITE A QUERY TO DISPLAY THE EMPLOYE’S 1 SELECT ENAME, SAL HIREDATE,
NAME AND SALARY REVIEW DATE, WHICH IS ADD_MONTHS(HIREDATE,6) "REVIEW DATE"
THE DATE AFTER SIX MONTHS OF HIREDATE 2 FROM EMP ;
WRITE A QUERY TO DISPLAY THE EMPLOYEE’S 1 SELECT ENAME, SAL,
NAME AND SALARY, REVIEW DATE , WHICH IS TO_CHAR(ADD_MONTHS(HIREDATE,6), 'DAY, DD MON
THE DATE AFTER SIX MONTHS OF HIREDATE YYYY')
IN FORMAT OF ‘SUNDAY, 7, SEP, 1981’. 2 FROM EMP
FOR EACH EMPLOYEE DISPLAY EMPLOYEE 1 SELECT ENAME, HIREDATE,
NAME AND TOTAL NUMBER OF DAYS LAPSED ROUND( TO_DATE('12-JAN-2007')- HIREDATE ,0)
BETWEEN HIREDATE AND TODAY "NUMBER OF DAYS"
2 FROM EMP
FOR EACH EMPLOYEE DISPLAY EMPLOYEE 1 SELECT ENAME, HIREDATE,
NAME AND TOTAL NUMBER OF WEEKS LAPSED ROUND((TO_DATE('12-JAN-2007')- HIREDATE ) /
BETWEEN HIREDATE AND TODAY 7,0) "NUMBER OF WEAK"
2 FROM EMP
CREATE A QUERY THAT PRODUCES DISPLAY IN 1 SELECT ENAME || 'EARNS ' ||
THE FOLLOWING FORMAT '$', SAL || ' MONTHLY AND WORKING AS ' ,
<EMPLOYEE NAME> EARNS $ <SALARY>
MONTHLY AND WORKING AS <JOB> JOB
2 FROM EMP
/
S. QUESTION ANSWER
O.
WRITE A QUERY TO DISPLAY THE EMPLOYEE 1 SELECT ENAME, NVL( TO_CHAR(COMM),
NAME AND COMMISSION AMOUNT. IF THE 'NO COMMISSION')
EMPLOYEE DOE NOT EARN COMMISSION , PUT 2 FROM EMP;
“NO COMMISSION”
WRITE A QUERY TO DISPLAY THE ENAME AND 1 SELECT ENAME, DEPT.DEPTNO, DNAME
DEPTNO AND DNAME FOR ALL EMPLOYEES 2 FROM EMP, DEPT
USING TABLES EMP AND DEPT 3 WHERE EMP.DEPTNO = DEPT.DEPTNO ;
WRITE A QUERY TO DISPLAY EMPLOYEE NAME, 1 SELECT ENAME,DNAME, MGR
DEPARTMENT NAME AND LOCATION OF ALL 2 FROM EMP, DEPT
EMPLOYEES WHO HAVE MANAGER NAME 3 WHERE MGR BETWEEN 7500 AND 7900
BETWEEN 7500 AND 7900 4 AND EMP.DEPTNO = DEPT.DEPTNO ;
WRITE A QUERY TO DISPLAY THE EMPLOYEE 1 SELECT ENAME,DEPTNO
NAME, DEPARTMENT NUMBER AND ALL THE 2 FROM EMP
EMPLOYEES THAT WORKED IN THE SAME 3 WHERE DEPTNO = (SELECT DEPTNO FROM EMP
DEPARTMENT AS A GIVEN EMPLOYEE WHERE ENAME = &ENAME)
WRITE A QUERY TO DISPLAY EMPLOYEE NAME 1 SELECT ENAME, HIREDATE
AND HIREDATE OF EMPLOYEES WH ARE 2 FROM EMP
EMPLOYEED AFTER EMPLOYEE ‘BLAKE’ 3 WHERE HIREDATE > (SELECT HIREDATE FROM
EMP
WHERE ENAME ='BLAKE')
WRITE A QUERY TO DISPLAY EMPLOYEE 1 SELECT E1.EMPNO "EMPNO", E1.ENAME
NUMBER, NAME, MANAGER’S NAME WITH "EMPNAME",
THEIR MANAGER NUMBER E2.ENAME "MANAGER NAME", E2.EMPNO "MGR NO"
2 FROM EMP E1, EMP E2
3 WHERE E1.MGR = E2.EMPNO
WRITE A QUERY TO DISPLAY THE SUM, 1 SELECT DEPTNO, JOB, SUM(SAL), AVG(SAL),
AVERAGE, HIGHEST AND LOWEST SALARY OF MIN(SAL), MAX(SAL)
THE EMPLOYEES GROUPED BY DEPARTMENT 2 FROM EMP
NUMBER AND SUB-GROUPED BY JOB 3 GROUP BY DEPTNO, JOB
WRITE A QUERY TO DISPLAY THE SUM, 1 SELECT DEPTNO, SUM(SAL), AVG(SAL), MAX(SAL),
AVERAGE, HIGHEST AND LOWEST SALARY OF MIN(SAL)
THE EMPLOYEES GROUPED BY DEPARTMENT 2 FROM EMP
NUMBER 3 GROUP BY DEPTNO
/
S. QUESTION ANSWER
O.
WRITE A QUERY TO DISPLAY THE SUM, 1 SELECT DEPTNO, JOB , SUM(SAL), AVG(SAL),
AVERAGE, HIGHEST AND LOWEST SALARY OF MIN(SAL),
THE EMPLOYEES GROUPED BY DEPARTMENT MAX(SAL)
AND SUB GROUPED BY JOB 2 FROM EMP
3 GROUP BY DEPTNO, JOB
WRITE A QUERY TO DISPLAY THE NUMBER OF 1 SELECT JOB, COUNT(*)
EMPLOYEE WITH THE SAME JOB 2 FROM EMP
3 GROUP BY JOB ;
WRITE A QUERY TO DISPLAY THE NUMBER OF SELECT JOB, COUNT(JOB) FROM EMP GROUP BY JOB;
EMPLOYEE WITH THE SAME JOB
WRITE A QUERY TO DISPLAY THE AVERAGE OF SELECT AVG( MIN(SAL) + MAX(SAL) ) FROM EMP
HIGHEST AND LOWEST SALARY OF EACH GROUP BY DEPTNO
DEPARTMENT
BEFORE THE FOLLOWING EXERCISE PLEASE NAME OF COLUMN TYPE
ENSURE THAT YOU ARE PROVIDED WITH A ID NUMBER(4)
TABLE EMPLOYEE WITH FOLLOWING FIRST_NAME VARCHAR2(30)
DESCRIPTION LAST_NAME VARCHAR2(30)
USER_ID VARCHAR(10)
SALARY NUMBER (9)
POPULATE WITH 4TH RECORD AND ENTER INSERT INTO EMPLOYEE (ID, FIRSTNAME)
ONLY ID AND FIRST_NAME VALUES (4, 'SHANKAR') ;
FOR RECORD WITH ID=4 UPDATE RECORD UPDATE EMPLOYEE
WITH LAST_NAME, USERID AND SALARY SET LASTNAME='Giri', USERID = 'sgiri', SALARY =
7000 ;
WHRE ID = 4
MAKE THE CHANGES PERMANENT COMMIT ;
MODIFY THE LASTNAME, OF EMPLOYEE 3 TO UPDATE EMPLOYEE
GOUTAM SET LASTNAME=’Goutam’
WHERE ID = 3 ;
MODIFY THE SALARY AND INCREASE IT BY UPDATE EMPLOYEE
1000, FOR ALL WHO GET SALARY LESS THEN SET SALARY = SALRY + 1000
5000 WHERE SALARY < 5000
DELETE THE EMPLOYEE RECORD HAVING DELETE FROM EMPLOYEE
FIRSTNAME = ‘Siddharth’ WHERE FIRSTNAME = ‘Siddharth’
Make the changes permanent COMMIT ;
REMOVE entire contents of the table DELETE FROM EMPLOYEE ;
CREATE A TABLE EMPLOYEE1 WITH COLUMNS CREATE TABLE EMPLOYEE1 AS (SELECT ID,
ID, FIRSTNAME, AND DEPTID FROM TABLE FIRSTNAME FROM EMPLOYEE) ;
EMPLOYEE AND ALSO CONFIRM THE
EXISTENCE OF TABLE EMPLOYEE1 ALTER TABLE EMPLOYEE1 ADD(DEPTID NUMBER(2)) ;
DESCRIBE EMPLOYEE1 ;
CREATE A VIEW VUEMP1 WHICH SHOULD CREATE VIEW VUEMP1
INCLUDE COLUMN EMPNO, ENAME, AND AS (SELECT EMPNO, ENAME, DEPTNO FROM EMP) ;
DEPTNO FROM TABLE EMP
CREATE A VIEW VUEMP2 WHICH SHOULD CREATE VIEW VUEMP2(EMPNUMBER, EMPLOYEE,
INCLUDE COLUMN EMPNO, ENAME, AND DEPARTMENT)
DEPTNO FROM TABLE EMP AND CHANGE THE AS (SELECT EMPNO, ENAME, DEPTNO FROM EMP)
COLUMN HEADING AS EMPNUMBER,
EMPLOYEE, DEPARTMENT. /
S. QUESTION ANSWER
O.
SELECT VIEWNAME AND TEXT FROM THE DATA SELECT VIEW_NAME, TEXT FROM USER_VIEWS ;
DICTIONARY USER_VIEWS RESULT
VIEW_NAME
------------------------------
TEXT
-------------------------------------------------------------
-------------------
VUEMP1
(SELECT EMPNO, ENAME, DEPTNO FROM EMP)
VUEMP2
(SELECT EMPNO, ENAME, DEPTNO FROM EMP)
CREATE THE TABLE DEPARTMENT TABLE SELECT VIEW_NAME, TEXT FROM USER_VIEWS ;
BASED ON THE FOLLOWING INSTANCE CHART RESULT
VIEW_NAME TEXT
-----------------------------------------------------
VUEMP1 (select empno, ename, deptno from
emp)
VUEMP2 (select empno, ename, deptno from
emp)
CREATE THE TABLE DEPARTMENT TABLE CREATE TABLE DEPARTMENT (ID NUMBER(8), DNAME
BASED ON THE FOLLOWING TABLE INSTANCE VARCHAR2(25)) ;
CHART
DESCRIBE DEPARTMENT ;
COL.NAME ID NAME
DATA TYPE NUMBER VARCHAR2
LENGTH 8 25
AND CONFIRM THE TABLE STRUCTURE
POPULATE THE TABLE DEPARTMENT WITH INSERT INTO DEPARTMENT
DATA FROM TABLE DEPT. INCLUDING ONLY SELECT DEPTNO, DNAME FROM DEPT ;
REQUIRED COLUMNS
/
S. QUESTION ANSWER
O.
CREATE THE TABLE EMPLOYEE BASED ON THE CREATE TABLE EMPLOYEE
FOLLOWING TABLE INSTANCE CHART ( ID NUMBER(8),
COL.NAME DATA TYPE LENGTH FIRSTNAME VARCHAR2(25),
ID NUMBER 8 LASTNAME VARCHAR(25),
FIRSTNAME VARCHAR2 25 DEPTID NUMBER(8) ) ;
LASTNAME VARCHAR2 25
DEPTID NUMBER 8
1 View comments
(And realistically, it has NOTHING to do with genetics or some hard exercise and absolutely EVERYTHING about
"how" they are eating.)
Click this link to discover if this short test can help you decipher your true weight loss potential
Reply
/
Enter your comment...