You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# PersonId is the primary key column for this table.
14
+
# Table: Address
15
+
#
16
+
# +-------------+---------+
17
+
# | Column Name | Type |
18
+
# +-------------+---------+
19
+
# | AddressId | int |
20
+
# | PersonId | int |
21
+
# | City | varchar |
22
+
# | State | varchar |
23
+
# +-------------+---------+
24
+
# AddressId is the primary key column for this table.
25
+
#
26
+
# Write a SQL query for a report that provides the following information for each person in the Person table, regardless if there is an address for each of those people:
27
+
#
28
+
#FirstName, LastName, City, State
29
+
#
30
+
#
31
+
# Write your MySQL query statement below
32
+
SELECT FirstName, LastName, City, State FROM Person LEFT JOIN Address
# Write a SQL query to get the nth highest salary from the Employee table.
5
+
#
6
+
# +----+--------+
7
+
# | Id | Salary |
8
+
# +----+--------+
9
+
# | 1 | 100 |
10
+
# | 2 | 200 |
11
+
# | 3 | 300 |
12
+
# +----+--------+
13
+
# For example, given the above Employee table, the nth highest salary where n = 2 is 200. If there is no nth highest salary, then the query should return null.
14
+
#
15
+
CREATEFUNCTIONgetNthHighestSalary(N INT) RETURNS INT
16
+
BEGIN
17
+
RETURN (
18
+
# Write your MySQL query statement below.
19
+
SELECTMAX(Salary) /*This is the outer query part */
# Write a SQL query to get the second highest salary from the Employee table.
5
+
#
6
+
# +----+--------+
7
+
# | Id | Salary |
8
+
# +----+--------+
9
+
# | 1 | 100 |
10
+
# | 2 | 200 |
11
+
# | 3 | 300 |
12
+
# +----+--------+
13
+
# For example, given the above Employee table, the second highest salary is 200. If there is no second highest salary, then the query should return null.
14
+
#
15
+
# Write your MySQL query statement below
16
+
SELECTMAX(Salary) FROM Employee
17
+
WHERE Salary NOT IN (SELECTMAX(Salary) FROM Employee)
0 commit comments