블로그 이미지
암초보

calendar

1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30

Notice

Tag

04-27 01:21
2014. 8. 12. 16:40 DB/MySQL

Group by로 묶은 것중에 n번째를 선택하는방법은...

아래 링크를 참고..

http://code.openark.org/blog/mysql/sql-selecting-top-n-records-per-group


간단한 예제. 해석은 알아서..

SELECT
    SUBSTRING_INDEX( GROUP_CONCAT(fieldA ORDER BY dateField DESC), ',', 1 ) as 'test'
FROM
    tableA
GROUP BY fieldC


그리고,,

group_concat_max_len 에 주의,,


'DB > MySQL' 카테고리의 다른 글

mysqldump db별 sql 덤프  (1) 2018.09.12
특정 테이블을 참조하고 있는 테이블 찾는 방법  (0) 2016.10.07
INSERT IGNORE  (0) 2013.11.29
procedure function 덤프  (0) 2013.10.31
The Rows Holding the Group-wise Maximum of a Certain Column  (0) 2013.10.23
posted by 암초보