SQL_Queries - Notepad

Embed Size (px)

Citation preview

  • 8/12/2019 SQL_Queries - Notepad

    1/92

    SQL_QueriesSQL_QueriesSQL_QueriesSQL_QueriesQueries solved by Somdutt Ganguly PQueries solved by Somdutt Ganguly PQueries solved by Somdutt Ganguly PQueries solved by Somdutt Ganguly Papril - 2002 (document printed)april - 2002 (document printed)april - 2002 (document printed)april - 2002 (document printed)email: [email protected]: [email protected]: [email protected]: [email protected]

    about me: i am right now a student of TYabout me: i am right now a student of TYabout me: i am right now a student of TYabout me: i am right now a student of TYBachelor in Computer applicationBachelor in Computer applicationBachelor in Computer applicationBachelor in Computer applicationfrom cpica college, Gujarat University,from cpica college, Gujarat University,from cpica college, Gujarat University,from cpica college, Gujarat University,Ahmedabad, Gujarat,Ahmedabad, Gujarat,Ahmedabad, Gujarat,Ahmedabad, Gujarat,India..India..India..India..

    address: no 6, chandrodaya apt,address: no 6, chandrodaya apt,address: no 6, chandrodaya apt,address: no 6, chandrodaya apt,bhaikaka nagar, thaltej, ahemdabad, gujarat,bhaikaka nagar, thaltej, ahemdabad, gujarat,bhaikaka nagar, thaltej, ahemdabad, gujarat,bhaikaka nagar, thaltej, ahemdabad, gujarat,

    india.india.india.india.'The following are the most twisted 150'The following are the most twisted 150'The following are the most twisted 150'The following are the most twisted 150queries given to us inqueries given to us inqueries given to us inqueries given to us in'our college......i think it will be very much'our college......i think it will be very much'our college......i think it will be very much'our college......i think it will be very muchuseful and handy in caseuseful and handy in caseuseful and handy in caseuseful and handy in case'when u can't solve these'when u can't solve these'when u can't solve these'when u can't solve thesequeries.....offcourse!! it took to bit ofqueries.....offcourse!! it took to bit ofqueries.....offcourse!! it took to bit ofqueries.....offcourse!! it took to bit ofbrainbrainbrainbrain

    'to solve these...(may be one or 2 or 3 are'to solve these...(may be one or 2 or 3 are'to solve these...(may be one or 2 or 3 are'to solve these...(may be one or 2 or 3 aredoubtful!! but will work...sometimesdoubtful!! but will work...sometimesdoubtful!! but will work...sometimesdoubtful!! but will work...sometimes'different answers will come up if u r working'different answers will come up if u r working'different answers will come up if u r working'different answers will come up if u r workingwith oracle on a network andwith oracle on a network andwith oracle on a network andwith oracle on a network and'on a personal edition......'on a personal edition......'on a personal edition......'on a personal edition......

    ....I welcome feedbacks..and do vote for my....I welcome feedbacks..and do vote for my....I welcome feedbacks..and do vote for my....I welcome feedbacks..and do vote for myhard work!!hard work!!hard work!!hard work!!

    TABLES:TABLES:TABLES:TABLES:

    1) Table name - programmer1) Table name - programmer1) Table name - programmer1) Table name - programmer

    Page 1Page 1Page 1Page 1

  • 8/12/2019 SQL_Queries - Notepad

    2/92

    SQL_QueriesSQL_QueriesSQL_QueriesSQL_Queriesname not null varchar2(8) namename not null varchar2(8) namename not null varchar2(8) namename not null varchar2(8) namedob not null date date of birthdob not null date date of birthdob not null date date of birthdob not null date date of birthdojdojdojdoj not null date date of joiningnot null date date of joiningnot null date date of joiningnot null date date of joining

    sex not null varchar2(1) male or femalesex not null varchar2(1) male or femalesex not null varchar2(1) male or femalesex not null varchar2(1) male or femaleprof1 varchar2(8) known language 1prof1 varchar2(8) known language 1prof1 varchar2(8) known language 1prof1 varchar2(8) known language 1prof2 varchar2(8) known language 2prof2 varchar2(8) known language 2prof2 varchar2(8) known language 2prof2 varchar2(8) known language 2salary not null number(4) salarysalary not null number(4) salarysalary not null number(4) salarysalary not null number(4) salary

    Entry eg:Entry eg:Entry eg:Entry eg:somdutt 21-apr-66 21-apr-92 m pascalsomdutt 21-apr-66 21-apr-92 m pascalsomdutt 21-apr-66 21-apr-92 m pascalsomdutt 21-apr-66 21-apr-92 m pascal

    basic 3200basic 3200basic 3200basic 3200

    2) Table name - software2) Table name - software2) Table name - software2) Table name - software

    name not null varchar2(8) namename not null varchar2(8) namename not null varchar2(8) namename not null varchar2(8) nametitle not null varchar2(20) developed projecttitle not null varchar2(20) developed projecttitle not null varchar2(20) developed projecttitle not null varchar2(20) developed projectnamenamenamenamedev_in not null varchar2(8) languagedev_in not null varchar2(8) languagedev_in not null varchar2(8) languagedev_in not null varchar2(8) language

    developeddevelopeddevelopeddevelopedscost number(7,2) software costscost number(7,2) software costscost number(7,2) software costscost number(7,2) software costdcost number(5) development costdcost number(5) development costdcost number(5) development costdcost number(5) development costsold number(3) number ofsold number(3) number ofsold number(3) number ofsold number(3) number ofsoftware soldsoftware soldsoftware soldsoftware sold

    Entry eg:Entry eg:Entry eg:Entry eg:

    somdutt parachutes basic 399.95 6000 43somdutt parachutes basic 399.95 6000 43somdutt parachutes basic 399.95 6000 43somdutt parachutes basic 399.95 6000 433) Table name - studies3) Table name - studies3) Table name - studies3) Table name - studies

    name not null varchar2(8) namename not null varchar2(8) namename not null varchar2(8) namename not null varchar2(8) namesplace not null varchar2(9) studies placesplace not null varchar2(9) studies placesplace not null varchar2(9) studies placesplace not null varchar2(9) studies place

    Page 2Page 2Page 2Page 2

  • 8/12/2019 SQL_Queries - Notepad

    3/92

    SQL_QueriesSQL_QueriesSQL_QueriesSQL_Queriescourse not null varchar2(5) course studiedcourse not null varchar2(5) course studiedcourse not null varchar2(5) course studiedcourse not null varchar2(5) course studiedccost not null number(5) course costccost not null number(5) course costccost not null number(5) course costccost not null number(5) course cost

    Entry example:Entry example:Entry example:Entry example:somdutt sabhari pgdca 4500somdutt sabhari pgdca 4500somdutt sabhari pgdca 4500somdutt sabhari pgdca 4500devdutt bdps dcs 5000devdutt bdps dcs 5000devdutt bdps dcs 5000devdutt bdps dcs 5000

    QUERIES - IQUERIES - IQUERIES - IQUERIES - I

    1) Find out the SELLING COST AVERAGE for the1) Find out the SELLING COST AVERAGE for the1) Find out the SELLING COST AVERAGE for the1) Find out the SELLING COST AVERAGE for the

    packages developed in PASCAL?packages developed in PASCAL?packages developed in PASCAL?packages developed in PASCAL?2) Display the names and ages of all2) Display the names and ages of all2) Display the names and ages of all2) Display the names and ages of allprogrammers.programmers.programmers.programmers.3) Display the names and ages of all the3) Display the names and ages of all the3) Display the names and ages of all the3) Display the names and ages of all theprogrammersprogrammersprogrammersprogrammers4) What is the highest numbers of copies sold4) What is the highest numbers of copies sold4) What is the highest numbers of copies sold4) What is the highest numbers of copies soldby a package?by a package?by a package?by a package?5) Display the names and date of birth of all5) Display the names and date of birth of all5) Display the names and date of birth of all5) Display the names and date of birth of allthe programmer born in JANUARY.the programmer born in JANUARY.the programmer born in JANUARY.the programmer born in JANUARY.

    6) Display lowest course fee.6) Display lowest course fee.6) Display lowest course fee.6) Display lowest course fee.7) How many programmer has done PGDCA course.7) How many programmer has done PGDCA course.7) How many programmer has done PGDCA course.7) How many programmer has done PGDCA course.8) How much revenue has been earned through8) How much revenue has been earned through8) How much revenue has been earned through8) How much revenue has been earned throughsales of packages in C.sales of packages in C.sales of packages in C.sales of packages in C.9) Display the details of software developed9) Display the details of software developed9) Display the details of software developed9) Display the details of software developedby Ramesh?by Ramesh?by Ramesh?by Ramesh?10) How many programmers studied at SABHARI.10) How many programmers studied at SABHARI.10) How many programmers studied at SABHARI.10) How many programmers studied at SABHARI.11) Display the details of PACKAGES whose11) Display the details of PACKAGES whose11) Display the details of PACKAGES whose11) Display the details of PACKAGES whose

    sales crossed the 20000 mark.sales crossed the 20000 mark.sales crossed the 20000 mark.sales crossed the 20000 mark.12) Find out the number of copies which should12) Find out the number of copies which should12) Find out the number of copies which should12) Find out the number of copies which shouldbe sold in order to recover the developmentbe sold in order to recover the developmentbe sold in order to recover the developmentbe sold in order to recover the developmentcost of each package.cost of each package.cost of each package.cost of each package.13) What is the price of the costliest13) What is the price of the costliest13) What is the price of the costliest13) What is the price of the costliestsoftware developed in BASIC?software developed in BASIC?software developed in BASIC?software developed in BASIC?

    Page 3Page 3Page 3Page 3

  • 8/12/2019 SQL_Queries - Notepad

    4/92

    SQL_QueriesSQL_QueriesSQL_QueriesSQL_Queries14) Display the details of packages for which14) Display the details of packages for which14) Display the details of packages for which14) Display the details of packages for whichdevelopment cost has been recovered.development cost has been recovered.development cost has been recovered.development cost has been recovered.15) How many packages were developed in dbase?15) How many packages were developed in dbase?15) How many packages were developed in dbase?15) How many packages were developed in dbase?

    16) How many programmers studies at paragathi?16) How many programmers studies at paragathi?16) How many programmers studies at paragathi?16) How many programmers studies at paragathi?17) How many programmers paid 5000 to 1000017) How many programmers paid 5000 to 1000017) How many programmers paid 5000 to 1000017) How many programmers paid 5000 to 10000for their course?for their course?for their course?for their course?18) What is the average course fee?18) What is the average course fee?18) What is the average course fee?18) What is the average course fee?19) Display the details of programmers knowing19) Display the details of programmers knowing19) Display the details of programmers knowing19) Display the details of programmers knowingc?c?c?c?20) How many programmers know either Cobol or20) How many programmers know either Cobol or20) How many programmers know either Cobol or20) How many programmers know either Cobol orPascal?Pascal?Pascal?Pascal?

    21) How many programmers don't know Pascal &21) How many programmers don't know Pascal &21) How many programmers don't know Pascal &21) How many programmers don't know Pascal &C?C?C?C?22) How old is the oldest male programmers?22) How old is the oldest male programmers?22) How old is the oldest male programmers?22) How old is the oldest male programmers?23) What is the average age of female23) What is the average age of female23) What is the average age of female23) What is the average age of femaleprogrammers?programmers?programmers?programmers?24) Calculate the experience in years for each24) Calculate the experience in years for each24) Calculate the experience in years for each24) Calculate the experience in years for eachprogrammers and display along with the namesprogrammers and display along with the namesprogrammers and display along with the namesprogrammers and display along with the namesin descending order?in descending order?in descending order?in descending order?25) Who are the programmers who celebrate25) Who are the programmers who celebrate25) Who are the programmers who celebrate25) Who are the programmers who celebrate

    their birthday during the current month?their birthday during the current month?their birthday during the current month?their birthday during the current month?26) How many female programmers are there?26) How many female programmers are there?26) How many female programmers are there?26) How many female programmers are there?27) What are the languages known by the male27) What are the languages known by the male27) What are the languages known by the male27) What are the languages known by the maleprogrammers?programmers?programmers?programmers?28) What is the Average salary?28) What is the Average salary?28) What is the Average salary?28) What is the Average salary?29) How many people draw 2000 to 4000?29) How many people draw 2000 to 4000?29) How many people draw 2000 to 4000?29) How many people draw 2000 to 4000?30) Display the details of those who don't30) Display the details of those who don't30) Display the details of those who don't30) Display the details of those who don'tknow Clipper, Cobol or Pascal?know Clipper, Cobol or Pascal?know Clipper, Cobol or Pascal?know Clipper, Cobol or Pascal?

    31) How many Female programmers knowing C are31) How many Female programmers knowing C are31) How many Female programmers knowing C are31) How many Female programmers knowing C areabove 24 years of age?above 24 years of age?above 24 years of age?above 24 years of age?32) Who are the programmers who will be32) Who are the programmers who will be32) Who are the programmers who will be32) Who are the programmers who will becelebrating their Birthday within a week?celebrating their Birthday within a week?celebrating their Birthday within a week?celebrating their Birthday within a week?33 Display the details of those with less than33 Display the details of those with less than33 Display the details of those with less than33 Display the details of those with less thana year's experience?a year's experience?a year's experience?a year's experience?

    Page 4Page 4Page 4Page 4

  • 8/12/2019 SQL_Queries - Notepad

    5/92

    SQL_QueriesSQL_QueriesSQL_QueriesSQL_Queries34 Display the details of those who will be34 Display the details of those who will be34 Display the details of those who will be34 Display the details of those who will becompleting 2 years of service this year?completing 2 years of service this year?completing 2 years of service this year?completing 2 years of service this year?35 Calculate the amount to be recovered for35 Calculate the amount to be recovered for35 Calculate the amount to be recovered for35 Calculate the amount to be recovered for

    those packages whose development cost has notthose packages whose development cost has notthose packages whose development cost has notthose packages whose development cost has notbeen recovered?been recovered?been recovered?been recovered?36)ist the packages which have not been sold36)ist the packages which have not been sold36)ist the packages which have not been sold36)ist the packages which have not been soldso far?so far?so far?so far?37) Find out the cost of the software37) Find out the cost of the software37) Find out the cost of the software37) Find out the cost of the softwaredeveloped by Mary?developed by Mary?developed by Mary?developed by Mary?38) Display the institutes names from the38) Display the institutes names from the38) Display the institutes names from the38) Display the institutes names from thestudies table without duplicates?studies table without duplicates?studies table without duplicates?studies table without duplicates?

    39) How many different courses are mentioned39) How many different courses are mentioned39) How many different courses are mentioned39) How many different courses are mentionedin the studies table?in the studies table?in the studies table?in the studies table?40) Display the names of the programmers whose40) Display the names of the programmers whose40) Display the names of the programmers whose40) Display the names of the programmers whosenames contain 2 occurrences of the letter A?names contain 2 occurrences of the letter A?names contain 2 occurrences of the letter A?names contain 2 occurrences of the letter A?41) Display the names of programmers whose41) Display the names of programmers whose41) Display the names of programmers whose41) Display the names of programmers whosenames contain unto 5 characters?names contain unto 5 characters?names contain unto 5 characters?names contain unto 5 characters?42) How many female programmers knowing COBOL42) How many female programmers knowing COBOL42) How many female programmers knowing COBOL42) How many female programmers knowing COBOLhave more than 2 years experience?have more than 2 years experience?have more than 2 years experience?have more than 2 years experience?43) What is the length of the shortest name in43) What is the length of the shortest name in43) What is the length of the shortest name in43) What is the length of the shortest name in

    the programmer table?the programmer table?the programmer table?the programmer table?44) What is the average development cost of a44) What is the average development cost of a44) What is the average development cost of a44) What is the average development cost of apackage developed in COBOL?package developed in COBOL?package developed in COBOL?package developed in COBOL?45) Display the name,sex,dob(DD/MM/YY format),45) Display the name,sex,dob(DD/MM/YY format),45) Display the name,sex,dob(DD/MM/YY format),45) Display the name,sex,dob(DD/MM/YY format),doj for all the programmers without usingdoj for all the programmers without usingdoj for all the programmers without usingdoj for all the programmers without usingconversion function?conversion function?conversion function?conversion function?46) Who are the programmers who were born on46) Who are the programmers who were born on46) Who are the programmers who were born on46) Who are the programmers who were born onthe last day of the month?the last day of the month?the last day of the month?the last day of the month?

    47) What is the amount paid in salaries of the47) What is the amount paid in salaries of the47) What is the amount paid in salaries of the47) What is the amount paid in salaries of themale programmers who do not know Cobol?male programmers who do not know Cobol?male programmers who do not know Cobol?male programmers who do not know Cobol?48) Display the title, scost, dcost and48) Display the title, scost, dcost and48) Display the title, scost, dcost and48) Display the title, scost, dcost anddifference between scost and dcost indifference between scost and dcost indifference between scost and dcost indifference between scost and dcost indescending order of difference?descending order of difference?descending order of difference?descending order of difference?49) Display the name, dob, doj of those month49) Display the name, dob, doj of those month49) Display the name, dob, doj of those month49) Display the name, dob, doj of those month

    Page 5Page 5Page 5Page 5

  • 8/12/2019 SQL_Queries - Notepad

    6/92

    SQL_QueriesSQL_QueriesSQL_QueriesSQL_Queriesof birth and month of joining are same?of birth and month of joining are same?of birth and month of joining are same?of birth and month of joining are same?50) Display the names of the packages whose50) Display the names of the packages whose50) Display the names of the packages whose50) Display the names of the packages whosenames contain more than 1 word?names contain more than 1 word?names contain more than 1 word?names contain more than 1 word?

    QUERIES - IIQUERIES - IIQUERIES - IIQUERIES - II

    1) Display THE NUMBER OF packages developed in1) Display THE NUMBER OF packages developed in1) Display THE NUMBER OF packages developed in1) Display THE NUMBER OF packages developed inEACH language.EACH language.EACH language.EACH language.2) Display THE NUMBER OF packages developed by2) Display THE NUMBER OF packages developed by2) Display THE NUMBER OF packages developed by2) Display THE NUMBER OF packages developed by

    EACH person.EACH person.EACH person.EACH person.3) Display THE NUMBER OF male and female3) Display THE NUMBER OF male and female3) Display THE NUMBER OF male and female3) Display THE NUMBER OF male and femaleprogrammer.programmer.programmer.programmer.4) Display THE COSTLIEST packages and HIGEST4) Display THE COSTLIEST packages and HIGEST4) Display THE COSTLIEST packages and HIGEST4) Display THE COSTLIEST packages and HIGESTselling developed in EACH language.selling developed in EACH language.selling developed in EACH language.selling developed in EACH language.5) Display THE NUMBER OF people BORN in EACH5) Display THE NUMBER OF people BORN in EACH5) Display THE NUMBER OF people BORN in EACH5) Display THE NUMBER OF people BORN in EACHYEAR.YEAR.YEAR.YEAR.6) Display THE NUMBER OF people JOINED in EACH6) Display THE NUMBER OF people JOINED in EACH6) Display THE NUMBER OF people JOINED in EACH6) Display THE NUMBER OF people JOINED in EACHYEAR.YEAR.YEAR.YEAR.

    7) Display THE NUMBER OF people BORN in EACH7) Display THE NUMBER OF people BORN in EACH7) Display THE NUMBER OF people BORN in EACH7) Display THE NUMBER OF people BORN in EACHMONTH.MONTH.MONTH.MONTH.8) Display THE NUMBER OF people JOINED in EACH8) Display THE NUMBER OF people JOINED in EACH8) Display THE NUMBER OF people JOINED in EACH8) Display THE NUMBER OF people JOINED in EACHMONTH.MONTH.MONTH.MONTH.9) Display the language wise COUNTS of prof1.9) Display the language wise COUNTS of prof1.9) Display the language wise COUNTS of prof1.9) Display the language wise COUNTS of prof1.10) Display the language wise COUNTS of prof2.10) Display the language wise COUNTS of prof2.10) Display the language wise COUNTS of prof2.10) Display the language wise COUNTS of prof2.11) Display THE NUMBER OF people in EACH11) Display THE NUMBER OF people in EACH11) Display THE NUMBER OF people in EACH11) Display THE NUMBER OF people in EACHsalary group.salary group.salary group.salary group.

    12) Display THE NUMBER OF people who studied12) Display THE NUMBER OF people who studied12) Display THE NUMBER OF people who studied12) Display THE NUMBER OF people who studiedin EACH institute.in EACH institute.in EACH institute.in EACH institute.13) Display THE NUMBER OF people who studied13) Display THE NUMBER OF people who studied13) Display THE NUMBER OF people who studied13) Display THE NUMBER OF people who studiedin EACH course.in EACH course.in EACH course.in EACH course.14) Display the TOTAL development COST of the14) Display the TOTAL development COST of the14) Display the TOTAL development COST of the14) Display the TOTAL development COST of thepackages developed in EACH language.packages developed in EACH language.packages developed in EACH language.packages developed in EACH language.

    Page 6Page 6Page 6Page 6

  • 8/12/2019 SQL_Queries - Notepad

    7/92

    SQL_QueriesSQL_QueriesSQL_QueriesSQL_Queries15) Display the selling cost of the package15) Display the selling cost of the package15) Display the selling cost of the package15) Display the selling cost of the packagedeveloped in EACH language.developed in EACH language.developed in EACH language.developed in EACH language.16) Display the cost of the package developed16) Display the cost of the package developed16) Display the cost of the package developed16) Display the cost of the package developed

    by EACH programmer.by EACH programmer.by EACH programmer.by EACH programmer.17) Display the sales values of the package17) Display the sales values of the package17) Display the sales values of the package17) Display the sales values of the packagedeveloped in EACH programmer.developed in EACH programmer.developed in EACH programmer.developed in EACH programmer.18) Display the NUMBER of packages developed18) Display the NUMBER of packages developed18) Display the NUMBER of packages developed18) Display the NUMBER of packages developedby EACH programmer.by EACH programmer.by EACH programmer.by EACH programmer.19) Display the sales COST of packages19) Display the sales COST of packages19) Display the sales COST of packages19) Display the sales COST of packagesdeveloped by EACH programmer language wise.developed by EACH programmer language wise.developed by EACH programmer language wise.developed by EACH programmer language wise.20) Display EACH programmers name, costliest20) Display EACH programmers name, costliest20) Display EACH programmers name, costliest20) Display EACH programmers name, costliest

    package and cheapest packages developed bypackage and cheapest packages developed bypackage and cheapest packages developed bypackage and cheapest packages developed byHim/Her.Him/Her.Him/Her.Him/Her.21) Display EACH language name with AVERAGE21) Display EACH language name with AVERAGE21) Display EACH language name with AVERAGE21) Display EACH language name with AVERAGEdevelopment cost, AVERAGE cost, selling costdevelopment cost, AVERAGE cost, selling costdevelopment cost, AVERAGE cost, selling costdevelopment cost, AVERAGE cost, selling costand AVERAGE price per copy.and AVERAGE price per copy.and AVERAGE price per copy.and AVERAGE price per copy.22) Display EACH institute name with NUMBER of22) Display EACH institute name with NUMBER of22) Display EACH institute name with NUMBER of22) Display EACH institute name with NUMBER ofcourses, AVERAGE cost per course.courses, AVERAGE cost per course.courses, AVERAGE cost per course.courses, AVERAGE cost per course.23) Display EACH institute name with NUMBER of23) Display EACH institute name with NUMBER of23) Display EACH institute name with NUMBER of23) Display EACH institute name with NUMBER ofstudents.students.students.students.

    24) Display names of male and female24) Display names of male and female24) Display names of male and female24) Display names of male and femaleprogrammers.programmers.programmers.programmers.25) Display the programmer's name and their25) Display the programmer's name and their25) Display the programmer's name and their25) Display the programmer's name and theirpackages.packages.packages.packages.26) Display the NUMBER of packages in EACH26) Display the NUMBER of packages in EACH26) Display the NUMBER of packages in EACH26) Display the NUMBER of packages in EACHlanguage.language.language.language.27) Display the NUMBER of packages in EACH27) Display the NUMBER of packages in EACH27) Display the NUMBER of packages in EACH27) Display the NUMBER of packages in EACHlanguage for which development cost is lesslanguage for which development cost is lesslanguage for which development cost is lesslanguage for which development cost is less

    than 1000.than 1000.than 1000.than 1000.28) Display the AVERAGE difference BETWEEN28) Display the AVERAGE difference BETWEEN28) Display the AVERAGE difference BETWEEN28) Display the AVERAGE difference BETWEENscost and dcost for EACH language.scost and dcost for EACH language.scost and dcost for EACH language.scost and dcost for EACH language.29) Display the TOTAL scost, dcsot and amount29) Display the TOTAL scost, dcsot and amount29) Display the TOTAL scost, dcsot and amount29) Display the TOTAL scost, dcsot and amountTOBE recovered for EACH programmer for whoseTOBE recovered for EACH programmer for whoseTOBE recovered for EACH programmer for whoseTOBE recovered for EACH programmer for whosedcost HAS NOT YET BEEN recovered.dcost HAS NOT YET BEEN recovered.dcost HAS NOT YET BEEN recovered.dcost HAS NOT YET BEEN recovered.

    Page 7Page 7Page 7Page 7

  • 8/12/2019 SQL_Queries - Notepad

    8/92

    SQL_QueriesSQL_QueriesSQL_QueriesSQL_Queries30) Display highest, lowest and average30) Display highest, lowest and average30) Display highest, lowest and average30) Display highest, lowest and averagesalaries for THOSE earning MORE than 2000.salaries for THOSE earning MORE than 2000.salaries for THOSE earning MORE than 2000.salaries for THOSE earning MORE than 2000.

    QUERIES - IIIQUERIES - IIIQUERIES - IIIQUERIES - III

    1) Who is the highest paid C programmer?1) Who is the highest paid C programmer?1) Who is the highest paid C programmer?1) Who is the highest paid C programmer?2) Who is the highest paid female cobol2) Who is the highest paid female cobol2) Who is the highest paid female cobol2) Who is the highest paid female cobolprogrammer?programmer?programmer?programmer?3) Display the name of the HIGEST paid3) Display the name of the HIGEST paid3) Display the name of the HIGEST paid3) Display the name of the HIGEST paid

    programmer for EACH language (prof1)programmer for EACH language (prof1)programmer for EACH language (prof1)programmer for EACH language (prof1)4) Who is the LEAST experienced programmer?4) Who is the LEAST experienced programmer?4) Who is the LEAST experienced programmer?4) Who is the LEAST experienced programmer?5) Who is the MOST experienced programmer?5) Who is the MOST experienced programmer?5) Who is the MOST experienced programmer?5) Who is the MOST experienced programmer?6) Which language is known by ONLY ONE6) Which language is known by ONLY ONE6) Which language is known by ONLY ONE6) Which language is known by ONLY ONEprogrammer?programmer?programmer?programmer?7) Who is the YONGEST programmer knowing7) Who is the YONGEST programmer knowing7) Who is the YONGEST programmer knowing7) Who is the YONGEST programmer knowingDBASE?DBASE?DBASE?DBASE?8) Which institute has MOST NUMBER of8) Which institute has MOST NUMBER of8) Which institute has MOST NUMBER of8) Which institute has MOST NUMBER ofstudents?students?students?students?

    9) Who is the above programmer?9) Who is the above programmer?9) Who is the above programmer?9) Who is the above programmer?10) Which female programmer earns MORE than10) Which female programmer earns MORE than10) Which female programmer earns MORE than10) Which female programmer earns MORE than3000/- but DOES NOT know C, C++, Oracle or3000/- but DOES NOT know C, C++, Oracle or3000/- but DOES NOT know C, C++, Oracle or3000/- but DOES NOT know C, C++, Oracle orDbase?Dbase?Dbase?Dbase?11) Which is the COSTLIEST course?11) Which is the COSTLIEST course?11) Which is the COSTLIEST course?11) Which is the COSTLIEST course?12) Which course has been done by MOST of the12) Which course has been done by MOST of the12) Which course has been done by MOST of the12) Which course has been done by MOST of thestudents?students?students?students?13) Display name of the institute and course13) Display name of the institute and course13) Display name of the institute and course13) Display name of the institute and course

    Which has below AVERAGE course fee?Which has below AVERAGE course fee?Which has below AVERAGE course fee?Which has below AVERAGE course fee?14) Which institute conducts COSTLIEST course?14) Which institute conducts COSTLIEST course?14) Which institute conducts COSTLIEST course?14) Which institute conducts COSTLIEST course?15) Which course has below AVERAGE number of15) Which course has below AVERAGE number of15) Which course has below AVERAGE number of15) Which course has below AVERAGE number ofstudents?students?students?students?16) Which institute conducts the above course?16) Which institute conducts the above course?16) Which institute conducts the above course?16) Which institute conducts the above course?17) Display names of the course WHOSE fees are17) Display names of the course WHOSE fees are17) Display names of the course WHOSE fees are17) Display names of the course WHOSE fees are

    Page 8Page 8Page 8Page 8

  • 8/12/2019 SQL_Queries - Notepad

    9/92

    SQL_QueriesSQL_QueriesSQL_QueriesSQL_Querieswithin 1000(+ or -) of the AVERAGE fee.within 1000(+ or -) of the AVERAGE fee.within 1000(+ or -) of the AVERAGE fee.within 1000(+ or -) of the AVERAGE fee.18) Which package has the HIGEST development18) Which package has the HIGEST development18) Which package has the HIGEST development18) Which package has the HIGEST developmentcost?cost?cost?cost?

    19) Which package has the LOWEST selling cost?19) Which package has the LOWEST selling cost?19) Which package has the LOWEST selling cost?19) Which package has the LOWEST selling cost?20) Who developed the package, which has sold20) Who developed the package, which has sold20) Who developed the package, which has sold20) Who developed the package, which has soldthe LEAST number of copies?the LEAST number of copies?the LEAST number of copies?the LEAST number of copies?21) Which language was used to develop the21) Which language was used to develop the21) Which language was used to develop the21) Which language was used to develop thepackage WHICH has the HIGEST sales amount?package WHICH has the HIGEST sales amount?package WHICH has the HIGEST sales amount?package WHICH has the HIGEST sales amount?22) How many copies of the package that has22) How many copies of the package that has22) How many copies of the package that has22) How many copies of the package that hasthe LEAST DIFFRENCE between development andthe LEAST DIFFRENCE between development andthe LEAST DIFFRENCE between development andthe LEAST DIFFRENCE between development andselling cost were sold?selling cost were sold?selling cost were sold?selling cost were sold?

    23) Which is the COSTLIEAST package developed23) Which is the COSTLIEAST package developed23) Which is the COSTLIEAST package developed23) Which is the COSTLIEAST package developedin PASCAL?in PASCAL?in PASCAL?in PASCAL?24) Which language was used to develop the24) Which language was used to develop the24) Which language was used to develop the24) Which language was used to develop theMOST NUMBER of package?MOST NUMBER of package?MOST NUMBER of package?MOST NUMBER of package?25) Which programmer has developed the HIGEST25) Which programmer has developed the HIGEST25) Which programmer has developed the HIGEST25) Which programmer has developed the HIGESTNUMBER of package?NUMBER of package?NUMBER of package?NUMBER of package?26) Who is the author of the COSTLIEST26) Who is the author of the COSTLIEST26) Who is the author of the COSTLIEST26) Who is the author of the COSTLIESTpackage?package?package?package?27) Display names of packages WHICH have been27) Display names of packages WHICH have been27) Display names of packages WHICH have been27) Display names of packages WHICH have been

    sold LESS THAN the AVERAGE number of copies?sold LESS THAN the AVERAGE number of copies?sold LESS THAN the AVERAGE number of copies?sold LESS THAN the AVERAGE number of copies?28) Who are the female programmers earning28) Who are the female programmers earning28) Who are the female programmers earning28) Who are the female programmers earningMORE than the HIGEST paid male programmers?MORE than the HIGEST paid male programmers?MORE than the HIGEST paid male programmers?MORE than the HIGEST paid male programmers?29) Which language has been stated as prof1 by29) Which language has been stated as prof1 by29) Which language has been stated as prof1 by29) Which language has been stated as prof1 byMOST of the programmers?MOST of the programmers?MOST of the programmers?MOST of the programmers?30) Who are the authors of packages, WHICH30) Who are the authors of packages, WHICH30) Who are the authors of packages, WHICH30) Who are the authors of packages, WHICHhave recovered MORE THAN double thehave recovered MORE THAN double thehave recovered MORE THAN double thehave recovered MORE THAN double thedevelopment cost?development cost?development cost?development cost?

    31) Display programmer names and CHEAPEST31) Display programmer names and CHEAPEST31) Display programmer names and CHEAPEST31) Display programmer names and CHEAPESTpackage developed by them in EACH language?package developed by them in EACH language?package developed by them in EACH language?package developed by them in EACH language?32) Who is the YOUNGEST male programmer born32) Who is the YOUNGEST male programmer born32) Who is the YOUNGEST male programmer born32) Who is the YOUNGEST male programmer bornin 1965?in 1965?in 1965?in 1965?33) Display language used by EACH programmer33) Display language used by EACH programmer33) Display language used by EACH programmer33) Display language used by EACH programmerto develop the HIGEST selling and LOWESTto develop the HIGEST selling and LOWESTto develop the HIGEST selling and LOWESTto develop the HIGEST selling and LOWEST

    Page 9Page 9Page 9Page 9

  • 8/12/2019 SQL_Queries - Notepad

    10/92

    SQL_QueriesSQL_QueriesSQL_QueriesSQL_Queriesselling package.selling package.selling package.selling package.34) Who is the OLDEST female programmer WHO34) Who is the OLDEST female programmer WHO34) Who is the OLDEST female programmer WHO34) Who is the OLDEST female programmer WHOjoined in 1992joined in 1992joined in 1992joined in 1992

    35) In WHICH year where the MOST NUMBER of35) In WHICH year where the MOST NUMBER of35) In WHICH year where the MOST NUMBER of35) In WHICH year where the MOST NUMBER ofprogrammer born?programmer born?programmer born?programmer born?36) In WHICH month did MOST NUMBRER of36) In WHICH month did MOST NUMBRER of36) In WHICH month did MOST NUMBRER of36) In WHICH month did MOST NUMBRER ofprogrammer join?programmer join?programmer join?programmer join?37) In WHICH language are MOST of the37) In WHICH language are MOST of the37) In WHICH language are MOST of the37) In WHICH language are MOST of theprogrammer's proficient?programmer's proficient?programmer's proficient?programmer's proficient?38) Who are the male programmers earning BELOW38) Who are the male programmers earning BELOW38) Who are the male programmers earning BELOW38) Who are the male programmers earning BELOWthe AVERAGE salary of female programmers?the AVERAGE salary of female programmers?the AVERAGE salary of female programmers?the AVERAGE salary of female programmers?

    QUERY - IVQUERY - IVQUERY - IVQUERY - IV

    1) Display the details of THOSE WHO are1) Display the details of THOSE WHO are1) Display the details of THOSE WHO are1) Display the details of THOSE WHO aredrawing the same salary.drawing the same salary.drawing the same salary.drawing the same salary.2) Display the details of software developed2) Display the details of software developed2) Display the details of software developed2) Display the details of software developedby male programmers earing MORE than 3000.by male programmers earing MORE than 3000.by male programmers earing MORE than 3000.by male programmers earing MORE than 3000.3) Display details of packages developed in3) Display details of packages developed in3) Display details of packages developed in3) Display details of packages developed in

    PASCAL by female programmers.PASCAL by female programmers.PASCAL by female programmers.PASCAL by female programmers.4) Display the details of these programmer WHO4) Display the details of these programmer WHO4) Display the details of these programmer WHO4) Display the details of these programmer WHOjoined BEFORE 1990.joined BEFORE 1990.joined BEFORE 1990.joined BEFORE 1990.5)Display details of software developed in C5)Display details of software developed in C5)Display details of software developed in C5)Display details of software developed in Cby female programmers of PRAGATHI.by female programmers of PRAGATHI.by female programmers of PRAGATHI.by female programmers of PRAGATHI.6) Display NUMBER of packages NUMBER of copies6) Display NUMBER of packages NUMBER of copies6) Display NUMBER of packages NUMBER of copies6) Display NUMBER of packages NUMBER of copiessold and sales value of EACH programmersold and sales value of EACH programmersold and sales value of EACH programmersold and sales value of EACH programmerInstitute-wise.Institute-wise.Institute-wise.Institute-wise.

    7) Display details of software developed in7) Display details of software developed in7) Display details of software developed in7) Display details of software developed inDBASE by male programmers WHO belong to theDBASE by male programmers WHO belong to theDBASE by male programmers WHO belong to theDBASE by male programmers WHO belong to theinstitute on which MOST NUMBER OF programmersinstitute on which MOST NUMBER OF programmersinstitute on which MOST NUMBER OF programmersinstitute on which MOST NUMBER OF programmersstudies.studies.studies.studies.8) Display the details of the software that8) Display the details of the software that8) Display the details of the software that8) Display the details of the software thatwas developed by male programmers born BEFOREwas developed by male programmers born BEFOREwas developed by male programmers born BEFOREwas developed by male programmers born BEFORE

    Page 10Page 10Page 10Page 10

  • 8/12/2019 SQL_Queries - Notepad

    11/92

    SQL_QueriesSQL_QueriesSQL_QueriesSQL_Queries1965 and female programmers born AFTER 1975.1965 and female programmers born AFTER 1975.1965 and female programmers born AFTER 1975.1965 and female programmers born AFTER 1975.9) Display the details of the software that9) Display the details of the software that9) Display the details of the software that9) Display the details of the software thatwas developed in the language that is NOT thewas developed in the language that is NOT thewas developed in the language that is NOT thewas developed in the language that is NOT the

    programmers first proficiency.programmers first proficiency.programmers first proficiency.programmers first proficiency.10) Display details of software that was10) Display details of software that was10) Display details of software that was10) Display details of software that wasdeveloped in the language which is NITHERdeveloped in the language which is NITHERdeveloped in the language which is NITHERdeveloped in the language which is NITHERfirst NOR second proficiency of thefirst NOR second proficiency of thefirst NOR second proficiency of thefirst NOR second proficiency of theprogrammer.programmer.programmer.programmer.11) Display details of software developed by11) Display details of software developed by11) Display details of software developed by11) Display details of software developed bymale students of SABHARI.male students of SABHARI.male students of SABHARI.male students of SABHARI.12) Display the names of programmers WHO HAVE12) Display the names of programmers WHO HAVE12) Display the names of programmers WHO HAVE12) Display the names of programmers WHO HAVE

    NOT developed any package.NOT developed any package.NOT developed any package.NOT developed any package.13) What is the total cost of the software13) What is the total cost of the software13) What is the total cost of the software13) What is the total cost of the softwaredeveloped by the programmers by APPLE?developed by the programmers by APPLE?developed by the programmers by APPLE?developed by the programmers by APPLE?14) Who are the programmers WHO JOINED in the14) Who are the programmers WHO JOINED in the14) Who are the programmers WHO JOINED in the14) Who are the programmers WHO JOINED in thesame day?same day?same day?same day?15) Who are the programmers WHO HAVE THE SAME15) Who are the programmers WHO HAVE THE SAME15) Who are the programmers WHO HAVE THE SAME15) Who are the programmers WHO HAVE THE SAMEPROF2?PROF2?PROF2?PROF2?16) Display the total sales values of16) Display the total sales values of16) Display the total sales values of16) Display the total sales values ofsoftware, institutes-wise.software, institutes-wise.software, institutes-wise.software, institutes-wise.

    17) In which institutes did the person who17) In which institutes did the person who17) In which institutes did the person who17) In which institutes did the person whodeveloped the COSTLIEST package study?developed the COSTLIEST package study?developed the COSTLIEST package study?developed the COSTLIEST package study?18) Which language listed in prof1 and prof218) Which language listed in prof1 and prof218) Which language listed in prof1 and prof218) Which language listed in prof1 and prof2HAS NOT BEEN used to develop any package?HAS NOT BEEN used to develop any package?HAS NOT BEEN used to develop any package?HAS NOT BEEN used to develop any package?19) How much does the person WHO developed the19) How much does the person WHO developed the19) How much does the person WHO developed the19) How much does the person WHO developed theHIGHEST selling package earn and WHAT courseHIGHEST selling package earn and WHAT courseHIGHEST selling package earn and WHAT courseHIGHEST selling package earn and WHAT coursedid he/she undergo?did he/she undergo?did he/she undergo?did he/she undergo?20) How many months will it take for each20) How many months will it take for each20) How many months will it take for each20) How many months will it take for each

    programmer to recover the cost of the courseprogrammer to recover the cost of the courseprogrammer to recover the cost of the courseprogrammer to recover the cost of the courseunderwent?underwent?underwent?underwent?21) Which is the COSTLIEST package developed21) Which is the COSTLIEST package developed21) Which is the COSTLIEST package developed21) Which is the COSTLIEST package developedby a person with under 3 years expenence?by a person with under 3 years expenence?by a person with under 3 years expenence?by a person with under 3 years expenence?22) What is the AVERAGE salary for those WHOSE22) What is the AVERAGE salary for those WHOSE22) What is the AVERAGE salary for those WHOSE22) What is the AVERAGE salary for those WHOSEsoftware's sales value is more than 50,000?software's sales value is more than 50,000?software's sales value is more than 50,000?software's sales value is more than 50,000?

    Page 11Page 11Page 11Page 11

  • 8/12/2019 SQL_Queries - Notepad

    12/92

    SQL_QueriesSQL_QueriesSQL_QueriesSQL_Queries23) How many packages were developed by the23) How many packages were developed by the23) How many packages were developed by the23) How many packages were developed by thestudents WHO studied in the institute thatstudents WHO studied in the institute thatstudents WHO studied in the institute thatstudents WHO studied in the institute thatCharge the LOWEST course fee?Charge the LOWEST course fee?Charge the LOWEST course fee?Charge the LOWEST course fee?

    24) How many packages were developed by the24) How many packages were developed by the24) How many packages were developed by the24) How many packages were developed by theperson WHO developed the CHEAPEST package.person WHO developed the CHEAPEST package.person WHO developed the CHEAPEST package.person WHO developed the CHEAPEST package.Where did he\she study?Where did he\she study?Where did he\she study?Where did he\she study?25) How many packages were developed by female25) How many packages were developed by female25) How many packages were developed by female25) How many packages were developed by femaleprogrammers earning MORE than the HIGHESTprogrammers earning MORE than the HIGHESTprogrammers earning MORE than the HIGHESTprogrammers earning MORE than the HIGHESTpaid male programmer?paid male programmer?paid male programmer?paid male programmer?26) How many packages were developed by the26) How many packages were developed by the26) How many packages were developed by the26) How many packages were developed by theMOST experienced programmers from BDPS.MOST experienced programmers from BDPS.MOST experienced programmers from BDPS.MOST experienced programmers from BDPS.

    27) List the programmers (from software table)27) List the programmers (from software table)27) List the programmers (from software table)27) List the programmers (from software table)and institutes they studied, including thoseand institutes they studied, including thoseand institutes they studied, including thoseand institutes they studied, including thoseWHO DIDN'T develop any package.WHO DIDN'T develop any package.WHO DIDN'T develop any package.WHO DIDN'T develop any package.28) List each profit with the number of28) List each profit with the number of28) List each profit with the number of28) List each profit with the number ofprogrammers having that prof1 and the numberprogrammers having that prof1 and the numberprogrammers having that prof1 and the numberprogrammers having that prof1 and the numberof packages developed in that prof1.of packages developed in that prof1.of packages developed in that prof1.of packages developed in that prof1.29) List programmer names (from programmer29) List programmer names (from programmer29) List programmer names (from programmer29) List programmer names (from programmertable) and number of packages EACH developed.table) and number of packages EACH developed.table) and number of packages EACH developed.table) and number of packages EACH developed.30) List all the details of programmers who30) List all the details of programmers who30) List all the details of programmers who30) List all the details of programmers who

    has done a course at S.S.I.L.has done a course at S.S.I.L.has done a course at S.S.I.L.has done a course at S.S.I.L.

    QUERIES - IQUERIES - IQUERIES - IQUERIES - I

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

    SELECT AVG(SCOST)SELECT AVG(SCOST)SELECT AVG(SCOST)SELECT AVG(SCOST)FROM SOFTWAREFROM SOFTWAREFROM SOFTWAREFROM SOFTWAREWHERE DEV_IN LIKE 'PASCAL'WHERE DEV_IN LIKE 'PASCAL'WHERE DEV_IN LIKE 'PASCAL'WHERE DEV_IN LIKE 'PASCAL'

    Output:Output:Output:Output:Page 12Page 12Page 12Page 12

  • 8/12/2019 SQL_Queries - Notepad

    13/92

    SQL_QueriesSQL_QueriesSQL_QueriesSQL_QueriesAVG(SCOST)AVG(SCOST)AVG(SCOST)AVG(SCOST)---------------------------------------- 2362.48 2362.48 2362.48 2362.48

    2) Display the names and ages of all2) Display the names and ages of all2) Display the names and ages of all2) Display the names and ages of allprogrammers.programmers.programmers.programmers.

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

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

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

    ANAND 34ANAND 34ANAND 34ANAND 34ALTAF 36ALTAF 36ALTAF 36ALTAF 36JAGADESH 30JAGADESH 30JAGADESH 30JAGADESH 30JULIANA 32JULIANA 32JULIANA 32JULIANA 32KAMALA 32KAMALA 32KAMALA 32KAMALA 32MARY 30MARY 30MARY 30MARY 30NELSON 35NELSON 35NELSON 35NELSON 35PATRICK 35PATRICK 35PATRICK 35PATRICK 35

    QADIR 35QADIR 35QADIR 35QADIR 35RAMESH 33RAMESH 33RAMESH 33RAMESH 33REBECCA 33REBECCA 33REBECCA 33REBECCA 33REMITHA 30REMITHA 30REMITHA 30REMITHA 30REVATHI 31REVATHI 31REVATHI 31REVATHI 31VIJAYA 35VIJAYA 35VIJAYA 35VIJAYA 35

    Page 13Page 13Page 13Page 13

  • 8/12/2019 SQL_Queries - Notepad

    14/92

    SQL_QueriesSQL_QueriesSQL_QueriesSQL_Queries

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

    SELECT NAMESELECT NAMESELECT NAMESELECT NAMEFROM STUDIESFROM STUDIESFROM STUDIESFROM STUDIESWHERE COURSE LIKE 'DAP'WHERE COURSE LIKE 'DAP'WHERE COURSE LIKE 'DAP'WHERE COURSE LIKE 'DAP'

    Output:Output:Output:Output:NAMENAMENAMENAME--------------------------------

    NELSONNELSONNELSONNELSONREVATHIREVATHIREVATHIREVATHI

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

    SELECT MAX(SOLD) FROM SOFTWARESELECT MAX(SOLD) FROM SOFTWARESELECT MAX(SOLD) FROM SOFTWARESELECT MAX(SOLD) FROM SOFTWARE

    Output:Output:Output:Output:

    SOLD SOLD SOLD SOLD---------------------------------------- 114 114 114 114

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

    SELECT DOB,NAMESELECT DOB,NAMESELECT DOB,NAMESELECT DOB,NAMEFROM PROGRAMMERFROM PROGRAMMERFROM PROGRAMMERFROM PROGRAMMER

    Page 14Page 14Page 14Page 14

  • 8/12/2019 SQL_Queries - Notepad

    15/92

    SQL_QueriesSQL_QueriesSQL_QueriesSQL_QueriesWHERE TO_CHAR(DOB,'MON') LIKE 'JAN'WHERE TO_CHAR(DOB,'MON') LIKE 'JAN'WHERE TO_CHAR(DOB,'MON') LIKE 'JAN'WHERE TO_CHAR(DOB,'MON') LIKE 'JAN'

    Output:Output:Output:Output:

    DOB NAMEDOB NAMEDOB NAMEDOB NAME--------- ----------------- ----------------- ----------------- --------31-JAN-68 JULIANA31-JAN-68 JULIANA31-JAN-68 JULIANA31-JAN-68 JULIANA01-JAN-67 REBECCA01-JAN-67 REBECCA01-JAN-67 REBECCA01-JAN-67 REBECCA

    6) Display lowest course fee.6) Display lowest course fee.6) Display lowest course fee.6) Display lowest course fee.

    SELECT MIN(CCOST) FROM STUDIESSELECT MIN(CCOST) FROM STUDIESSELECT MIN(CCOST) FROM STUDIESSELECT MIN(CCOST) FROM STUDIES

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

    7) How many programmer has done PGDCA course.7) How many programmer has done PGDCA course.7) How many programmer has done PGDCA course.7) How many programmer has done PGDCA course.

    SELECT COUNT(NAME)SELECT COUNT(NAME)SELECT COUNT(NAME)SELECT COUNT(NAME)

    FROM STUDIESFROM STUDIESFROM STUDIESFROM STUDIESWHERE COURSE LIKE 'PGDCA'WHERE COURSE LIKE 'PGDCA'WHERE COURSE LIKE 'PGDCA'WHERE COURSE LIKE 'PGDCA'

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

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

    SELECT SUM(SOLD*SCOST)SELECT SUM(SOLD*SCOST)SELECT SUM(SOLD*SCOST)SELECT SUM(SOLD*SCOST)FROM SOFTWAREFROM SOFTWAREFROM SOFTWAREFROM SOFTWAREWHERE DEV_IN LIKE 'C'WHERE DEV_IN LIKE 'C'WHERE DEV_IN LIKE 'C'WHERE DEV_IN LIKE 'C'

    Page 15Page 15Page 15Page 15

  • 8/12/2019 SQL_Queries - Notepad

    16/92

    SQL_QueriesSQL_QueriesSQL_QueriesSQL_Queries

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

    ------------------------------------------------------------ 113775 113775 113775 1137759) Display the details of software developed9) Display the details of software developed9) Display the details of software developed9) Display the details of software developedby Ramesh?by Ramesh?by Ramesh?by Ramesh?

    SELECT *SELECT *SELECT *SELECT *FROM SOFTWAREFROM SOFTWAREFROM SOFTWAREFROM SOFTWAREWHERE NAME='RAMESH'WHERE NAME='RAMESH'WHERE NAME='RAMESH'WHERE NAME='RAMESH'

    Output:Output:Output:Output:NAME TITLE DEV_INNAME TITLE DEV_INNAME TITLE DEV_INNAME TITLE DEV_INSCOST DCOST SOLDSCOST DCOST SOLDSCOST DCOST SOLDSCOST DCOST SOLD-------- -------------------- ---------------- -------------------- ---------------- -------------------- ---------------- -------------------- ------------------ ---------- -------------------- ---------- -------------------- ---------- -------------------- ---------- ----------RAMESH HOTEL MANAGEMENT DBASERAMESH HOTEL MANAGEMENT DBASERAMESH HOTEL MANAGEMENT DBASERAMESH HOTEL MANAGEMENT DBASE12000 35000 412000 35000 412000 35000 412000 35000 4RAMESH DEAD LEE PASCALRAMESH DEAD LEE PASCALRAMESH DEAD LEE PASCALRAMESH DEAD LEE PASCAL

    99.95 4500 7399.95 4500 7399.95 4500 7399.95 4500 73

    10) How many programmers studied at SABHARI.10) How many programmers studied at SABHARI.10) How many programmers studied at SABHARI.10) How many programmers studied at SABHARI.

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

    Output:Output:Output:Output:NOPROGRAMMERSNOPROGRAMMERSNOPROGRAMMERSNOPROGRAMMERS---------------------------------------------------- 4 4 4 4

    Page 16Page 16Page 16Page 16

  • 8/12/2019 SQL_Queries - Notepad

    17/92

    SQL_QueriesSQL_QueriesSQL_QueriesSQL_Queries11) Display the details of PACKAGES whose11) Display the details of PACKAGES whose11) Display the details of PACKAGES whose11) Display the details of PACKAGES whosesales crossed the 20000 mark.sales crossed the 20000 mark.sales crossed the 20000 mark.sales crossed the 20000 mark.

    SELECT *SELECT *SELECT *SELECT *FROM SOFTWAREFROM SOFTWAREFROM SOFTWAREFROM SOFTWAREWHERE (SOLD*SCOST)>20000WHERE (SOLD*SCOST)>20000WHERE (SOLD*SCOST)>20000WHERE (SOLD*SCOST)>20000

    Output:Output:Output:Output:NAME TITLE DEV_INNAME TITLE DEV_INNAME TITLE DEV_INNAME TITLE DEV_INSCOST DCOST SOLDSCOST DCOST SOLDSCOST DCOST SOLDSCOST DCOST SOLD-------- -------------------- ---------------- -------------------- ---------------- -------------------- ---------------- -------------------- --------

    ---------- ---------- -------------------- ---------- -------------------- ---------- -------------------- ---------- ----------ANAND VIDEO TITLING PACK PASCALANAND VIDEO TITLING PACK PASCALANAND VIDEO TITLING PACK PASCALANAND VIDEO TITLING PACK PASCAL7500 16000 97500 16000 97500 16000 97500 16000 9JAGADESH SHARES MANAGEMENT ORACLEJAGADESH SHARES MANAGEMENT ORACLEJAGADESH SHARES MANAGEMENT ORACLEJAGADESH SHARES MANAGEMENT ORACLE3000 12000 143000 12000 143000 12000 143000 12000 14KAMALA PAYROLL PACKAGE DBASEKAMALA PAYROLL PACKAGE DBASEKAMALA PAYROLL PACKAGE DBASEKAMALA PAYROLL PACKAGE DBASE9000 20000 79000 20000 79000 20000 79000 20000 7MARY FINANCILA ACC S/W ORACLEMARY FINANCILA ACC S/W ORACLEMARY FINANCILA ACC S/W ORACLEMARY FINANCILA ACC S/W ORACLE18000 85000 418000 85000 418000 85000 418000 85000 4

    MARY CODE GENERATOR CMARY CODE GENERATOR CMARY CODE GENERATOR CMARY CODE GENERATOR C4500 20000 234500 20000 234500 20000 234500 20000 23MARY READ ME C++MARY READ ME C++MARY READ ME C++MARY READ ME C++300 1200 84300 1200 84300 1200 84300 1200 84QADIR BOMBS AWAY ASSEMBLYQADIR BOMBS AWAY ASSEMBLYQADIR BOMBS AWAY ASSEMBLYQADIR BOMBS AWAY ASSEMBLY499.95 530 114499.95 530 114499.95 530 114499.95 530 114QADIR VACCINES CQADIR VACCINES CQADIR VACCINES CQADIR VACCINES C1900 3400 211900 3400 211900 3400 211900 3400 21

    RAMESH HOTEL MANAGEMENT DBASERAMESH HOTEL MANAGEMENT DBASERAMESH HOTEL MANAGEMENT DBASERAMESH HOTEL MANAGEMENT DBASE12000 35000 412000 35000 412000 35000 412000 35000 4REMITHA PC UTILITIES CREMITHA PC UTILITIES CREMITHA PC UTILITIES CREMITHA PC UTILITIES C725 5000 51725 5000 51725 5000 51725 5000 51REVATHI QUIZ MASTER BASICREVATHI QUIZ MASTER BASICREVATHI QUIZ MASTER BASICREVATHI QUIZ MASTER BASIC3200 2100 153200 2100 153200 2100 153200 2100 15

    Page 17Page 17Page 17Page 17

  • 8/12/2019 SQL_Queries - Notepad

    18/92

    SQL_QueriesSQL_QueriesSQL_QueriesSQL_Queries

    12) Find out the number of copies which should12) Find out the number of copies which should12) Find out the number of copies which should12) Find out the number of copies which shouldbe sold in order to recover the developmentbe sold in order to recover the developmentbe sold in order to recover the developmentbe sold in order to recover the development

    cost of each package.cost of each package.cost of each package.cost of each package.

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

  • 8/12/2019 SQL_Queries - Notepad

    19/92

    SQL_QueriesSQL_QueriesSQL_QueriesSQL_Queries

    14) Display the details of packages for which14) Display the details of packages for which14) Display the details of packages for which14) Display the details of packages for which

    development cost has been recovered.development cost has been recovered.development cost has been recovered.development cost has been recovered.SELECT *SELECT *SELECT *SELECT *FROM SOFTWAREFROM SOFTWAREFROM SOFTWAREFROM SOFTWAREWHERE (SOLD*SCOST)>DCOSTWHERE (SOLD*SCOST)>DCOSTWHERE (SOLD*SCOST)>DCOSTWHERE (SOLD*SCOST)>DCOST

    Output:Output:Output:Output:NAME TITLE DEV_INNAME TITLE DEV_INNAME TITLE DEV_INNAME TITLE DEV_INSCOST DCOST SOLDSCOST DCOST SOLDSCOST DCOST SOLDSCOST DCOST SOLD

    -------- -------------------- ---------------- -------------------- ---------------- -------------------- ---------------- -------------------- ------------------ ---------- -------------------- ---------- -------------------- ---------- -------------------- ---------- ----------ANAND PARACHUTES BASICANAND PARACHUTES BASICANAND PARACHUTES BASICANAND PARACHUTES BASIC399.95 6000 43399.95 6000 43399.95 6000 43399.95 6000 43ANAND VIDEO TITLING PACK PASCALANAND VIDEO TITLING PACK PASCALANAND VIDEO TITLING PACK PASCALANAND VIDEO TITLING PACK PASCAL7500 16000 97500 16000 97500 16000 97500 16000 9JAGADESH SERIAL LINK UTILITY JAVAJAGADESH SERIAL LINK UTILITY JAVAJAGADESH SERIAL LINK UTILITY JAVAJAGADESH SERIAL LINK UTILITY JAVA800 7500 10800 7500 10800 7500 10800 7500 10

    JAGADESH SHARES MANAGEMENT ORACLEJAGADESH SHARES MANAGEMENT ORACLEJAGADESH SHARES MANAGEMENT ORACLEJAGADESH SHARES MANAGEMENT ORACLE3000 12000 143000 12000 143000 12000 143000 12000 14KAMALA PAYROLL PACKAGE DBASEKAMALA PAYROLL PACKAGE DBASEKAMALA PAYROLL PACKAGE DBASEKAMALA PAYROLL PACKAGE DBASE9000 20000 79000 20000 79000 20000 79000 20000 7MARY CODE GENERATOR CMARY CODE GENERATOR CMARY CODE GENERATOR CMARY CODE GENERATOR C4500 20000 234500 20000 234500 20000 234500 20000 23

    Page 19Page 19Page 19Page 19

  • 8/12/2019 SQL_Queries - Notepad

    20/92

    SQL_QueriesSQL_QueriesSQL_QueriesSQL_QueriesMARY READ ME C++MARY READ ME C++MARY READ ME C++MARY READ ME C++300 1200 84300 1200 84300 1200 84300 1200 84PATRICK GRAPHIC EDITOR PASCALPATRICK GRAPHIC EDITOR PASCALPATRICK GRAPHIC EDITOR PASCALPATRICK GRAPHIC EDITOR PASCAL

    750 5000 11750 5000 11750 5000 11750 5000 11QADIR BOMBS AWAY ASSEMBLYQADIR BOMBS AWAY ASSEMBLYQADIR BOMBS AWAY ASSEMBLYQADIR BOMBS AWAY ASSEMBLY499.95 530 114499.95 530 114499.95 530 114499.95 530 114QADIR VACCINES CQADIR VACCINES CQADIR VACCINES CQADIR VACCINES C1900 3400 211900 3400 211900 3400 211900 3400 21RAMESH HOTEL MANAGEMENT DBASERAMESH HOTEL MANAGEMENT DBASERAMESH HOTEL MANAGEMENT DBASERAMESH HOTEL MANAGEMENT DBASE12000 35000 412000 35000 412000 35000 412000 35000 4RAMESH DEAD LEE PASCALRAMESH DEAD LEE PASCALRAMESH DEAD LEE PASCALRAMESH DEAD LEE PASCAL

    99.95 4500 7399.95 4500 7399.95 4500 7399.95 4500 73REMITHA PC UTILITIES CREMITHA PC UTILITIES CREMITHA PC UTILITIES CREMITHA PC UTILITIES C725 5000 51725 5000 51725 5000 51725 5000 51REMITHA TSR HELP PACKAGE ASSEMBLYREMITHA TSR HELP PACKAGE ASSEMBLYREMITHA TSR HELP PACKAGE ASSEMBLYREMITHA TSR HELP PACKAGE ASSEMBLY2500 6000 62500 6000 62500 6000 62500 6000 6REVATHI QUIZ MASTER BASICREVATHI QUIZ MASTER BASICREVATHI QUIZ MASTER BASICREVATHI QUIZ MASTER BASIC3200 2100 153200 2100 153200 2100 153200 2100 15VIJAYA ISK EDITOR CVIJAYA ISK EDITOR CVIJAYA ISK EDITOR CVIJAYA ISK EDITOR C900 700 6900 700 6900 700 6900 700 6

    15) How many packages were developed in dbase?15) How many packages were developed in dbase?15) How many packages were developed in dbase?15) How many packages were developed in dbase?

    SELECT COUNT(TITLE) AS TOTALSELECT COUNT(TITLE) AS TOTALSELECT COUNT(TITLE) AS TOTALSELECT COUNT(TITLE) AS TOTALFROM SOFTWAREFROM SOFTWAREFROM SOFTWAREFROM SOFTWAREWHERE DEV_IN='DBASE'WHERE DEV_IN='DBASE'WHERE DEV_IN='DBASE'WHERE DEV_IN='DBASE'

    Output:Output:Output:Output:

    TOTAL TOTAL TOTAL TOTAL---------------------------------------- 2 2 2 2

    16) How many programmers studies at paragathi?16) How many programmers studies at paragathi?16) How many programmers studies at paragathi?16) How many programmers studies at paragathi?

    Page 20Page 20Page 20Page 20

  • 8/12/2019 SQL_Queries - Notepad

    21/92

    SQL_QueriesSQL_QueriesSQL_QueriesSQL_QueriesSELECT COUNT(NAME)SELECT COUNT(NAME)SELECT COUNT(NAME)SELECT COUNT(NAME)FROM STUDIESFROM STUDIESFROM STUDIESFROM STUDIESWHERE SPLACE='PRAGATHI'WHERE SPLACE='PRAGATHI'WHERE SPLACE='PRAGATHI'WHERE SPLACE='PRAGATHI'

    Output:Output:Output:Output:COUNT(NAME)COUNT(NAME)COUNT(NAME)COUNT(NAME)-------------------------------------------- 3 3 3 317) How many programmers paid 5000 to 1000017) How many programmers paid 5000 to 1000017) How many programmers paid 5000 to 1000017) How many programmers paid 5000 to 10000for their course?for their course?for their course?for their course?

    SELECT COUNT(NAME) AS NOOFPROGRAMMERSSELECT COUNT(NAME) AS NOOFPROGRAMMERSSELECT COUNT(NAME) AS NOOFPROGRAMMERSSELECT COUNT(NAME) AS NOOFPROGRAMMERSFROM STUDIESFROM STUDIESFROM STUDIESFROM STUDIESWHERE CCOST>=5000WHERE CCOST>=5000WHERE CCOST>=5000WHERE CCOST>=5000AND CCOST

  • 8/12/2019 SQL_Queries - Notepad

    22/92

    SQL_QueriesSQL_QueriesSQL_QueriesSQL_Queries------------------------------------------------ 10471.429 10471.429 10471.429 10471.429

    19) Display the details of programmers knowing19) Display the details of programmers knowing19) Display the details of programmers knowing19) Display the details of programmers knowingc?c?c?c?

    SELECT *SELECT *SELECT *SELECT *FROM PROGRAMMERFROM PROGRAMMERFROM PROGRAMMERFROM PROGRAMMERWHERE PROF1='C' OR PROF2='C'WHERE PROF1='C' OR PROF2='C'WHERE PROF1='C' OR PROF2='C'WHERE PROF1='C' OR PROF2='C'

    Output:Output:Output:Output:NAME DOB DOJ S PROF1 PROF2NAME DOB DOJ S PROF1 PROF2NAME DOB DOJ S PROF1 PROF2NAME DOB DOJ S PROF1 PROF2SALARY SALARY SALARY SALARY

    -------- --------- --------- - ---------------- --------- --------- - ---------------- --------- --------- - ---------------- --------- --------- - ---------------- ------------------ ------------------ ------------------ ----------KAMALA 30-OCT-68 02-JAN-92 F C DBASEKAMALA 30-OCT-68 02-JAN-92 F C DBASEKAMALA 30-OCT-68 02-JAN-92 F C DBASEKAMALA 30-OCT-68 02-JAN-92 F C DBASE

    2900 2900 2900 2900QADIR 31-AUG-65 21-APR-93 M ASSEMBLY CQADIR 31-AUG-65 21-APR-93 M ASSEMBLY CQADIR 31-AUG-65 21-APR-93 M ASSEMBLY CQADIR 31-AUG-65 21-APR-93 M ASSEMBLY C

    3000 3000 3000 3000

    REMITHA 19-APR-70 20-APR-93 F CREMITHA 19-APR-70 20-APR-93 F CREMITHA 19-APR-70 20-APR-93 F CREMITHA 19-APR-70 20-APR-93 F CASSEMBLY 3600ASSEMBLY 3600ASSEMBLY 3600ASSEMBLY 3600VIJAYA 14-DEC-65 02-MAY-92 F FOXPRO CVIJAYA 14-DEC-65 02-MAY-92 F FOXPRO CVIJAYA 14-DEC-65 02-MAY-92 F FOXPRO CVIJAYA 14-DEC-65 02-MAY-92 F FOXPRO C

    3500 3500 3500 3500

    20) How many programmers know either Cobol or20) How many programmers know either Cobol or20) How many programmers know either Cobol or20) How many programmers know either Cobol orPascal?Pascal?Pascal?Pascal?

    SELECT COUNT(NAME) AS PROGRAMMERSSELECT COUNT(NAME) AS PROGRAMMERSSELECT COUNT(NAME) AS PROGRAMMERSSELECT COUNT(NAME) AS PROGRAMMERSFROM PROGRAMMERFROM PROGRAMMERFROM PROGRAMMERFROM PROGRAMMERWHERE PROF1='COBOL'WHERE PROF1='COBOL'WHERE PROF1='COBOL'WHERE PROF1='COBOL'OR PROF1='PASCAL'OR PROF1='PASCAL'OR PROF1='PASCAL'OR PROF1='PASCAL'OR PROF2='COBOL'OR PROF2='COBOL'OR PROF2='COBOL'OR PROF2='COBOL'OR PROF2='PASCAL'OR PROF2='PASCAL'OR PROF2='PASCAL'OR PROF2='PASCAL'

    Page 22Page 22Page 22Page 22

  • 8/12/2019 SQL_Queries - Notepad

    23/92

    SQL_QueriesSQL_QueriesSQL_QueriesSQL_Queries

    Output:Output:Output:Output:PROGRAMMERSPROGRAMMERSPROGRAMMERSPROGRAMMERS

    -------------------------------------------- 8888

    21) How many programmers don't know Pascal &21) How many programmers don't know Pascal &21) How many programmers don't know Pascal &21) How many programmers don't know Pascal &C?C?C?C?

    SELECT COUNT(NAME) AS PROGRAMMERSELECT COUNT(NAME) AS PROGRAMMERSELECT COUNT(NAME) AS PROGRAMMERSELECT COUNT(NAME) AS PROGRAMMERFROM PROGRAMMERFROM PROGRAMMERFROM PROGRAMMERFROM PROGRAMMER

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

    Output:Output:Output:Output:PROGRAMMERPROGRAMMERPROGRAMMERPROGRAMMER---------------------------------------- 6 6 6 6

    22) How old is the oldest male programmers?22) How old is the oldest male programmers?22) How old is the oldest male programmers?22) How old is the oldest male programmers?

    SELECT MAX(FLOOR((SYSDATE - DOB)/365)) ASSELECT MAX(FLOOR((SYSDATE - DOB)/365)) ASSELECT MAX(FLOOR((SYSDATE - DOB)/365)) ASSELECT MAX(FLOOR((SYSDATE - DOB)/365)) ASOLDESTMALEPROGRAMMERAGEOLDESTMALEPROGRAMMERAGEOLDESTMALEPROGRAMMERAGEOLDESTMALEPROGRAMMERAGEFROM PROGRAMMERFROM PROGRAMMERFROM PROGRAMMERFROM PROGRAMMER

    Output:Output:Output:Output:

    OLDESTMALEPROGRAMMERAGEOLDESTMALEPROGRAMMERAGEOLDESTMALEPROGRAMMERAGEOLDESTMALEPROGRAMMERAGE-------------------------------------------------------------------------------------------- 36 36 36 36

    Page 23Page 23Page 23Page 23

  • 8/12/2019 SQL_Queries - Notepad

    24/92

    SQL_QueriesSQL_QueriesSQL_QueriesSQL_Queries

    23) What is the average age of female23) What is the average age of female23) What is the average age of female23) What is the average age of female

    programmers?programmers?programmers?programmers?

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

    Output:Output:Output:Output:AVERAGEFEMALEAGEAVERAGEFEMALEAGEAVERAGEFEMALEAGEAVERAGEFEMALEAGE

    ---------------------------------------------------------------- 32 32 32 32

    24) Calculate the experience in years for each24) Calculate the experience in years for each24) Calculate the experience in years for each24) Calculate the experience in years for eachprogrammers and display along with the namesprogrammers and display along with the namesprogrammers and display along with the namesprogrammers and display along with the namesin descending order?in descending order?in descending order?in descending order?

    SELECT NAME AS PRNAME,FLOOR((SYSDATE -SELECT NAME AS PRNAME,FLOOR((SYSDATE -SELECT NAME AS PRNAME,FLOOR((SYSDATE -SELECT NAME AS PRNAME,FLOOR((SYSDATE -DOJ)/365) AS EXPERIENCEDOJ)/365) AS EXPERIENCEDOJ)/365) AS EXPERIENCEDOJ)/365) AS EXPERIENCE

    FROM PROGRAMMERFROM PROGRAMMERFROM PROGRAMMERFROM PROGRAMMERORDER BY NAME DESCORDER BY NAME DESCORDER BY NAME DESCORDER BY NAME DESC

    Output:Output:Output:Output:PR_NAME EXPERIENCEPR_NAME EXPERIENCEPR_NAME EXPERIENCEPR_NAME EXPERIENCE-------- ------------------ ------------------ ------------------ ----------VIJAYA 8VIJAYA 8VIJAYA 8VIJAYA 8REVATHI 9REVATHI 9REVATHI 9REVATHI 9

    REMITHA 7REMITHA 7REMITHA 7REMITHA 7REBECCA 10REBECCA 10REBECCA 10REBECCA 10RAMESH 10RAMESH 10RAMESH 10RAMESH 10QADIR 7QADIR 7QADIR 7QADIR 7PATRICK 10PATRICK 10PATRICK 10PATRICK 10NELSON 11NELSON 11NELSON 11NELSON 11

    Page 24Page 24Page 24Page 24

  • 8/12/2019 SQL_Queries - Notepad

    25/92

    SQL_QueriesSQL_QueriesSQL_QueriesSQL_QueriesMARY 10MARY 10MARY 10MARY 10KAMALA 9KAMALA 9KAMALA 9KAMALA 9JULIANA 10JULIANA 10JULIANA 10JULIANA 10

    JAGADISH 6JAGADISH 6JAGADISH 6JAGADISH 6ANAND 8ANAND 8ANAND 8ANAND 8ALTAF 10ALTAF 10ALTAF 10ALTAF 10

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

    SELECT NAMESELECT NAMESELECT NAMESELECT NAME

    FROM PROGRAMMERFROM PROGRAMMERFROM PROGRAMMERFROM PROGRAMMERWHERE TO_CHAR(DOB,'MM')=TO_CHAR(SYSDATE,'MM')WHERE TO_CHAR(DOB,'MM')=TO_CHAR(SYSDATE,'MM')WHERE TO_CHAR(DOB,'MM')=TO_CHAR(SYSDATE,'MM')WHERE TO_CHAR(DOB,'MM')=TO_CHAR(SYSDATE,'MM')

    Output:Output:Output:Output:NAMENAMENAMENAME--------------------------------ANANDANANDANANDANANDREMITHAREMITHAREMITHAREMITHA

    26) How many female programmers are there?26) How many female programmers are there?26) How many female programmers are there?26) How many female programmers are there?

    SELECT COUNT(NAME) AS NOFPROGSELECT COUNT(NAME) AS NOFPROGSELECT COUNT(NAME) AS NOFPROGSELECT COUNT(NAME) AS NOFPROGFROM PROGRAMMERFROM PROGRAMMERFROM PROGRAMMERFROM PROGRAMMERWHERE SEX='F'WHERE SEX='F'WHERE SEX='F'WHERE SEX='F'

    Output:Output:Output:Output:NO_OF_FEMALE_PROGRAMMERSNO_OF_FEMALE_PROGRAMMERSNO_OF_FEMALE_PROGRAMMERSNO_OF_FEMALE_PROGRAMMERS

    ------------------------------------------------------------------------------------------------ 7 7 7 7

    Page 25Page 25Page 25Page 25

  • 8/12/2019 SQL_Queries - Notepad

    26/92

    SQL_QueriesSQL_QueriesSQL_QueriesSQL_Queries

    27) What are the languages known by the male27) What are the languages known by the male27) What are the languages known by the male27) What are the languages known by the maleprogrammers?programmers?programmers?programmers?

    SELECT DISTINCT PROF1 AS LANGUAGESSELECT DISTINCT PROF1 AS LANGUAGESSELECT DISTINCT PROF1 AS LANGUAGESSELECT DISTINCT PROF1 AS LANGUAGESFROM PROGRAMMERFROM PROGRAMMERFROM PROGRAMMERFROM PROGRAMMERWHERE SEX='M'WHERE SEX='M'WHERE SEX='M'WHERE SEX='M'UNIONUNIONUNIONUNIONSELECT DISTINCT PROF2 AS LANGUAGESSELECT DISTINCT PROF2 AS LANGUAGESSELECT DISTINCT PROF2 AS LANGUAGESSELECT DISTINCT PROF2 AS LANGUAGESFROM PROGRAMMERFROM PROGRAMMERFROM PROGRAMMERFROM PROGRAMMERWHERE SEX='M'WHERE SEX='M'WHERE SEX='M'WHERE SEX='M'

    Output:Output:Output:Output:LANGUAGELANGUAGELANGUAGELANGUAGE--------------------------------ASSEMBLYASSEMBLYASSEMBLYASSEMBLYBASICBASICBASICBASICCCCCCLIPPERCLIPPERCLIPPERCLIPPERCOBOLCOBOLCOBOLCOBOL

    DBASEDBASEDBASEDBASEJAVAJAVAJAVAJAVAORACLEORACLEORACLEORACLEPASCALPASCALPASCALPASCAL

    28) What is the Average salary?28) What is the Average salary?28) What is the Average salary?28) What is the Average salary?

    SELECT AVG(SALARY) AS AVGSALSELECT AVG(SALARY) AS AVGSALSELECT AVG(SALARY) AS AVGSALSELECT AVG(SALARY) AS AVGSAL

    FROM PROGRAMMERFROM PROGRAMMERFROM PROGRAMMERFROM PROGRAMMEROutput:Output:Output:Output:AVERAGE_SALARYAVERAGE_SALARYAVERAGE_SALARYAVERAGE_SALARY-------------------------------------------------------- 3235.7143 3235.7143 3235.7143 3235.7143

    Page 26Page 26Page 26Page 26

  • 8/12/2019 SQL_Queries - Notepad

    27/92

    SQL_QueriesSQL_QueriesSQL_QueriesSQL_Queries29) How many people draw 2000 to 4000?29) How many people draw 2000 to 4000?29) How many people draw 2000 to 4000?29) How many people draw 2000 to 4000?

    SELECT NAME AS PRNAMESELECT NAME AS PRNAMESELECT NAME AS PRNAMESELECT NAME AS PRNAME

    FROM PROGRAMMERFROM PROGRAMMERFROM PROGRAMMERFROM PROGRAMMERWHERE SALARY>= 2000WHERE SALARY>= 2000WHERE SALARY>= 2000WHERE SALARY>= 2000OR SALARY

  • 8/12/2019 SQL_Queries - Notepad

    28/92

    SQL_QueriesSQL_QueriesSQL_QueriesSQL_Queriesknow Clipper, Cobol or Pascal?know Clipper, Cobol or Pascal?know Clipper, Cobol or Pascal?know Clipper, Cobol or Pascal?

    SELECT *SELECT *SELECT *SELECT *

    FROM PROGRAMMERFROM PROGRAMMERFROM PROGRAMMERFROM PROGRAMMERWHERE PROF1 NOT INWHERE PROF1 NOT INWHERE PROF1 NOT INWHERE PROF1 NOT IN('CLIPPER','COBOL','PASCAL')('CLIPPER','COBOL','PASCAL')('CLIPPER','COBOL','PASCAL')('CLIPPER','COBOL','PASCAL')AND PROF2 NOT IN ('CLIPPER','COBOL','PASCAL')AND PROF2 NOT IN ('CLIPPER','COBOL','PASCAL')AND PROF2 NOT IN ('CLIPPER','COBOL','PASCAL')AND PROF2 NOT IN ('CLIPPER','COBOL','PASCAL')

    Output:Output:Output:Output:NAME DOB DOJ S PROF1 PROF2NAME DOB DOJ S PROF1 PROF2NAME DOB DOJ S PROF1 PROF2NAME DOB DOJ S PROF1 PROF2

    SALARY SALARY SALARY SALARY

    -------- --------- --------- - ---------------- --------- --------- - ---------------- --------- --------- - ---------------- --------- --------- - ---------------- ------------------ ------------------ ------------------ ----------JAGADESH 06-OCT-70 04-OCT-94 M ORACLE JAVAJAGADESH 06-OCT-70 04-OCT-94 M ORACLE JAVAJAGADESH 06-OCT-70 04-OCT-94 M ORACLE JAVAJAGADESH 06-OCT-70 04-OCT-94 M ORACLE JAVA

    4100 4100 4100 4100KAMALA 30-OCT-68 02-JAN-92 F C DBASEKAMALA 30-OCT-68 02-JAN-92 F C DBASEKAMALA 30-OCT-68 02-JAN-92 F C DBASEKAMALA 30-OCT-68 02-JAN-92 F C DBASE

    2900 2900 2900 2900MARY 24-JUN-70 01-FEB-91 F C++ ORACLEMARY 24-JUN-70 01-FEB-91 F C++ ORACLEMARY 24-JUN-70 01-FEB-91 F C++ ORACLEMARY 24-JUN-70 01-FEB-91 F C++ ORACLE 4500 4500 4500 4500QADIR 31-AUG-65 21-APR-93 M ASSEMBLY CQADIR 31-AUG-65 21-APR-93 M ASSEMBLY CQADIR 31-AUG-65 21-APR-93 M ASSEMBLY CQADIR 31-AUG-65 21-APR-93 M ASSEMBLY C

    3000 3000 3000 3000REMITHA 19-APR-70 20-APR-93 F CREMITHA 19-APR-70 20-APR-93 F CREMITHA 19-APR-70 20-APR-93 F CREMITHA 19-APR-70 20-APR-93 F CASSEMBLY 3600ASSEMBLY 3600ASSEMBLY 3600ASSEMBLY 3600VIJAYA 14-DEC-65 02-MAY-92 F FOXPRO CVIJAYA 14-DEC-65 02-MAY-92 F FOXPRO CVIJAYA 14-DEC-65 02-MAY-92 F FOXPRO CVIJAYA 14-DEC-65 02-MAY-92 F FOXPRO C

    3500 3500 3500 3500

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

    SELECT COUNT(NAME) AS NOOFFPRGSELECT COUNT(NAME) AS NOOFFPRGSELECT COUNT(NAME) AS NOOFFPRGSELECT COUNT(NAME) AS NOOFFPRGFROM PROGRAMMERFROM PROGRAMMERFROM PROGRAMMERFROM PROGRAMMERWHERE SEX='F'WHERE SEX='F'WHERE SEX='F'WHERE SEX='F'AND (PROF1='C' OR PROF2='C')AND (PROF1='C' OR PROF2='C')AND (PROF1='C' OR PROF2='C')AND (PROF1='C' OR PROF2='C')AND ((SYSDATE-DOB)/365) > 24AND ((SYSDATE-DOB)/365) > 24AND ((SYSDATE-DOB)/365) > 24AND ((SYSDATE-DOB)/365) > 24

    Page 28Page 28Page 28Page 28

  • 8/12/2019 SQL_Queries - Notepad

    29/92

    SQL_QueriesSQL_QueriesSQL_QueriesSQL_Queries

    Output:Output:Output:Output: NOOFFPRGNOOFFPRGNOOFFPRGNOOFFPRG

    ---------------------------------------- 3 3 3 3

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

    SELECT NAMESELECT NAMESELECT NAMESELECT NAMEFROM PROGRAMMERFROM PROGRAMMERFROM PROGRAMMERFROM PROGRAMMER

    WHERE TO_CHAR(DOB,'WW') LIKEWHERE TO_CHAR(DOB,'WW') LIKEWHERE TO_CHAR(DOB,'WW') LIKEWHERE TO_CHAR(DOB,'WW') LIKETO_CHAR(SYSDATE,'WW')TO_CHAR(SYSDATE,'WW')TO_CHAR(SYSDATE,'WW')TO_CHAR(SYSDATE,'WW')

    OROROROR

    select * from programmer whereselect * from programmer whereselect * from programmer whereselect * from programmer whereto_char(dob,'dd') betweento_char(dob,'dd') betweento_char(dob,'dd') betweento_char(dob,'dd') betweento_char(sysdate,'dd') andto_char(sysdate,'dd') andto_char(sysdate,'dd') andto_char(sysdate,'dd') andto_char(next_day(sysdate,(to_char(sysdate,'dayto_char(next_day(sysdate,(to_char(sysdate,'dayto_char(next_day(sysdate,(to_char(sysdate,'dayto_char(next_day(sysdate,(to_char(sysdate,'day

    '))),'dd') and'))),'dd') and'))),'dd') and'))),'dd') andto_char(dob,'mon') betweento_char(dob,'mon') betweento_char(dob,'mon') betweento_char(dob,'mon') betweento_char(sysdate,'mon') andto_char(sysdate,'mon') andto_char(sysdate,'mon') andto_char(sysdate,'mon') andto_char(next_day(sysdate,(to_char(sysdate,'dayto_char(next_day(sysdate,(to_char(sysdate,'dayto_char(next_day(sysdate,(to_char(sysdate,'dayto_char(next_day(sysdate,(to_char(sysdate,'day'))),'mon')'))),'mon')'))),'mon')'))),'mon')

    Output:Output:Output:Output:no rows selectedno rows selectedno rows selectedno rows selected

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

    SELECT *SELECT *SELECT *SELECT *FROM PROGRAMMERFROM PROGRAMMERFROM PROGRAMMERFROM PROGRAMMER

    Page 29Page 29Page 29Page 29

  • 8/12/2019 SQL_Queries - Notepad

    30/92

    SQL_QueriesSQL_QueriesSQL_QueriesSQL_QueriesWHERE FLOOR((SYSDATE - DOJ)/365)

  • 8/12/2019 SQL_Queries - Notepad

    31/92

    SQL_QueriesSQL_QueriesSQL_QueriesSQL_Queries 3500350035003500

    14 rows selected.14 rows selected.14 rows selected.14 rows selected.

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

    SELECT NAME AS PRNAMESELECT NAME AS PRNAMESELECT NAME AS PRNAMESELECT NAME AS PRNAMEFROM PROGRAMMER WHEREFROM PROGRAMMER WHEREFROM PROGRAMMER WHEREFROM PROGRAMMER WHERE

    FLOOR((SYSDATE-DOJ)/365)=2;FLOOR((SYSDATE-DOJ)/365)=2;FLOOR((SYSDATE-DOJ)/365)=2;FLOOR((SYSDATE-DOJ)/365)=2;OROROROR

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

    OROROROR

    SELECT * FROM PROGRAMMER WHERESELECT * FROM PROGRAMMER WHERESELECT * FROM PROGRAMMER WHERESELECT * FROM PROGRAMMER WHERE(100 + MONTHS_BETWEEN('31-DEC-00',DOJ)/12)>=2(100 + MONTHS_BETWEEN('31-DEC-00',DOJ)/12)>=2(100 + MONTHS_BETWEEN('31-DEC-00',DOJ)/12)>=2(100 + MONTHS_BETWEEN('31-DEC-00',DOJ)/12)>=2ANDANDANDAND(100 + MONTHS_BETWEEN(SYSDATE,DOJ)/12) != 2;(100 + MONTHS_BETWEEN(SYSDATE,DOJ)/12) != 2;(100 + MONTHS_BETWEEN(SYSDATE,DOJ)/12) != 2;(100 + MONTHS_BETWEEN(SYSDATE,DOJ)/12) != 2;

    Output:Output:Output:Output:no rows selectedno rows selectedno rows selectedno rows selected

    35 Calculate the amount to be recovered for35 Calculate the amount to be recovered for35 Calculate the amount to be recovered for35 Calculate the amount to be recovered forthose packages whose development cost has notthose packages whose development cost has notthose packages whose development cost has notthose packages whose development cost has notbeen recovered?been recovered?been recovered?been recovered?

    SELECT (DCOST-(SCOST*SOLD)),TITLESELECT (DCOST-(SCOST*SOLD)),TITLESELECT (DCOST-(SCOST*SOLD)),TITLESELECT (DCOST-(SCOST*SOLD)),TITLEPage 31Page 31Page 31Page 31

  • 8/12/2019 SQL_Queries - Notepad

    32/92

    SQL_QueriesSQL_QueriesSQL_QueriesSQL_QueriesFROM SOFTWAREFROM SOFTWAREFROM SOFTWAREFROM SOFTWAREWHERE (SCOST*SOLD)

  • 8/12/2019 SQL_Queries - Notepad

    33/92

    SQL_QueriesSQL_QueriesSQL_QueriesSQL_QueriesREAD ME 300READ ME 300READ ME 300READ ME 300

    38) Display the institutes names from the38) Display the institutes names from the38) Display the institutes names from the38) Display the institutes names from the

    studies table without duplicates?studies table without duplicates?studies table without duplicates?studies table without duplicates?

    SELECT DISTINCT SPLACESELECT DISTINCT SPLACESELECT DISTINCT SPLACESELECT DISTINCT SPLACEFROM STUDIESFROM STUDIESFROM STUDIESFROM STUDIES

    Output:Output:Output:Output:SPLACESPLACESPLACESPLACE------------------------------------

    APPLEAPPLEAPPLEAPPLEBDPSBDPSBDPSBDPSBITSBITSBITSBITSBRILLIANTBRILLIANTBRILLIANTBRILLIANTCCITCCITCCITCCITPRAGATHIPRAGATHIPRAGATHIPRAGATHIS.S.I.LS.S.I.LS.S.I.LS.S.I.LSABHARISABHARISABHARISABHARI

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

    SELECT DISTINCT COURSE AS COURSESSELECT DISTINCT COURSE AS COURSESSELECT DISTINCT COURSE AS COURSESSELECT DISTINCT COURSE AS COURSESFROM STUDIESFROM STUDIESFROM STUDIESFROM STUDIES

    Output:Output:Output:Output:COURSCOURSCOURSCOURS--------------------DAPDAPDAPDAPDCADCADCADCADCA/PDCA/PDCA/PDCA/P

    Page 33Page 33Page 33Page 33

  • 8/12/2019 SQL_Queries - Notepad

    34/92

    SQL_QueriesSQL_QueriesSQL_QueriesSQL_QueriesDCAPDCAPDCAPDCAPDCPDCPDCPDCPDCSDCSDCSDCS

    HDCPHDCPHDCPHDCPPGDCAPGDCAPGDCAPGDCA

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

    SELECT NAMESELECT NAMESELECT NAMESELECT NAMEFROM PROGRAMMERFROM PROGRAMMERFROM PROGRAMMERFROM PROGRAMMER

    WHERE NAME LIKE '%A%A%'WHERE NAME LIKE '%A%A%'WHERE NAME LIKE '%A%A%'WHERE NAME LIKE '%A%A%'Output:Output:Output:Output:NAMENAMENAMENAME--------------------------------ANANDANANDANANDANANDALTAFALTAFALTAFALTAFJAGADESHJAGADESHJAGADESHJAGADESHJULIANAJULIANAJULIANAJULIANA

    KAMALAKAMALAKAMALAKAMALAVIJAYAVIJAYAVIJAYAVIJAYA

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

    SELECT NAMESELECT NAMESELECT NAMESELECT NAMEFROM PROGRAMMERFROM PROGRAMMERFROM PROGRAMMERFROM PROGRAMMER

    WHERE LENGTH(NAME)=5WHERE LENGTH(NAME)=5WHERE LENGTH(NAME)=5WHERE LENGTH(NAME)=5Output:Output:Output:Output:NAMENAMENAMENAME--------------------------------ANANDANANDANANDANAND

    Page 34Page 34Page 34Page 34

  • 8/12/2019 SQL_Queries - Notepad

    35/92

    SQL_QueriesSQL_QueriesSQL_QueriesSQL_QueriesALTAFALTAFALTAFALTAFQADIRQADIRQADIRQADIR

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

    SELECT NAME AS PRNAMESELECT NAME AS PRNAMESELECT NAME AS PRNAMESELECT NAME AS PRNAMEFROM PROGRAMMERFROM PROGRAMMERFROM PROGRAMMERFROM PROGRAMMERWHERE FLOOR((SYSDATE-DOJ)/365)>2WHERE FLOOR((SYSDATE-DOJ)/365)>2WHERE FLOOR((SYSDATE-DOJ)/365)>2WHERE FLOOR((SYSDATE-DOJ)/365)>2AND SEX='F'AND SEX='F'AND SEX='F'AND SEX='F'AND (PROF1='COBOL' OR PROF2='COBOL')AND (PROF1='COBOL' OR PROF2='COBOL')AND (PROF1='COBOL' OR PROF2='COBOL')AND (PROF1='COBOL' OR PROF2='COBOL')

    Output:Output:Output:Output:PRNAMEPRNAMEPRNAMEPRNAME--------------------------------JULIANAJULIANAJULIANAJULIANAREBECCAREBECCAREBECCAREBECCA