3609961 SQL Queries

Embed Size (px)

Citation preview

  • 8/2/2019 3609961 SQL Queries

    1/49

    Gopal Prasad Patel

    Queries compiled by Gopal Prasad Patel

    'The following are the most twisted 150 queries..i think it will be very muchuseful and handy in case 'when u can't solve these queries.....of course !! It took to bit of brain'to solve these...(may be one or 2 or 3 are doubtful!! but will work...sometimes different answers

    will come up if u r working with oracle on a network and on a personal edition......

    ....I welcome feedbacks..!!

    TABLES:

    1) Table name - programmer

    name not null varchar2(8) namedob not null date date of birthdoj not null date date of joiningsex not null varchar2(1) male or femaleprof1 varchar2(8) known language 1

    prof2 varchar2(8) known language 2salary not null number(4) salary

    Entry eg:Gopal 21-apr-66 21-apr-92 m pascal basic 3200

    2) Table name - software

    name not null varchar2(8) nametitle not nullvarchar2(20) developed project namedev_in not null varchar2(8) language developed

    scost number(7,2) software costdcost number(5) development costsold number(3) number of software sold

    Entry eg:Gopal parachutes basic 399.95 6000 43

    3) Table name - studies

    name not null varchar2(8) namesplace not null varchar2(9) studies placecourse not null varchar2(5) course studied

    ccost not null number(5) course cost

    Entry example:Gopal Sabhari pgdca 4500devdutt bdps dcs 5000

    QUERIES - I

    [email protected] Page 1 of 49

    mailto:[email protected]:[email protected]
  • 8/2/2019 3609961 SQL Queries

    2/49

    Gopal Prasad Patel

    1) Find out the SELLING COST AVERAGE for the packages developed in PASCAL?2) Display the names and ages of all programmers.3) Display the names and ages of all the programmers4) What is the highest numbers of copies sold by a package?5) Display the names and date of birth of all the programmer born in JANUARY.6) Display lowest course fee.7) How many programmer has done PGDCA course.8) How much revenue has been earned through sales of packages in C.9) Display the details of software developed by Ramesh?10) How many programmers studied at SABHARI.11) Display the details of PACKAGES whose sales crossed the 20000 mark.12) Find out the number of copies which should be sold in order to recover the development costof each package.13) What is the price of the costliest software developed in BASIC?14) Display the details of packages for which development cost has been recovered.15) How many packages were developed in dbase?16) How many programmers studies at paragathi?17) How many programmers paid 5000 to 10000 for their course?18) What is the average course fee?19) Display the details of programmers knowing c?

    20) How many programmers know either Cobol or Pascal?21) How many programmers don't know Pascal & C?22) How old is the oldest male programmers?23) What is the average age of female programmers?24) Calculate the experience in years for each programmers and display along with the names indescending order?25) Who are the programmers who celebrate their birthday during the current month?26) How many female programmers are there?27) What are the languages known by the male programmers?28) What is the Average salary?29) How many people draw 2000 to 4000?30) Display the details of those who don't know Clipper, Cobol or Pascal?31) How many Female programmers knowing C are above 24 years of age?

    32) Who are the programmers who will be celebrating their Birthday within a week?33 Display the details of those with less than a year's experience?34 Display the details of those who will be completing 2 years of service this year?35 Calculate the amount to be recovered for those packages whose development cost has notbeen recovered?36)ist the packages which have not been sold so far?37) Find out the cost of the software developed by Mary?38) Display the institutes names from the studies table without duplicates?39) How many different courses are mentioned in the studies table?40) Display the names of the programmers whose names contain 2 occurrences of the letter A?41) Display the names of programmers whose names contain unto 5 characters?42) How many female programmers knowing COBOL have more than 2 years experience?43) What is the length of the shortest name in the programmer table?

    44) What is the average development cost of a package developed in COBOL?45) Display the name,sex,dob(DD/MM/YY format), doj for all the programmers without usingconversion function?46) Who are the programmers who were born on the last day of the month?47) What is the amount paid in salaries of the male programmers who do not know Cobol?48) Display the title, scost, dcost and difference between scost and dcost in descending order ofdifference?49) Display the name, dob, doj of those month of birth and month of joining are same?50) Display the names of the packages whose names contain more than 1 word?

    [email protected] Page 2 of 49

  • 8/2/2019 3609961 SQL Queries

    3/49

    Gopal Prasad Patel

    QUERIES - II

    1) Display THE NUMBER OF packages developed in EACH language.2) Display THE NUMBER OF packages developed by EACH person.3) Display THE NUMBER OF male and female programmer.4) Display THE COSTLIEST packages and HIGEST selling developed in EACH language.5) Display THE NUMBER OF people BORN in EACH YEAR.6) Display THE NUMBER OF people JOINED in EACH YEAR.7) Display THE NUMBER OF people BORN in EACH MONTH.8) Display THE NUMBER OF people JOINED in EACH MONTH.9) Display the language wise COUNTS of prof1.10) Display the language wise COUNTS of prof2.11) Display THE NUMBER OF people in EACH salary group.12) Display THE NUMBER OF people who studied in EACH institute.13) Display THE NUMBER OF people who studied in EACH course.14) Display the TOTAL development COST of the packages developed in EACH language.15) Display the selling cost of the package developed in EACH language.

    16) Display the cost of the package developed by EACH programmer.17) Display the sales values of the package developed in EACH programmer.18) Display the NUMBER of packages developed by EACH programmer.19) Display the sales COST of packages developed by EACH programmer language wise.20) Display EACH programmers name, costliest package and cheapest packages developed byHim/Her.21) Display EACH language name with AVERAGE development cost, AVERAGE cost, sellingcost and AVERAGE price per copy.22) Display EACH institute name with NUMBER of courses, AVERAGE cost per course.23) Display EACH institute name with NUMBER of students.24) Display names of male and female programmers.25) Display the programmer's name and their packages.26) Display the NUMBER of packages in EACH language.

    27) Display the NUMBER of packages in EACH language for which development cost is less than1000.28) Display the AVERAGE difference BETWEEN scost and dcost for EACH language.29) Display the TOTAL scost, dcsot and amount TOBE recovered for EACH programmer forwhose dcost HAS NOT YET BEEN recovered.30) Display highest, lowest and average salaries for THOSE earning MORE than 2000.

    QUERIES - III

    1) Who is the highest paid C programmer?2) Who is the highest paid female cobol programmer?

    3) Display the name of the HIGEST paid programmer for EACH language (prof1)4) Who is the LEAST experienced programmer?5) Who is the MOST experienced programmer?6) Which language is known by ONLY ONE programmer?7) Who is the YONGEST programmer knowing DBASE?8) Which institute has MOST NUMBER of students?9) Who is the above programmer?10) Which female programmer earns MORE than 3000/- but DOES NOT know C, C++, Oracle orDbase?

    [email protected] Page 3 of 49

  • 8/2/2019 3609961 SQL Queries

    4/49

    Gopal Prasad Patel

    11) Which is the COSTLIEST course?12) Which course has been done by MOST of the students?13) Display name of the institute and course Which has below AVERAGE course fee?14) Which institute conducts COSTLIEST course?15) Which course has below AVERAGE number of students?16) Which institute conducts the above course?17) Display names of the course WHOSE fees are within 1000(+ or -) of the AVERAGE fee.18) Which package has the HIGEST development cost?19) Which package has the LOWEST selling cost?20) Who developed the package, which has sold the LEAST number of copies?21) Which language was used to develop the package WHICH has the HIGEST sales amount?22) How many copies of the package that has the LEAST DIFFRENCE between developmentand selling cost were sold?23) Which is the COSTLIEAST package developed in PASCAL?24) Which language was used to develop the MOST NUMBER of package?25) Which programmer has developed the HIGEST NUMBER of package?26) Who is the author of the COSTLIEST package?27) Display names of packages WHICH have been sold LESS THAN the AVERAGE number ofcopies?28) Who are the female programmers earning MORE than the HIGEST paid male programmers?

    29) Which language has been stated as prof1 by MOST of the programmers?30) Who are the authors of packages, WHICH have recovered MORE THAN double thedevelopment cost?31) Display programmer names and CHEAPEST package developed by them in EACHlanguage?32) Who is the YOUNGEST male programmer born in 1965?33) Display language used by EACH programmer to develop the HIGEST selling and LOWESTselling package.34) Who is the OLDEST female programmer WHO joined in 199235) In WHICH year where the MOST NUMBER of programmer born?36) In WHICH month did MOST NUMBRER of programmer join?37) In WHICH language are MOST of the programmer's proficient?38) Who are the male programmers earning BELOW the AVERAGE salary of female

    programmers?

    QUERY - IV

    1) Display the details of THOSE WHO are drawing the same salary.2) Display the details of software developed by male programmers earing MORE than 3000.3) Display details of packages developed in PASCAL by female programmers.4) Display the details of these programmer WHO joined BEFORE 1990.5)Display details of software developed in C by female programmers of PRAGATHI.6) Display NUMBER of packages NUMBER of copies sold and sales value of EACH programmerInstitute-wise.7) Display details of software developed in DBASE by male programmers WHO belong to the

    institute on which MOST NUMBER OF programmers studies.8) Display the details of the software that was developed by male programmers born BEFORE1965 and female programmers born AFTER 1975.9) Display the details of the software that was developed in the language that is NOT theprogrammers first proficiency.10) Display details of software that was developed in the language which is NITHER first NORsecond proficiency of the programmer.11) Display details of software developed by male students of SABHARI.12) Display the names of programmers WHO HAVE NOT developed any package.

    [email protected] Page 4 of 49

  • 8/2/2019 3609961 SQL Queries

    5/49

    Gopal Prasad Patel

    13) What is the total cost of the software developed by the programmers by APPLE?14) Who are the programmers WHO JOINED in the same day?15) Who are the programmers WHO HAVE THE SAME PROF2?16) Display the total sales values of software, institutes-wise.17) In which institutes did the person who developed the COSTLIEST package study?18) Which language listed in prof1 and prof2 HAS NOT BEEN used to develop any package?19) How much does the person WHO developed the HIGHEST selling package earn and WHATcourse did he/she undergo?20) How many months will it take for each programmer to recover the cost of the courseunderwent?21) Which is the COSTLIEST package developed by a person with under 3 years expenence?22) What is the AVERAGE salary for those WHOSE software's sales value is more than 50,000?23) How many packages were developed by the students WHO studied in the institute thatCharge the LOWEST course fee?24) How many packages were developed by the person WHO developed the CHEAPESTpackage. Where did he\she study?25) How many packages were developed by female programmers earning MORE than theHIGHEST paid male programmer?26) How many packages were developed by the MOST experienced programmers from BDPS.27) List the programmers (from software table) and institutes they studied, including those WHO

    DIDN'T develop any package.28) List each profit with the number of programmers having that prof1 and the number ofpackages developed in that prof1.29) List programmer names (from programmer table) and number of packages EACH developed.30) List all the details of programmers who has done a course at S.S.I.L.

    QUERIES - I

    1) Find out the SELLING COST AVERAGE for the packages developed in PASCAL?

    SELECT AVG(SCOST)FROM SOFTWARE

    WHERE DEV_IN LIKE 'PASCAL'

    Output:AVG(SCOST)----------

    2362.48

    2) Display the names and ages of all programmers.

    SELECT NAME AS NAME,FLOOR((SYSDATE-DOB)/365) AS AGEFROM PROGRAMMER

    OR

    SELECT 100 + MONTHS_BETWEEN(SYSDATE,DOB)/12 FROM PROGRAMMER;

    Output:NAME AGE-------- ----------

    ANAND 34

    [email protected] Page 5 of 49

  • 8/2/2019 3609961 SQL Queries

    6/49

    Gopal Prasad Patel

    ALTAF 36JAGADESH 30JULIANA 32KAMALA 32MARY 30NELSON 35PATRICK 35QADIR 35RAMESH 33REBECCA 33REMITHA 30REVATHI 31VIJAYA 35

    3) Display the names and ages of all the programmers.

    SELECT NAMEFROM STUDIESWHERE COURSE LIKE 'DAP'

    Output:NAME--------NELSONREVATHI

    4) What is the highest numbers of copies sold by a package?

    SELECT MAX(SOLD) FROM SOFTWARE

    Output:SOLD

    ----------

    114

    5) Display the names and date of birth of all the programmer born in JANUARY.

    SELECT DOB,NAMEFROM PROGRAMMERWHERE TO_CHAR(DOB,'MON') LIKE 'JAN'

    Output:DOB NAME--------- --------31-JAN-68 JULIANA01-JAN-67 REBECCA

    6) Display lowest course fee.

    SELECT MIN(CCOST) FROM STUDIES

    [email protected] Page 6 of 49

  • 8/2/2019 3609961 SQL Queries

    7/49

    Gopal Prasad Patel

    Output:MIN(CCOST)----------

    3500

    7) How many programmer has done PGDCA course.

    SELECT COUNT(NAME)FROM STUDIESWHERE COURSE LIKE 'PGDCA'

    Output:COUNT(NAME)-----------

    3

    8) How much revenue has been earned through sales of packages in C.

    SELECT SUM(SOLD*SCOST)

    FROM SOFTWAREWHERE DEV_IN LIKE 'C'

    Output:SUM(SOLD*SCOST)---------------

    1137759) Display the details of software developed by Ramesh?

    SELECT *FROM SOFTWAREWHERE NAME='RAMESH'

    Output:NAME TITLE DEV_IN SCOST DCOST SOLD-------- -------------------- -------- ---------- ---------- ----------RAMESH HOTEL MANAGEMENT DBASE 12000 35000 4RAMESH DEAD LEE PASCAL 99.95 4500 73

    10) How many programmers studied at SABHARI.

    SELECT COUNT(NAME) AS NOPROGRAMMERSFROM STUDIESWHERE SPLACE='SABHARI'

    Output:

    NOPROGRAMMERS-------------4

    11) Display the details of PACKAGES whose sales crossed the 20000 mark.

    SELECT *FROM SOFTWARE

    [email protected] Page 7 of 49

  • 8/2/2019 3609961 SQL Queries

    8/49

    Gopal Prasad Patel

    WHERE (SOLD*SCOST)>20000

    Output:NAME TITLE DEV_IN SCOST DCOST SOLD-------- -------------------- -------- ---------- ---------- ----------

    ANAND VIDEO TITLING PACK PASCAL 7500 16000 9JAGADESH SHARES MANAGEMENT ORACLE 3000 12000 14KAMALA PAYROLL PACKAGE DBASE 9000 20000 7MARY FINANCILA ACC S/W ORACLE 18000 85000 4MARY CODE GENERATOR C 4500 20000 23MARY READ ME C++ 300 1200 84QADIR BOMBS AWAY ASSEMBLY 499.95 530 114QADIR VACCINES C 1900 3400 21RAMESH HOTEL MANAGEMENT DBASE 12000 35000 4REMITHA PC UTILITIES C 725 5000 51REVATHI QUIZ MASTER BASIC 3200 2100 15

    12) Find out the number of copies which should be sold in order to recover the development costof each package.

    SELECT ROUND(DCOST/SCOST)FROM SOFTWAREWHERE SCOST*SOLD

  • 8/2/2019 3609961 SQL Queries

    9/49

    Gopal Prasad Patel

    14) Display the details of packages for which development cost has been recovered.

    SELECT *FROM SOFTWAREWHERE (SOLD*SCOST)>DCOST

    Output:NAME TITLE DEV_IN SCOST DCOST SOLD-------- -------------------- -------- ---------- ---------- ----------

    ANAND PARACHUTES BASIC 399.95 6000 43 ANAND VIDEO TITLING PACK PASCAL 7500 16000 9JAGADESH SERIAL LINK UTILITY JAVA 800 7500 10JAGADESH SHARES MANAGEMENT ORACLE 3000 12000 14KAMALA PAYROLL PACKAGE DBASE 9000 20000 7MARY CODE GENERATOR C 4500 20000 23MARY READ ME C++ 300 1200 84PATRICK GRAPHIC EDITOR PASCAL 750 5000 11

    QADIR BOMBS AWAY ASSEMBLY 499.95 530 114QADIR VACCINES C 1900 3400 21RAMESH HOTEL MANAGEMENT DBASE 12000 35000 4RAMESH DEAD LEE PASCAL 99.95 4500 73REMITHA PC UTILITIES C 725 5000 51REMITHA TSR HELP PACKAGE ASSEMBLY 2500 6000 6REVATHI QUIZ MASTER BASIC 3200 2100 15VIJAYA ISK EDITOR C 900 700 6

    15) How many packages were developed in dbase?

    SELECT COUNT(TITLE) AS TOTALFROM SOFTWARE

    WHERE DEV_IN='DBASE'

    Output:TOTAL

    ----------2

    16) How many programmers studies at paragathi?

    SELECT COUNT(NAME)FROM STUDIESWHERE SPLACE='PRAGATHI'

    Output:COUNT(NAME)-----------

    317) How many programmers paid 5000 to 10000 for their course?

    SELECT COUNT(NAME) AS NOOFPROGRAMMERSFROM STUDIESWHERE CCOST>=5000

    [email protected] Page 9 of 49

  • 8/2/2019 3609961 SQL Queries

    10/49

    Gopal Prasad Patel

    AND CCOST

  • 8/2/2019 3609961 SQL Queries

    11/49

    Gopal Prasad Patel

    FROM PROGRAMMERWHERE PROF1!='C'

    AND PROF1!='PASCAL'AND PROF2!='C'AND PROF2!='PASCAL'

    Output:PROGRAMMER----------

    6

    22) How old is the oldest male programmers?

    SELECT MAX(FLOOR((SYSDATE - DOB)/365)) AS OLDESTMALEPROGRAMMERAGEFROM PROGRAMMER

    Output:OLDESTMALEPROGRAMMERAGE-----------------------

    36

    23) What is the average age of female programmers?

    SELECT FLOOR(AVG(FLOOR((SYSDATE - DOB)/365))) AS AVERAGEFEMALEAGEFROM PROGRAMMER

    Output:AVERAGEFEMALEAGE----------------

    32

    24) Calculate the experience in years for each programmers and display along with the names indescending order?

    SELECT NAME AS PRNAME,FLOOR((SYSDATE - DOJ)/365) AS EXPERIENCEFROM PROGRAMMERORDER BY NAME DESC

    Output:PR_NAME EXPERIENCE-------- ----------VIJAYA 8

    REVATHI 9REMITHA 7REBECCA 10RAMESH 10QADIR 7PATRICK 10NELSON 11MARY 10KAMALA 9

    [email protected] Page 11 of 49

  • 8/2/2019 3609961 SQL Queries

    12/49

    Gopal Prasad Patel

    JULIANA 10JAGADISH 6

    ANAND 8 ALTAF 10

    25) Who are the programmers who celebrate their birthday during the current month?

    SELECT NAMEFROM PROGRAMMERWHERE TO_CHAR(DOB,'MM')=TO_CHAR(SYSDATE,'MM')

    Output:NAME--------

    ANANDREMITHA

    26) How many female programmers are there?

    SELECT COUNT(NAME) AS NOFPROG

    FROM PROGRAMMERWHERE SEX='F'

    Output:NO_OF_FEMALE_PROGRAMMERS------------------------

    7

    27) What are the languages known by the male programmers?

    SELECT DISTINCT PROF1 AS LANGUAGESFROM PROGRAMMERWHERE SEX='M'UNIONSELECT DISTINCT PROF2 AS LANGUAGESFROM PROGRAMMERWHERE SEX='M'

    Output:LANGUAGE--------

    ASSEMBLY

    BASICCCLIPPERCOBOLDBASEJAVAORACLEPASCAL

    [email protected] Page 12 of 49

  • 8/2/2019 3609961 SQL Queries

    13/49

    Gopal Prasad Patel

    28) What is the Average salary?

    SELECT AVG(SALARY) AS AVGSALFROM PROGRAMMER

    Output:AVERAGE_SALARY--------------

    3235.714329) How many people draw 2000 to 4000?

    SELECT NAME AS PRNAMEFROM PROGRAMMERWHERE SALARY>= 2000OR SALARY

  • 8/2/2019 3609961 SQL Queries

    14/49

    Gopal Prasad Patel

    QADIR 31-AUG-65 21-APR-93 M ASSEMBLY C 3000REMITHA 19-APR-70 20-APR-93 F C ASSEMBLY 3600VIJAYA 14-DEC-65 02-MAY-92 F FOXPRO C 3500

    31) How many Female programmers knowing C are above 24 years of age?

    SELECT COUNT(NAME) AS NOOFFPRGFROM PROGRAMMERWHERE SEX='F'

    AND (PROF1='C' OR PROF2='C')AND ((SYSDATE-DOB)/365) > 24

    Output:NOOFFPRG

    ----------3

    32) Who are the programmers who will be celebrating their Birthday within a week?

    SELECT NAME

    FROM PROGRAMMERWHERE TO_CHAR(DOB,'WW') LIKE TO_CHAR(SYSDATE,'WW')

    OR

    select * from programmer whereto_char(dob,'dd') between to_char(sysdate,'dd') andto_char(next_day(sysdate,(to_char(sysdate,'day'))),'dd') andto_char(dob,'mon') between to_char(sysdate,'mon') andto_char(next_day(sysdate,(to_char(sysdate,'day'))),'mon')

    Output:no rows selected

    33 Display the details of those with less than a year's experience?

    SELECT *FROM PROGRAMMERWHERE FLOOR((SYSDATE - DOJ)/365)

  • 8/2/2019 3609961 SQL Queries

    15/49

    Gopal Prasad Patel

    REVATHI 02-DEC-69 02-JAN-92 F PASCAL BASIC 3700VIJAYA 14-DEC-65 02-MAY-92 F FOXPRO C 3500

    14 rows selected.

    34 Display the details of those who will be completing 2 years of service this year?

    SELECT NAME AS PRNAMEFROM PROGRAMMER WHERE FLOOR((SYSDATE-DOJ)/365)=2;

    OR

    select * from programmer where(to_number(to_char(sysdate,'yyyy'))-to_number(to_char(doj,'yyyy')))=2;

    OR

    SELECT * FROM PROGRAMMER WHERE

    (100 + MONTHS_BETWEEN('31-DEC-00',DOJ)/12)>=2 AND(100 + MONTHS_BETWEEN(SYSDATE,DOJ)/12) != 2;

    Output:no rows selected

    35 Calculate the amount to be recovered for those packages whose development cost has notbeen recovered?

    SELECT (DCOST-(SCOST*SOLD)),TITLEFROM SOFTWAREWHERE (SCOST*SOLD)

  • 8/2/2019 3609961 SQL Queries

    16/49

    Gopal Prasad Patel

    WHERE NAME='MARY'

    Output:SOFTNAME SOFTCOST-------------------- ----------FINANCILA ACC S/W 18000CODE GENERATOR 4500READ ME 300

    38) Display the institutes names from the studies table without duplicates?

    SELECT DISTINCT SPLACEFROM STUDIES

    Output:SPLACE---------

    APPLEBDPSBITS

    BRILLIANTCCITPRAGATHIS.S.I.LSABHARI

    39) How many different courses are mentioned in the studies table?

    SELECT DISTINCT COURSE AS COURSESFROM STUDIES

    Output:COURS-----DAPDCADCA/PDCAPDCPDCSHDCPPGDCA

    40) Display the names of the programmers whose names contain 2 occurrences of the letter A?

    SELECT NAMEFROM PROGRAMMERWHERE NAME LIKE '%A%A%'

    Output:NAME--------

    ANAND

    [email protected] Page 16 of 49

  • 8/2/2019 3609961 SQL Queries

    17/49

    Gopal Prasad Patel

    ALTAFJAGADESHJULIANAKAMALAVIJAYA

    41) Display the names of programmers whose names contain unto 5 characters?

    SELECT NAMEFROM PROGRAMMERWHERE LENGTH(NAME)=5

    Output:NAME--------

    ANANDALTAFQADIR

    42) How many female programmers knowing COBOL have more than 2 years experience?

    SELECT NAME AS PRNAMEFROM PROGRAMMERWHERE FLOOR((SYSDATE-DOJ)/365)>2

    AND SEX='F'AND (PROF1='COBOL' OR PROF2='COBOL')

    Output:PRNAME--------JULIANAREBECCA

    43) What is the length of the shortest name in the programmer table?

    SELECT MIN(LENGTH(NAME)) AS SHORTNAMEFROM PROGRAMMER

    Output:SHORTNAME

    ----------4

    44) What is the average development cost of a package developed in COBOL?

    SELECT AVG(DCOST) AS AVGCOSTFROM SOFTWAREWHERE DEV_IN='COBOL'

    Output:AVGCOST

    [email protected] Page 17 of 49

  • 8/2/2019 3609961 SQL Queries

    18/49

    Gopal Prasad Patel

    ----------3500

    45) Display the name,sex,dob(DD/MM/YY format), doj for all the programmers without usingconversion function?

    SELECT NAME AS PRNAME, SEX AS SEX, SUBSTR(DOB,1,2)||'/'||SUBSTR(DOB,4,3)||'/'||SUBSTR(DOB,8,2) AS DATEOFBIRTH, SUBSTR(DOJ,1,2)||'/'||SUBSTR(DOJ,4,3)||'/'||SUBSTR(DOJ,8,2) AS DATEOFJOIN FROM PROGRAMMER

    Output:PRNAME S DATEOFBIR DATEOFJOI-------- - --------- ---------

    ANAND M 21/APR/66 21/APR/92 ALTAF M 02/JUL/64 13/NOV/90JAGADESH M 06/OCT/70 04/OCT/94JULIANA F 31/JAN/68 21/APR/90KAMALA F 30/OCT/68 02/JAN/92

    MARY F 24/JUN/70 01/FEB/91NELSON M 11/SEP/65 11/OCT/89PATRICK M 19/NOV/65 21/APR/90QADIR M 31/AUG/65 21/APR/93RAMESH M 03/MAY/67 28/FEB/91REBECCA F 01/JAN/67 01/DEC/90REMITHA F 19/APR/70 20/APR/93REVATHI F 02/DEC/69 02/JAN/92VIJAYA F 14/DEC/65 02/MAY/92

    46) Who are the programmers who were born on the last day of the month?

    SELECT NAME AS PRNAME

    FROM PROGRAMMERWHERE LAST_DAY(DOB) LIKE DOB

    Output:PRNAME--------JULIANAQADIR

    47) What is the amount paid in salaries of the male programmers who do not know Cobol?

    SELECT SALARY AS SALOFPRFROM PROGRAMMERWHERE SEX='M'

    AND (PROF1!='COBOL'OR PROF2!='COBOL)

    [email protected] Page 18 of 49

  • 8/2/2019 3609961 SQL Queries

    19/49

    Gopal Prasad Patel

    Output:SALOFPR

    ----------3200280041002500280030003200

    48) Display the title, scost, dcost and difference between scost and dcost in descending order ofdifference?

    SELECT TITLE AS SOFTNAME,SCOST AS SOFTCOST,DCOST AS DEVCOST,DCOST -SCOST DIFF FROM SOFTWAREORDER BY 4 DESC

    Output:

    SOFTNAME SOFTCOST DEVCOST DIFF-------------------- ---------- ---------- ----------HOTEL MANAGEMENT 1100 75000 73900FINANCILA ACC S/W 18000 85000 67000HOTEL MANAGEMENT 12000 35000 23000CODE GENERATOR 4500 20000 15500PAYROLL PACKAGE 9000 20000 11000SHARES MANAGEMENT 3000 12000 9000VIDEO TITLING PACK 7500 16000 8500SERIAL LINK UTILITY 800 7500 6700PARACHUTES 399.95 6000 5600.05DEAD LEE 99.95 4500 4400.05PC UTILITIES 725 5000 4275

    GRAPHIC EDITOR 750 5000 4250TSR HELP PACKAGE 2500 6000 3500VACCINES 1900 3400 1500READ ME 300 1200 900INVENTORY CONTROL 3000 3500 500BOMBS AWAY 499.95 530 30.05ISK EDITOR 900 700 -200QUIZ MASTER 3200 2100 -1100

    49) Display the name, dob, doj of those month of birth and month of joining are same?

    SELECT NAME AS PRNAMEFROM PROGRAMMER

    WHERE TO_CHAR(DOB,'MM')=TO_CHAR(DOJ,'MM')

    Output:PRNAME--------

    ANANDJAGADESHREMITHA

    [email protected] Page 19 of 49

  • 8/2/2019 3609961 SQL Queries

    20/49

    Gopal Prasad Patel

    50) Display the names of the packages whose names contain more than 1 word?

    SELECT TITLE AS PACKAGESFROM SOFTWAREWHERE TITLE LIKE '% %'

    Output:PACKAGES--------------------VIDEO TITLING PACKSERIAL LINK UTILITYSHARES MANAGEMENTINVENTORY CONTROLPAYROLL PACKAGEFINANCILA ACC S/WCODE GENERATOR

    READ MEGRAPHIC EDITORBOMBS AWAYHOTEL MANAGEMENTDEAD LEEPC UTILITIESTSR HELP PACKAGEHOTEL MANAGEMENTQUIZ MASTERISK EDITOR

    QUERIES - II

    1) Display THE NUMBER OF packages developed in EACH language.

    SELECT DEV_IN AS LANGUAGE,COUNT(TITLE) AS NOOFPACKFROM SOFTWAREGROUP BY DEV_IN

    Output:LANGUAGE NOOFPACK-------- ----------

    ASSEMBLY 2BASIC 2C 4C++ 1COBOL 1DBASE 2JAVA 1ORACLE 2PASCAL 4

    [email protected] Page 20 of 49

  • 8/2/2019 3609961 SQL Queries

    21/49

    Gopal Prasad Patel

    2) Display THE NUMBER OF packages developed by EACH person.

    SELECT NAME AS PRNAME,COUNT(TITLE)AS NOOFPACKFROM SOFTWAREGROUP BY NAME

    Output:PRNAME NOOFPACK-------- ----------

    ANAND 2JAGADESH 2JULIANA 1KAMALA 1MARY 3PATRICK 1QADIR 2RAMESH 2REMITHA 2REVATHI 2

    VIJAYA 1

    3) Display THE NUMBER OF male and female programmer.

    SELECT SEX,COUNT(NAME) AS NAMEFROM PROGRAMMERGROUP BY SEXOutput:S NAME- ---------F 7M 7

    4) Display THE COSTLIEST packages and HIGEST selling developed in EACH language.

    SELECT DEV_IN AS LANGAUGE,MAX(SCOST) AS COSTPACK,MAX(SOLD) AS HIGHPACKSFROM SOFTWARE

    GROUP BY DEV_IN

    Output:LANGAUGE COSTPACK HIGHPACK-------- ---------- ----------

    ASSEMBLY 2500 114BASIC 3200 43C 4500 51C++ 300 84

    [email protected] Page 21 of 49

  • 8/2/2019 3609961 SQL Queries

    22/49

    Gopal Prasad Patel

    COBOL 3000 0DBASE 12000 7JAVA 800 10ORACLE 18000 14PASCAL 7500 73

    5) Display THE NUMBER OF people BORN in EACH YEAR.

    SELECT TO_CHAR(DOB,'YY') AS YEAR,COUNT(NAME) AS PRNOFROM PROGRAMMERGROUP BY TO_CHAR(DOB,'YY')

    Output:YE PRNO-- ----------64 165 466 167 268 2

    69 170 3

    6) Display THE NUMBER OF people JOINED in EACH YEAR.

    SELECT TO_CHAR(DOJ,'YY') AS YEAR,COUNT(NAME) AS PRNOFROM PROGRAMMERGROUP BY TO_CHAR(DOJ,'YY')

    Output:YE PRNO-- ----------89 1

    90 491 292 493 294 1

    7) Display THE NUMBER OF people BORN in EACH MONTH.

    SELECT SUBSTR(DOB,4,3) AS MONTHOFBIRTH,COUNT(NAME) AS PRNO FROMPROGRAMMER

    [email protected] Page 22 of 49

  • 8/2/2019 3609961 SQL Queries

    23/49

    Gopal Prasad Patel

    GROUP BY SUBSTR(DOB,4,3)

    Output:MON PRNO--- ----------

    APR 2 AUG 1DEC 2JAN 2JUL 1JUN 1MAY 1NOV 1OCT 2SEP 1

    8) Display THE NUMBER OF people JOINED in EACH MONTH.

    SELECT SUBSTR(DOJ,4,3) AS MONTHOFJOIN,COUNT(NAME) AS PRNOFROM PROGRAMMER

    GROUP BY SUBSTR(DOJ,4,3)

    Output:MON PRNO--- ----------

    APR 5DEC 1FEB 2JAN 2MAY 1NOV 1OCT 2

    9) Display the language wise COUNTS of prof1.

    SELECT PROF1 AS LANGUAGE, COUNT(PROF1) AS PROF1COUNTFROM PROGRAMMERGROUP BY PROF1

    Output:LANGUAGE PROF1COUNT-------- ----------

    Assembly 1Basic 1C 2C++ 1

    Clipper 1Cobol 2Foxpro 1Oracle 1Pascal 4

    [email protected] Page 23 of 49

  • 8/2/2019 3609961 SQL Queries

    24/49

    Gopal Prasad Patel

    10) Display the language wise COUNTS of prof2.

    SELECT PROF2 AS LANGUAGE, COUNT(PROF2) AS PROF2COUNTFROM PROGRAMMERGROUP BY PROF2

    Output:LANGUAGE PROF2COUNT-------- ----------

    Assembly 1Basic 2C 2Clipper 1Cobol 2

    Dbase 4Java 1Oracle 1

    11) Display THE NUMBER OF people in EACH salary group.

    SELECT SALARY,COUNT(NAME) AS PEOPLEFROM PROGRAMMERGROUP BY SALARY

    Output:SALARY PEOPLE

    ---------- ----------

    2500 22800 22900 13000 23200 23500 13600 13700 14100 14500 1

    12) Display THE NUMBER OF people who studied in EACH institute.

    SELECT SPLACE AS INSTITUTE,COUNT(NAME) AS PEOPLEFROM STUDIESGROUP BY SPLACE

    Output:INSTITUTE PEOPLE--------- ----------

    APPLE 1BDPS 2

    [email protected] Page 24 of 49

  • 8/2/2019 3609961 SQL Queries

    25/49

    Gopal Prasad Patel

    BITS 1BRILLIANT 1CCIT 1PRAGATHI 3S.S.I.L 1SABHARI 4

    13) Display THE NUMBER OF people who studied in EACH course.

    SELECT COURSE AS STUDY,COUNT(NAME) AS PEOPLEFROM STUDIES GROUP BY COURSE

    Output:STUDY PEOPLE----- ----------DAP 2DCA 4DCA/P 1DCAP 1DCP 1DCS 1HDCP 1PGDCA 3

    14) Display the TOTAL development COST of the packages developed in EACH language.

    SELECT DEV_IN AS LANGUAGE,SUM(DCOST) AS TOTCOSTFROM SOFTWAREGROUP BY DEV_IN

    Output:LANGUAGE TOTCOST-------- ----------

    ASSEMBLY 6530BASIC 8100C 29100C++ 1200COBOL 3500

    DBASE 55000JAVA 7500ORACLE 97000PASCAL 100500

    15) Display the selling cost of the package developed in EACH language.

    SELECT DEV_IN AS LANGUAGE,SUM(SCOST) AS SELLCOSTFROM SOFTWARE

    [email protected] Page 25 of 49

  • 8/2/2019 3609961 SQL Queries

    26/49

    Gopal Prasad Patel

    GROUP BY DEV_IN

    Output:LANGUAGE SELLCOST-------- ----------

    ASSEMBLY 2999.95BASIC 3599.95C 8025C++ 300COBOL 3000DBASE 21000JAVA 800ORACLE 21000PASCAL 9449.95

    16) Display the cost of the package developed by EACH programmer.

    SELECT NAME AS PRNAME,SUM(DCOST) AS TOTCOSTFROM SOFTWAREGROUP BY NAME

    Output:PRNAME TOTCOST-------- ----------

    ANAND 22000JAGADESH 19500JULIANA 3500KAMALA 20000MARY 106200PATRICK 5000QADIR 3930RAMESH 39500REMITHA 11000REVATHI 77100VIJAYA 700

    17) Display the sales values of the package developed in EACH programmer.

    SELECT NAME AS PRNAME, SUM(SCOST*SOLD) AS SALESVALFROM SOFTWAREGROUP BY NAME

    Output:PRNAME SALESVAL-------- ----------

    ANAND 84697.85

    [email protected] Page 26 of 49

  • 8/2/2019 3609961 SQL Queries

    27/49

    Gopal Prasad Patel

    JAGADESH 50000JULIANA 0KAMALA 63000MARY 200700PATRICK 8250QADIR 96894.3RAMESH 55296.35REMITHA 51975REVATHI 50200GOPAL 5400

    18) Display the NUMBER of packages developed by EACH programmer.

    SELECT NAME AS PRNAME,COUNT(TITLE) AS TOTPACKFROM SOFTWAREGROUP BY NAME

    Output:PRNAME TOTPACK-------- ----------

    ANAND 2JAGADESH 2JULIANA 1KAMALA 1MARY 3GOPAL 1NIHAR 2RAMESH 2REMITHA 2REVATHI 2VIJAYA 1

    19) Display the sales COST of packages developed by EACH programmer language wise.

    SELECT SUM(SCOST) AS SELLCOSTFROM SOFTWAREGROUP BY DEV_IN

    Output:SELLCOST

    ----------2999.953599.95

    8025300300021000800

    210009449.92

    [email protected] Page 27 of 49

  • 8/2/2019 3609961 SQL Queries

    28/49

    Gopal Prasad Patel

    20) Display EACH programmers name, costliest package and cheapest packages developed byHim/Her.

    SELECT NAME PRNAME,MIN(DCOST) CHEAPEST,MAX(DCOST) COSTLIESTFROM SOFTWAREGROUP BY NAME

    Output:PRNAME CHEAPEST COSTLIEST-------- ---------- ----------

    ANAND 6000 16000JAGADESH 7500 12000JULIANA 3500 3500KAMALA 20000 20000MARY 1200 85000PATRICK 5000 5000QADIR 530 3400RAMESH 4500 35000REMITHA 5000 6000REVATHI 2100 75000

    VIJAYA 700 700

    21) Display EACH language name with AVERAGE development cost, AVERAGE cost, sellingcost and AVERAGE price per copy.

    SELECT DEV_IN AS LANGUAGE,AVG(DCOST) AS AVGDEVCOST,AVG(SCOST) ASAVGSELLCOST,AVG(SCOST) AS PRICEPERCPYFROM SOFTWAREGROUP BY DEV_IN

    Output:LANGUAGE AVGDEVCOST AVGSELLCOST PRICEPERCPY-------- ---------- ----------- -----------

    ASSEMBLY 3265 1499.975 1499.975BASIC 4050 1799.975 1799.975C 7275 2006.25 2006.25C++ 1200 300 300COBOL 3500 3000 3000DBASE 27500 10500 10500JAVA 7500 800 800ORACLE 48500 10500 10500PASCAL 25125 2362.4875 2362.4875

    22) Display EACH institute name with NUMBER of courses, AVERAGE cost per course.

    SELECT SPLACE AS INSTITUTE,COUNT(COURSE) AS NOOFCOURS,AVG(CCOST) ASAVGCOSTPERCOURFROM STUDIESGROUP BY SPLACE

    Output:

    [email protected] Page 28 of 49

  • 8/2/2019 3609961 SQL Queries

    29/49

    Gopal Prasad Patel

    INSTITUTE NOOFCOURS AVGCOSTPERCOUR--------- ---------- --------------

    APPLE 1 14000BDPS 2 27000BITS 1 22000BRILLIANT 1 11000CCIT 1 7200PRAGATHI 3 5466.66667S.S.I.L 1 3500SABHARI 4 4625

    23) Display EACH institute name with NUMBER of students.

    SELECT SPLACE AS INSTITUTE,COUNT(NAME) AS NOOFSTUDFROM STUDIESGROUP BY SPLACE

    Output:INSTITUTE NOOFSTUD--------- ----------

    APPLE 1BDPS 2BITS 1BRILLIANT 1CCIT 1PRAGATHI 3S.S.I.L 1SABHARI 4

    24) Display names of male and female programmers.

    SELECT NAME AS PRNAME,SEX AS SEXFROM PROGRAMMER

    ORDER BY SEX

    Output:PRNAME S-------- -JULIANA FKAMALA FMARY FREMITHA FVIJAYA FREVATHI FREBECCA F

    ANAND M

    PATRICK MRAMESH MQADIR MNELSON M

    ALTAF MJAGADESH M

    [email protected] Page 29 of 49

  • 8/2/2019 3609961 SQL Queries

    30/49

    Gopal Prasad Patel

    25) Display the programmer's name and their packages.

    SELECT NAME AS PRNAME,TITLE AS PACKAGEFROM SOFTWAREORDER BY NAME

    Output:PRNAME PACKAGE-------- --------------------

    ANAND PARACHUTES ANAND VIDEO TITLING PACKJAGADESH SERIAL LINK UTILITYJAGADESH SHARES MANAGEMENTJULIANA INVENTORY CONTROLKAMALA PAYROLL PACKAGEMARY FINANCILA ACC S/WMARY CODE GENERATORMARY READ ME

    PATRICK GRAPHIC EDITORQADIR BOMBS AWAYQADIR VACCINESRAMESH HOTEL MANAGEMENTRAMESH DEAD LEEREMITHA PC UTILITIESREMITHA TSR HELP PACKAGEREVATHI HOTEL MANAGEMENTREVATHI QUIZ MASTERVIJAYA ISK EDITOR

    26) Display the NUMBER of packages in EACH language.

    SELECT COUNT(TITLE) AS NOOFPACK,DEV_IN AS LANGUAGEFROM SOFTWAREGROUP BY DEV_IN

    Output:NOOFPACK LANGUAGE

    ---------- --------2 ASSEMBLY2 BASIC4 C1 C++1 COBOL2 DBASE

    1 JAVA2 ORACLE4 PASCAL

    27) Display the NUMBER of packages in EACH language for which development cost is less than1000.

    SELECT COUNT(TITLE) AS NOOFPACK,DEV_IN AS LANGUAGEFROM SOFTWARE

    [email protected] Page 30 of 49

  • 8/2/2019 3609961 SQL Queries

    31/49

    Gopal Prasad Patel

    WHERE DCOSTSUM(SOLD*SCOST)

    Output:SUM(SCOST) SUM(DCOST) SUM(DCOST-(SOLD*SCOST))---------- ---------- -----------------------

    3000 3500 35004300 77100 26900

    30) Display highest, lowest and average salaries for THOSE earning MORE than 2000.

    SELECT MAX(SALARY), MIN(SALARY), AVG(SALARY)FROM PROGRAMMERWHERE SALARY > 2000

    Output:MAX(SALARY) MIN(SALARY) AVG(SALARY)----------- ----------- -----------

    [email protected] Page 31 of 49

  • 8/2/2019 3609961 SQL Queries

    32/49

    Gopal Prasad Patel

    4500 2500 3235.7143

    QUERIES - III

    1) Who is the highest paid C programmer?

    SELECT * FROM PROGRAMMERWHERE SALARY=(SELECT MAX(SALARY)FROM PROGRAMMERWHERE PROF1 LIKE 'C' OR PROF2 LIKE 'C')

    Output:NAME DOB DOJ S PROF1 PROF2 SALARY-------- --------- --------- - -------- -------- ---------REMITHA 19-APR-70 20-APR-93 F C ASSEMBLY 3600

    2) Who is the highest paid female cobol programmer?

    SELECT * FROM PROGRAMMERWHERE SALARY=(SELECT MAX(SALARY)FROM PROGRAMMERWHERE (PROF1 LIKE 'COBOL' OR PROF2 LIKE 'COBOL'))

    AND SEX LIKE 'F'

    Output:NAME DOB DOJ S PROF1 PROF2 SALARY-------- --------- --------- - -------- -------- ---------JULIANA 31-JAN-68 21-APR-90 F COBOL DBASE 3000

    3) Display the name of the HIGEST paid programmer for EACH language (prof1)

    SELECT DISTINCT NAME, SALARY, PROF1FROM PROGRAMMERWHERE (SALARY,PROF1) IN (SELECT MAX(SALARY),PROF1FROM PROGRAMMERGROUP BY PROF1)

    Output:NAME SALARY PROF1-------- --------- --------REBECCA 2500 BASIC

    ALTAF 2800 CLIPPERDADIR 3000 ASSEMBLYJULIANA 3000 COBOL

    VIJAYA 3500 FOXPROREMITHA 3600 CREVATHI 3700 PASCALJAGADESH 4100 ORACLEMARY 4500 C++

    4) Who is the LEAST experienced programmer?

    SELECT FLOOR((SYSDATE-DOJ)/365) EXP,NAME

    [email protected] Page 32 of 49

  • 8/2/2019 3609961 SQL Queries

    33/49

    Gopal Prasad Patel

    FROM PROGRAMMERWHERE FLOOR((SYSDATE-DOJ)/365) = (SELECT MIN(FLOOR((SYSDATE-DOJ)/365))FROM PROGRAMMER)

    Output:EXP NAME

    --------- --------5 JAGADESH

    5) Who is the MOST experienced programmer?

    SELECT FLOOR((SYSDATE-DOJ)/365) EXP,NAME,PROF1,PROF2FROM PROGRAMMERWHERE FLOOR((SYSDATE-DOJ)/365) = (SELECT MAX(FLOOR((SYSDATE-DOJ)/365))FROM PROGRAMMER)

    AND (PROF1 LIKE 'COBOL' OR PROF2 LIKE 'COBOL')

    Output:EXP NAME PROF1 PROF2

    --------- -------- -------- --------10 NELSON COBOL DBASE

    6) Which language is known by ONLY ONE programmer?

    SELECT PROF1FROM PROGRAMMERGROUP BY PROF1HAVING PROF1 NOT IN

    (SELECT PROF2 FROM PROGRAMMER)

    AND COUNT(PROF1)=1UNIONSELECT PROF2FROM PROGRAMMERGROUP BY PROF2HAVING PROF2 NOT IN

    (SELECT PROF1 FROM PROGRAMMER)AND COUNT(PROF2)=1;

    Output:PROF1--------C++

    FoxproJava

    7) Who is the YONGEST programmer knowing DBASE?

    SELECT FLOOR((SYSDATE-DOB)/365) AGE, NAME, PROF1, PROF2FROM PROGRAMMERWHERE FLOOR((SYSDATE-DOB)/365) = (SELECT MIN(FLOOR((SYSDATE-DOB)/365))FROM PROGRAMMER

    [email protected] Page 33 of 49

  • 8/2/2019 3609961 SQL Queries

    34/49

    Gopal Prasad Patel

    WHERE PROF1 LIKE 'DBASE' OR PROF2 LIKE 'DBASE')

    Output:AGE NAME PROF1 PROF2---- -------- -------- --------31 JULIANA COBOL DBASE31 KAMALA C DBASE

    8) Which institute has MOST NUMBER of students?

    SELECT SPLACEFROM STUDIESGROUP BY SPLACEHAVING COUNT(SPLACE)= (SELECT MAX(COUNT(SPLACE))

    FROM STUDIES GROUP BY SPLACE)

    Output:SPLACE---------SABHARI

    9) Who is the above programmer?

    SELECT NAMEFROM PROGRAMMERWHERE PROF1 IN (SELECT PROF1

    FROM PROGRAMMERGROUP BY PROF1HAVING PROF1 NOT IN (SELECT PROF2 FROM PROGRAMMER)

    AND COUNT(PROF1)=1UNION

    SELECT PROF2FROM PROGRAMMERGROUP BY PROF2HAVING PROF2 NOT IN (SELECT PROF1 FROM PROGRAMMER)

    AND COUNT(PROF2)=1))UNIONSELECT NAMEFROM PROGRAMMERWHERE PROF2 IN (SELECT PROF1

    FROM PROGRAMMERGROUP BY PROF1HAVING PROF1 NOT IN (SELECT PROF2 FROM PROGRAMMER)

    AND COUNT(PROF1)=1

    UNIONSELECT PROF2FROM PROGRAMMERGROUP BY PROF2HAVING PROF2 NOT IN (SELECT PROF1 FROM PROGRAMMER)

    AND COUNT(PROF2)=1))

    Output:NAME

    [email protected] Page 34 of 49

  • 8/2/2019 3609961 SQL Queries

    35/49

    Gopal Prasad Patel

    --------JAGADESHMARYVIJAYA

    10) Which female programmer earns MORE than 3000/- but DOES NOT know C, C++, Oracle orDbase?

    SELECT * FROM PROGRAMMERWHERE SEX LIKE 'F'

    AND SALARY >3000AND (PROF1 NOT IN('C','C++','ORACLE','DBASE')OR PROF2 NOT IN('C','C++','ORACLE','DBASE'))

    Output:NAME DOB DOJ S PROF1 PROF2 SALARY-------- --------- --------- - -------- -------- ---------REMITHA 19-APR-70 20-APR-93 F C ASSEMBLY 3600REVATHI 02-DEC-69 12-JAN-92 F PASCAL BASIC 3700

    VIJAYA 14-DEC-65 12-MAY-92 F FOXPRO C 3500

    11) Which is the COSTLIEST course?

    SELECT COURSEFROM STUDIESWHERE CCOST = (SELECT MAX(CCOST) FROM STUDIES)

    Output:COURS-----DCA

    12) Which course has been done by MOST of the students?

    SELECT COURSEFROM STUDIESGROUP BY COURSEHAVING COUNT(COURSE)= (SELECT MAX(COUNT(COURSE))

    FROM STUDIESGROUP BY COURSE)

    Output:COURS

    -----DCA

    13) Display name of the institute and course Which has below AVERAGE course fee?

    SELECT SPLACE,COURSEFROM STUDIESWHERE CCOST < (SELECT AVG(CCOST) FROM STUDIES)

    [email protected] Page 35 of 49

  • 8/2/2019 3609961 SQL Queries

    36/49

    Gopal Prasad Patel

    Output:SPLACE COURS--------- -----SABHARI PGDCASABHARI PGDCACCIT DCAS.S.I.L. DCAPRAGATHI DCPSABHARI PGDCAPRAGATHI DAPPRAGATHI DCAPSABHARI PGDCABDPS DCSSABHARI DAP

    14) Which institute conducts COSTLIEST course?

    SELECT SPLACEFROM STUDIESWHERE CCOST = (SELECT MAX(CCOST) FROM STUDIES)

    Output:SPLACE---------BDPS

    15) Which course has below AVERAGE number of students?

    SELECT COURSEFROM STUDIESHAVING COUNT(NAME)

  • 8/2/2019 3609961 SQL Queries

    37/49

    Gopal Prasad Patel

    GROUP BY COURSE);

    Output:SPLACE---------BRILLIANTPRAGATHIPRAGATHIBDPS

    APPLE

    17) Display names of the course WHOSE fees are within 1000(+ or -) of the AVERAGE fee.

    SELECT COURSEFROM STUDIESWHERE CCOST < (SELECT AVG(CCOST)+1000 FROM STUDIES)

    AND CCOST > (SELECT AVG(CCOST)-1000 FROM STUDIES)

    Output:COURS

    -----DCA/P

    18) Which package has the HIGEST development cost?

    SELECT TITLE,DCOSTFROM SOFTWAREWHERE DCOST = (SELECT MAX(DCOST) FROM SOFTWARE)

    Output:TITLE DCOST-------------------- ---------FINANCILA ACC S/W 85000

    19) Which package has the LOWEST selling cost?

    SELECT TITLE,SCOSTFROM SOFTWAREWHERE SCOST = (SELECT MIN(SCOST) FROM SOFTWARE)

    Output:TITLE SCOST-------------------- ---------DEAD LEE 99.92

    20) Who developed the package, which has sold the LEAST number of copies?

    SELECT NAME,SOLDFROM SOFTWAREWHERE SOLD = (SELECT MIN(SOLD) FROM SOFTWARE)

    Output:NAME SOLD-------- ---------

    [email protected] Page 37 of 49

  • 8/2/2019 3609961 SQL Queries

    38/49

    Gopal Prasad Patel

    JULIANA 0

    21) Which language was used to develop the package WHICH has the HIGEST sales amount?SELECT DEV_IN,SCOSTFROM SOFTWAREWHERE SCOST = (SELECT MAX(SCOST) FROM SOFTWARE)

    Output:DEV_IN SCOST-------- ---------ORACLE 18000

    22) How many copies of the package that has the LEAST DIFFRENCE between developmentand selling cost were sold?

    SELECT SOLD,TITLEFROM SOFTWAREWHERE TITLE = (SELECT TITLEFROM SOFTWARE

    WHERE (DCOST-SCOST)=(SELECT MIN(DCOST-SCOST) FROM SOFTWARE))

    Output:SOLD TITLE---- --------------------15 QUIZ MASTER

    23) Which is the COSTLIEAST package developed in PASCAL?

    SELECT TITLEFROM SOFTWAREWHERE DCOST = (SELECT MAX(DCOST)FROM SOFTWARE

    WHERE DEV_IN LIKE 'PASCAL')

    Output:TITLE--------------------HOTEL MANAGEMENT

    24) Which language was used to develop the MOST NUMBER of package?

    SELECT DEV_IN FROM SOFTWAREGROUP BY DEV_INHAVING MAX(DEV_IN) = (SELECT MAX(DEV_IN) FROM SOFTWARE)

    Output:DEV_IN--------PASCAL

    25) Which programmer has developed the HIGEST NUMBER of package?

    SELECT NAME FROM SOFTWAREGROUP BY NAME

    [email protected] Page 38 of 49

  • 8/2/2019 3609961 SQL Queries

    39/49

    Gopal Prasad Patel

    HAVING MAX(NAME) = (SELECT MAX(NAME) FROM SOFTWARE)

    Output:NAME--------VIJAYA

    26) Who is the author of the COSTLIEST package?

    SELECT NAME,DCOSTFROM SOFTWAREWHERE DCOST = (SELECT MAX(DCOST) FROM SOFTWARE)

    Output:NAME DCOST-------- ---------

    MARY 85000

    27) Display names of packages WHICH have been sold LESS THAN the AVERAGE number ofcopies?

    SELECT TITLEFROM SOFTWAREWHERE SOLD < (SELECT AVG(SOLD) FROM SOFTWARE)

    Output:TITLE--------------------VIDEO TITLING PACK

    SERIAL LINK UTILITYSHARES MANAGMENTINVENTORY CONTROLPAYROLL PACKAGEFINANCILA ACC S/WCODE GENERATORGRAPHIC EDITORVACCINESHOTEL MANAGEMENTTSR HELP PACKAGEHOTEL MANAGEMENTQUIZ MASTERISK EDITOR

    28) Who are the female programmers earning MORE than the HIGEST paid male programmers?

    SELECT NAMEFROM PROGRAMMERWHERE SEX LIKE 'F'

    AND SALARY > (SELECT(MAX(SALARY))FROM PROGRAMMERWHERE SEX LIKE 'M')

    [email protected] Page 39 of 49

  • 8/2/2019 3609961 SQL Queries

    40/49

    Gopal Prasad Patel

    Output:NAME--------MARY

    29) Which language has been stated as prof1 by MOST of the programmers?

    SELECT PROF1FROM PROGRAMMERGROUP BY PROF1HAVING PROF1 = (SELECT MAX(PROF1)FROM PROGRAMMER)

    Output:PROF1--------PASCAL

    30) Who are the authors of packages, WHICH have recovered MORE THAN double thedevelopment cost?

    SELECT NAME distinctFROM SOFTWAREWHERE SOLD*SCOST > 2*DCOST

    Output:NAME--------

    ANAND

    JAGDESHKAMALAMARYQADIRREMITHAREVATHIVIJAYA

    31) Display programmer names and CHEAPEST package developed by them in EACHlanguage?

    SELECT NAME,TITLEFROM SOFTWARE

    WHERE DCOST IN (SELECT MIN(DCOST)FROM SOFTWAREGROUP BY DEV_IN)

    Output:NAME TITLE-------- --------------------QADIR BOMBOS AWAYVIJAYA ISK EDITOR

    [email protected] Page 40 of 49

  • 8/2/2019 3609961 SQL Queries

    41/49

    Gopal Prasad Patel

    MARY READ MEREVATHI QUIZ MASTERJULIANA INVENTORY CONTROLRAMESH DEAD LEEJAGADESH SERIAL LINK UTILITYJAGDESH SHARES MANAGMENTKAMALA PAYROLL PACKAGEMARY CODE GENERATOR

    32) Who is the YOUNGEST male programmer born in 1965?

    SELECT NAMEFROM PROGRAMMERWHERE DOB=(SELECT (MAX(DOB))

    FROM PROGRAMMERWHERE TO_CHAR(DOB,'YYYY') LIKE '1965')

    Output:NAME--------

    VIJAYA

    33) Display language used by EACH programmer to develop the HIGEST selling and LOWEST

    selling package.

    SELECT NAME, DEV_INFROM SOFTWAREWHERE SOLD IN (SELECT MAX(SOLD)FROM SOFTWAREGROUP BY NAME)

    UNIONSELECT NAME, DEV_INFROM SOFTWAREWHERE SOLD IN (SELECT MIN(SOLD)FROM SOFTWAREGROUP BY NAME)

    Output:NAME DEV_IN-------- --------

    ANAND BASIC ANAND PASCALJAGADESH JAVAJAGDESH ORACLEJULIANA COBOL

    [email protected] Page 41 of 49

  • 8/2/2019 3609961 SQL Queries

    42/49

    Gopal Prasad Patel

    KAMALA DBASEMARY C++MARY ORACLEPATRICK PASCALQADIR ASSEMBLYQADIR CRAMESH DBASERAMESH PASCALREMITHA ASSEMBLYREMITHA CREVATHI BASICREVATHI PASCALVIJAYA C

    34) Who is the OLDEST female programmer WHO joined in 1992

    SELECT NAMEFROM PROGRAMMERWHERE DOJ=(SELECT (MIN(DOJ))

    FROM PROGRAMMER

    WHERE TO_CHAR(DOJ,'YYYY') LIKE '1992')

    Output:NAME--------KAMALAREVATHI

    35) In WHICH year where the MOST NUMBER of programmer born?

    SELECT DISTINCT TO_CHAR(DOB,'YYYY')FROM PROGRAMMERWHERE TO_CHAR(DOJ,'YYYY') = (SELECT MIN(TO_CHAR(DOJ,'YYYY'))

    FROM PROGRAMMER)

    Output:TO_C----1965

    36) In WHICH month did MOST NUMBRER of programmer join?

    SELECT DISTINCT TO_CHAR(DOJ,'MONTH')

    FROM PROGRAMMERWHERE TO_CHAR(DOJ,'MON') = (SELECT MIN(TO_CHAR(DOJ,'MON'))FROM PROGRAMMER)

    Output:TO_CHAR(D---------

    APRIL

    [email protected] Page 42 of 49

  • 8/2/2019 3609961 SQL Queries

    43/49

    Gopal Prasad Patel

    37) In WHICH language are MOST of the programmer's proficient?

    SELECT PROF1FROM PROGRAMMERGROUP BY PROF1HAVING COUNT(PROF1)=(SELECT MAX(COUNT(PROF1))FROM PROGRAMMERGROUP BY PROF1)

    OR COUNT(PROF2)=(SELECT MAX(COUNT(PROF2))FROM PROGRAMMERGROUP BY PROF2)

    UNIONSELECT PROF2FROM PROGRAMMERGROUP BY PROF2HAVING COUNT(PROF1)=(SELECT MAX(COUNT(PROF1))FROM PROGRAMMERGROUP BY PROF1)

    OR COUNT(PROF2)=(SELECT MAX(COUNT(PROF2))FROM PROGRAMMER

    GROUP BY PROF2)

    Output:PROF1--------DBASEPASCAL

    38) Who are the male programmers earning BELOW the AVERAGE salary of femaleprogrammers?

    SELECT NAMEFROM PROGRAMMER

    WHERE SEX LIKE 'M'AND SALARY < (SELECT(AVG(SALARY))

    FROM PROGRAMMERWHERE SEX LIKE 'F')

    Output:NAME--------

    ANANDALTAFNELSONPATRICKDADIR

    RAMESH

    QUERY - IV

    1) Display the details of THOSE WHO are drawing the same salary.

    [email protected] Page 43 of 49

  • 8/2/2019 3609961 SQL Queries

    44/49

    Gopal Prasad Patel

    select a.name,a.salaryfrom programmer a,programmer bwhere a.salary=b.salary and a.name b.name

    OR

    select name, salary from programmer wheresalary = any(select salary from programmer p group by salary havingsalary=p.salary and count(*)>1)

    2) Display the details of software developed by male programmers earing MORE than 3000.select software.*from programmer p,software swhere p.name=s.name and salary>3000 and sex='m';

    3) Display details of packages developed in PASCAL by female programmers.select s.*from programmer p,software swhere p.name=s.name and sex='f' and dev_in='pascal';

    4) Display the details of these programmer WHO joined BEFORE 1990.select *from programmerwhere to_char(doj,'yy')

  • 8/2/2019 3609961 SQL Queries

    45/49

    Gopal Prasad Patel

    from programmer p,software swhere s.name=p.name and sex='m' and to_char(dob,'yy')75);

    9) Display the details of the software that was developed in the language that is NOT theprogrammers first proficiency.

    select *from softwarewhere dev_in in(select unique(prof2)from programmerwhere prof2 not in(select prof1

    from programmer));or

    select distinct x.* from software x, programmer ywhere y.prof1 x.dev_inand x.name = y.name

    10) Display details of software that was developed in the language which is NITHER first NORsecond proficiency of the programmer.

    select s.*from programmer p,software s

    where s.name=p.name and (dev_in prof1 and dev_in prof2);

    11) Display details of software developed by male students of SABHARI.select s.*from programmer p,software s,studies stwhere p.name=s.name and s.name=st.name and sex='m' and splace='sabhari';

    12) Display the names of programmers WHO HAVE NOT developed any package.select name

    from programmerwhere name not in(select namefrom software);

    or

    select distinct name from programmer minusselect distinct name from software;

    13) What is the total cost of the software developed by the programmers by APPLE?select sum(scost)from software s,studies stwhere s.name=st.name and splace='apple';

    or

    select sum(x.scost) from software x, studies y wherex.name=y.namegroup by y.splacehavingy.splace = 'APPLE'

    14) Who are the programmers WHO JOINED in the same day?select a.name,a.doj

    [email protected] Page 45 of 49

  • 8/2/2019 3609961 SQL Queries

    46/49

    Gopal Prasad Patel

    from programmer a,programmer bwhere a.doj=b.doj and a.name b.name;

    or

    select name from programmer where to_char(doj,'dd')=any(select to_char(doj,'dd') from programmergroup byto_Char(doj,'dd')havingcount(*)>1)

    15) Who are the programmers WHO HAVE THE SAME PROF2?select unique(a.name),a.prof2from programmer a,programmer bwhere a.prof2=b.prof2 and a.name b.name;

    or

    select name from programmer where prof2 = any(

    select prof2 from programmer group by prof2 having count(*) >1);

    16) Display the total sales values of software, institutes-wise.select studies.splace,sum(software.sold*software.scost)from software,studieswhere studies.name=software.name group by studies.splace;

    17) In which institutes did the person who developed the COSTLIEST package study?select splacefrom software st,studies swhere s.name=st.name group by splace,dcost having max(dcost)=(select max(dcost)

    from software);

    or

    select x.splace from studies x, software y wherey.scost = ( select max(y.scost) from software y) andx.name=y.name;

    18) Which language listed in prof1 and prof2 HAS NOT BEEN used to develop any package?select prof1from programmerwhere prof1 not in(select dev_in

    from software) unionselect prof2

    from programmerwhere prof2 not in(select dev_in from software);or

    (select distinct prof1 from prgrammer unionselect distinct prof2 from programmer) minusselect distinct dev_in from software;

    [email protected] Page 46 of 49

  • 8/2/2019 3609961 SQL Queries

    47/49

    Gopal Prasad Patel

    19) How much does the person WHO developed the HIGHEST selling package earn and WHATcourse did he/she undergo?

    select p1.salary,s2.coursefrom programmer p1,software s1,studies s2where p1.name=s1.name and s1.name=s2.name and scost=(selectmax(scost) from software);

    20) How many months will it take for each programmer to recover the cost of the courseunderwent?

    select p.name,ceil(ccost/salary)from programmer p,studies s

    where s.name=p.name;

    21) Which is the COSTLIEST package developed by a person with under 3 years expenence?select dev_infrom programmer p,software swhere p.name=s.name and dcost= (select max(software.dcost)

    from programmer p, software swhere p.name=s.name and to_char(round(((sysdate-

    doj)/365)+100)) 3 andx.name=y.name;

    22) What is the AVERAGE salary for those WHOSE software's sales value is more than 50,000?select avg(salary)from programmer p,software swhere p .name=s.name and sold*scost>50000;

    23) How many packages were developed by the students WHO studied in the institute thatCharge the LOWEST course fee?

    select count(s.name)from software s,studies st

    where s.name=st.name group by s.name,ccost having min(ccost)=(select min(ccost) fromstudies);

    24) How many packages were developed by the person WHO developed the CHEAPESTpackage. Where did he\she study?

    select count(*)from programmer p,software s

    where s .name=p.name group by dev_in having min(dcost)=(select min(dcost) from software);

    25) How many packages were developed by female programmers earning MORE than theHIGHEST paid male programmer?

    select count(dev_in)from programmer p,software s

    where s.name=p.name and sex='f' and salary>(select max(salary)from programmer p,software swhere s.name=p.name and sex='m');

    [email protected] Page 47 of 49

  • 8/2/2019 3609961 SQL Queries

    48/49

    Gopal Prasad Patel

    26) How many packages were developed by the MOST experienced programmers from BDPS.select count(*)from software s,programmer p

    where p.name=s.name group by doj having max(doj)=(select max(doj)from studies st,programmer p, software s

    where p.name=s.name and st.name=p.name and (splace='bdps'));

    or

    select count(x.name) from software x, programmer y, studies x wheremonths_between(sysdate, y.doj)/12) = (select max(months_between(sysdate,y.doj)/12)from programmer y, studies = wherex.splace = 'BDPS' and y.name = z.name) andx.name=y.name andz.splace='BDPS'

    27) List the programmers (from software table) and institutes they studied, including those WHODIDN'T develop any package.

    select name,splace

    from studieswhere name not in(select name

    from software);or

    (select distinct x.name, z.splace from programmer x, software y, studies z wherex.name not in (select y.name from software y) andx.name = z.name) union(select distinct y.name, z.splace fromsoftware y, studies z where y.name=z.name);

    28) List each profit with the number of programmers having that prof1 and the number of

    packages developed in that prof1.select count(*),sum(scost*sold-dcost) "PROFIT"from softwarewhere dev_in in (select prof1

    from programmer) group by dev_in;

    29) List programmer names (from programmer table) and number of packages EACH developed.select s.name,count(dev_in)from programmer p1,software swhere p1.name=s.name group by s.name;

    or

    select programmer name, count(title) from programmer , software

    whereprogrammer name = software.name(+)group by programmer.name;

    30) List all the details of programmers who has done a course at S.S.I.L.select programmer.*from programmer,studies

    [email protected] Page 48 of 49

  • 8/2/2019 3609961 SQL Queries

    49/49

    Gopal Prasad Patel

    where splace='SSIL' and programmer.name=software.name andprogrammer.name=studies.name and studies.splace='s.s.i.l.';