標籤:

SQL

sgd

1. Find the names of all instructors in Comp Sci and, if they taught a course in Autumn

2009, give the course id and sec id.

SELECT A2, A4, A5FROM ( SELECT ID AS A1, NAME AS A2 FROM instructor WHERE dept_name = 『Comp.Sci.』) AS T1LEFT OUTER JOIN( SELECT ID AS A3, course_id AS A4, sec_id AS A5 FROM teaches WHERE semester = 『Autumn』 AND YEAR = 2009) AS T2ON (A1 = A3)

1. Find the maximum enrolment, across all sections, in Spring

2009.

SELECT MAX(enrolmt) AS maxEnrolmtFROM ( SELECT course_id, sec_id, COUNT(*) AS enrolmt FROM takes WHERE semester = Spring AND YEAR = 2009 GROUP BY course_id, sec_id) AS T1;

asdgfds

5. Find all instructors earning the highest salary (there may be more than one with the same salary).

SELECT ID, NAMEFROM instructorWHERE salary IN( SELECT MAX(salary) FROM instructor);

Find the enrollment of each section that was offered in Spring 2009

SELECT course_id, sec_id, COUNT(*) AS enrollFROM takesWHERE semester = Spring AND YEAR = 2009GROUP BY course_id, sec_id;

lists the number of customers in each country:

SELECT COUNT(CustomerID), CountryFROM CustomersGROUP BY Country;

1. SELECT max(Salary) as maxSalary

FROM instructor;

SELECT MAX(Salary) AS maxSalaryFROM instructor;

推薦閱讀:

Sqli labs系列-less-5&6 報錯注入法(下)
零基礎如何學習SQL——了解select查詢語句
Python3 pandas如何加快SQL Server讀寫速度?
mysql表中查找和小於某個數的所有最前面的記錄?
SQL 查詢按照家庭住址進行分組時,組內平均年齡小於50歲的組中成員的姓名和年齡?

TAG:SQL |