my sql"group by"와"orderby"의 연구-분류 에서 최신 내용
CREATE TABLE `test` (
`id` INT(10) NOT NULL AUTO_INCREMENT,
`name` VARCHAR(255) NOT NULL,
`category_id` INT(10) NOT NULL,
`date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
)
ENGINE=MyISAM
ROW_FORMAT=DEFAULT;
INSERT INTO `test` (`id`, `name`, `category_id`, `date`)
VALUES
(1, 'aaa', 1, '2010-06-10 19:14:37'),
(2, 'bbb', 2, '2010-06-10 19:14:55'),
(3, 'ccc', 1, '2010-06-10 19:16:02'),
(4, 'ddd', 1, '2010-06-10 19:16:15'),
(5, 'eee', 2, '2010-06-10 19:16:35');

select * from test group by category_id order by `date`
결 과 는 다음 과 같다
인용 하 다.
쓰 는 순서:select...from...where...group by...having..order by..실행 순서:from..where..group by..having...select..order by..그래서 order by 가 받 은 결과 에 서 는 이미 조 를 나 눈 마지막 결과 입 니 다.from 에서 where 까지 의 결 과 는 다음 과 같다.




select group_concat(id order by `date` desc) from `test` group by category_id

select * from `test` where id in(select SUBSTRING_INDEX(group_concat(id order by `date` desc),',',1) from `test` group by category_id)order by`date`desc

select * from (select * from `test` order by `date` desc) `temp` group by category_id order by `date` desc

이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
🕗[프로그래머스] 입양 시각 구하기(2)문제 설명 ANIMAL_OUTS 테이블은 동물 보호소에서 입양 보낸 동물의 정보를 담은 테이블입니다. ANIMAL_OUTS 테이블 구조는 다음과 같으며, ANIMAL_ID, ANIMAL_TYPE, DATETIME, ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.