연구원생활

[SQL] 내가 들은 음악 결산 - 데이터 확인하기

저녕이 2025. 3. 15. 14:49
728x90
반응형
📖참고
코드잇 | SQL 프로젝트 : 내가 들은 음악 결산
🔖 목차
1. [SQL] 내가 들은 음악 결산 - 실습 설명
2. [SQL] 내가 들은 음악 결산 - 데이터 불러오기
3. [SQL] 내가 들은 음악 결산 - 데이터 확인하기

📍 데이터 확인하기

  • 존재하는 테이블의 목록과, 각 테이블의 컬럼 정보 확인하기
  • 사용자의 목록, 아티스트 목록 각각 확인하기
  • 궁금한 아티스트를 한 명 골라 모든 앨범 목록 확인하기
  • 사용자를 한 명 골라 가장 최근에 재상한 20곡을 재생 시점 순으로 확인하기

🐾 존재하는 테이블의 목록과, 각 테이블의 컬럼 정보 확인하기

  • music database에 존재하는 테이블 목록 확인하기
USE music;
SHOW TABLES;
Tables_in_music
albums
artists
history
songs
users

  • 각 테이블의 컬럼 정보 확인하기 

 aritsts 

DESCRIBE music.artists;
Field Type Null Key Default Extra
id int NO PRI NULL auto_increment
name varchar(30) NO   NULL  

 albums 

DESCRIBE music.albums;
Field Type Null Key Default Extra
id int NO PRI NULL auto_increment
title varchar(250) NO   NULL  
release_date datetime NO   NULL  
artist_id int NO MUL NULL  

 songs 

DESCRIBE music.songs;
Field Type Null Key Default Extra
id int NO PRI NULL auto_increment
title varchar(250) NO   NULL  
duration_seconds int NO   NULL  
album_id int NO MUL NULL  

 users 

DESCRIBE music.users;
Field Type Null Key Default Extra
id int NO PRI NULL auto_increment
username varchar(30) NO   NULL  
created_at datetime NO   NULL  

 history 

DESCRIBE music.history;
Field Type Null Key Default Extra
id int NO PRI NULL auto_increment
played_at datetime NO   NULL  
user_id int YES MUL NULL  
song_id int YES MUL NULL  

🐾 사용자의 목록, 아티스트 목록 각각 확인하기

 users 

SELECT * from users;
id username created_at
1 ljones 2020-02-16 8:51
2 alexanderbaker 2020-03-05 6:16
3 michaelacosta 2020-03-23 19:44
4 joshuadaniel 2020-03-25 21:09
5 rramirez 2020-05-06 4:26

 aritsts 

SELECT * from artists;
id name
1 Carmen Johnson
2 Lisa Fox
3 Tammy Webb
4 Amy Hancock
5 Lindsay Mendoza

🐾 궁금한 아티스트를 한 명 골라 모든 앨범 목록 확인하기

  • Carmen Johnson 조회하기
SELECT * from albums
WHERE artist_id = (
SELECT id from artists WHERE name = "Carmen Johnson");
id title release_date artist_id
60 Itself budget 2015-03-19 0:00 1
101 Land sound thank 2018-09-29 0:00 1
357 Power information expect 2021-04-13 0:00 1

🐾 사용자를 한 명 골라 가장 최근에 재생한 20곡을 재생 시점 순으로 확인하기

  • angela08 사용자가 가장 최근에 재생한 20곡 조회하기
SELECT history.id,
	   history.played_at,
       history.user_id,
       users.username,
       history.song_id,
       songs.title
       FROM history
INNER JOIN users ON history.user_id = users.id
INNER JOIN songs ON history.song_id = songs.id
WHERE username = 'angela08'
ORDER BY played_at DESC
LIMIT 20;
id played_at user_id username song_id title
84443 2025-02-12 23:14 87 angela08 3476 Response show
28596 2025-02-12 15:00 87 angela08 2459 Management order
67899 2025-02-12 12:01 87 angela08 1018 Group
50386 2025-02-11 1:39 87 angela08 2259 When
30075 2025-02-06 19:38 87 angela08 3414 Without
98670 2025-02-06 5:15 87 angela08 2068 Amount
36386 2025-02-06 5:05 87 angela08 1899 Product
51773 2025-02-06 1:52 87 angela08 4640 Who
10527 2025-02-05 20:45 87 angela08 2384 Leader
48723 2025-02-05 17:59 87 angela08 690 Director home
74799 2025-02-03 10:49 87 angela08 587 Morning
38499 2025-02-02 13:44 87 angela08 2100 Wall crime
56359 2025-02-02 11:02 87 angela08 4587 Process but
25821 2025-02-02 3:12 87 angela08 4787 Everything
33689 2025-02-01 23:17 87 angela08 3370 Movie
22663 2025-01-31 12:51 87 angela08 4524 Art two
31258 2025-01-31 12:28 87 angela08 4974 Cover less
90416 2025-01-31 12:25 87 angela08 198 Low once
75550 2025-01-31 10:51 87 angela08 4661 Company
19697 2025-01-30 18:45 87 angela08 2424 Responsibility too
728x90
반응형