반응형
SELECT
cs.case_id,
cs.timestamp,
cs.score
FROM `untechbox-sql.interview_question.case_score` AS cs
INNER JOIN
(
SELECT
case_id,
MAX(timestamp) AS most_recent_date
FROM `untechbox-sql.interview_question.case_score`
GROUP BY 1
) AS md
ON cs.timestamp = md.most_recent_date AND cs.case_id = md.case_id;
Q2.
We have a "HISTORY" table with 4 fields
User_id
Action_date
Action_time
ActionQ: Create the following "ARCHIVE" table
User_id,
Last_action_date,
Last_action_time,
Num_actions,
Archive_date
SELECT
user_id,
MAX(action_date) AS last_action_date,
MAX(action_time) AS last_action_time,
COUNT(action) AS number_of_actions,
CURRENT_DATE() AS archive_date
반응형
'SQL > SQL 문제풀이' 카테고리의 다른 글
[SQL-P] 해커랭크 Advanced Join_Interviews (0) | 2020.12.02 |
---|---|
[SQL-P] 해커랭크 Advanced Join_Placements (0) | 2020.12.02 |
[SQL-P] 해커랭크 Basic Join_African Cities (0) | 2020.12.02 |