SQL
Lab
Microsoft Microsoft Interview Question 06

License
Expiry
Alert

Find licenses expiring within the next 7 days.

Table Schema

Inspect
Table

interactive
ColumnType
license_idinteger
user_idinteger
expiry_datedate

Sample Data

Input
Output

Sample Input: licenses
license_iduser_idexpiry_date
11012024-02-01
21022024-02-05
31032024-02-20
41042024-02-03
51052024-02-10
Expected Output
license_iduser_id
1101
2102
4104

SQL Editor

Run
Query

postgresql
Waiting for query

license_iduser_id
1101
2102
4104

Hints

Unlock
Clues

Hint 01: Identify the grouping level required by the output.
Hint 02: Aggregate with COUNT, SUM, AVG, or a window function as needed.
Hint 03: Filter after aggregation with HAVING or after ranking with an outer query.

Solution

Locked
Answer

Solution is locked until you decide to reveal it. Try the editor first, then open this when you want the reference answer.

SELECT license_id, user_id
FROM licenses
WHERE expiry_date BETWEEN DATE '2024-02-01' AND DATE '2024-02-01' + INTERVAL '7 days';

Explanation

Step By
Step

01

Read the expected output columns to determine the final grain.

02

Aggregate or rank the input rows to calculate the requested metric.

03

Filter, sort, and alias the final columns to match the output.

Related Questions

Keep
Solving