SQL/SQL 문제풀이

구글 인터뷰 질문

DACHO 2020. 11. 30. 21:37
반응형
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

 

반응형