10-Queries-for-SQL-101-Session.docx - 10 Queries for...

This preview shows page 1 - 5 out of 12 pages.

10 Queries for Revision from SQL 101 Session To run the below commands please paste the following in the Schema (left side) on Screenshot of output pasted below that worked at my end. CREATE TABLE attendees ( personid INT PRIMARY KEY , heroname VARCHAR ( 255 ) , age INT , assets INT , sector VARCHAR ( 255 ) , city VARCHAR ( 255 ) , salary INT , distancetraveled INT , rating INT ) ; INSERT INTO attendees (personid , heroname , age , assets , sector , city , salary , distancetraveled , rating) VALUES ( 1 , 'Spider Man ' , 32 , 300000 , 'Tech' , 'B' , 10000 , 10 , 9 ) , ( 2 , 'Super Man ' , 64 , 700000 , 'Tech' , 'M' , 10700 , 1
Image of page 1

Subscribe to view the full document.

11 , 5 ) , ( 3 , 'Bat Man ' , 100 , 900000 , 'Fin' , 'Q' , 12000 , 11 , 4 ) , ( 4 , 'X Man ' , 200 , 140000 , 'Fin' , 'B' , 12500 , 13 , 5 ) , ( 5 , 'Wonder Woman' , 100 , 13000 , 'Tech' , 'C' , 11500 , 11 , NULL ) ; CREATE TABLE avgsalary ( city2 VARCHAR ( 255 ) , avgsalary INT ) ; INSERT INTO avgsalary (city2 , avgsalary) VALUES ( 'M' , 12000 ) , ( 'B' , 11000 ) , ( 'Q' , 9000 ) , ( 'LI' , 8500 ) ; CREATE TABLE avgsalary2 ( city VARCHAR ( 255 ) , 2
Image of page 2
avgsalary INT ) ; INSERT INTO avgsalary2 (city , avgsalary) VALUES ( 'M' , 12000 ) , ( 'B' , 11000 ) , ( 'Br' , 9000 ) , ( 'Bs' , 7000 ) ; Queries: Select Superhero from cities where avg salary is greater than 10000: (Using Correlated Subquery): SELECT * FROM attendees WHERE city IN ( SELECT city FROM avgsalary WHERE avgsalary > 10000 ) ; 3
Image of page 3

Subscribe to view the full document.

Show an example with Having, Where and Order by in the same query?
Image of page 4
Image of page 5
  • Fall '19
  • hari
  • Wonder Woman, Avgsalary

{[ snackBarMessage ]}

Get FREE access by uploading your study materials

Upload your study materials now and get free access to over 25 million documents.

Upload now for FREE access Or pay now for instant access
Christopher Reinemann
"Before using Course Hero my grade was at 78%. By the end of the semester my grade was at 90%. I could not have done it without all the class material I found."
— Christopher R., University of Rhode Island '15, Course Hero Intern

Ask a question for free

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern