MySQL 테이블에서 최신 레코드를 검색하는 방법
시간에 민감한 데이터를 MySQL 테이블에 저장할 때 다음이 필요한 경우가 많습니다. 특정 필드 조합에 대한 최신 레코드를 검색합니다. 다음 예에서는 타임스탬프, 메서드, ID 등의 필드가 포함된 RPC 응답 테이블을 처리할 때 이를 달성하는 방법을 보여줍니다.
질문
rpc_responses는 다음 구조를 갖습니다:
CREATE TABLE rpc_responses ( timestamp DATE, method VARCHAR, id VARCHAR, response MEDIUMTEXT, PRIMARY KEY (timestamp, method, id) );
다음과 같은 경우 데이터:
timestamp | method | id | response |
---|---|---|---|
2009-01-10 | getThud | 16 | "....." |
2009-01-10 | getFoo | 12 | "....." |
2009-01-10 | getBar | 12 | "....." |
2009-01-11 | getFoo | 12 | "....." |
2009-01-11 | getBar | 16 | "....." |
원하는 결과
모든 기존 메소드 및 ID 조합에 대한 가장 최근 응답 목록 가져오기:
timestamp | method | id | response |
---|---|---|---|
2009-01-10 | getThud | 16 | "....." |
2009-01-10 | getBar | 12 | "....." |
2009-01-11 | getFoo | 12 | "....." |
2009-01-11 | getBar | 16 | "....." |
답변
성취하려면 이를 위해서는 다음 쿼리를 활용하세요.
SELECT * FROM ( SELECT *, IF(@last_method = method, 0, 1) AS new_method_group, @last_method := method FROM rpc_responses ORDER BY method, timestamp DESC ) AS t1 WHERE new_method_group = 1;
이 쿼리는 조인 없이도 원하는 결과를 효율적으로 검색합니다. 또한 원하는 행 구조를 유지하여 메소드와 ID의 고유한 조합마다 고유한 레코드를 제공합니다.
위 내용은 MySQL에서 각 방법 및 ID 조합에 대한 최신 레코드를 선택하는 방법은 무엇입니까?의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

todropaViewInmysql, "dropviewifexistsview_name;"및 TomodifyAview를 사용하고 "createOrreplaceViewView_NameAsselect ...". "

mysqlViewScaneFeficTicallyINGILIDESIGNPATTORNSLIKEADAPTER, DECIARATOR, FACTORY 및 OBSERVER.1) AdapterPatternAdAptSDataFromDifferentTablesinToAunifiedView.2) Decor

viewsinmysqlarebeneficialforsimplifyingcomplexqueries, envancingsecurity, dataconsistency, andoptimizing promperformance

toeteimpleviewinmysql, usethecreateviewstatement.1) definetheviewwithReateViewview_nameas.2) specifyTesLectStatementToreTrievesiredData.3) usetheViewLikeAtableForqueries.ViewsSimplifyDataAccessAndenHances, ButconSiderFormance

toCreateUserSinmysql, usethecreateuserstatement.1) foralocaluser : createUser'LocalUser '@'localHost'IndifiedBy'SecurePassword '; 2) foremoteUser : createUser'RemoteUser'@'%'reidentifiedBy'StrongPassword ';

mysqlviewshavelimitations : 1) 그들은 upportallsqloperations, datamanipulation throughviewswithjoinsorbqueries를 제한하지 않습니다

적절한 usermanagementInmysqliscrucialforenhancingsecurityandensuringfefficientDatabaseOperation.1) USECREATEUSERTOWDDUSERS,@'localHost'or@'%'.

mysqldoes notimposeahardlimitontriggers, butpracticalfactorsdeteirefectiveuse : 1) ServerConfigurationimpactStriggerManagement; 2) 복잡한 트리거 스케일 스케일 사이드로드; 3) argertableSlowtriggerTriggerPerformance; 4) High ConconcercencyCancaUspriggerContention; 5) m


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

MinGW - Windows용 미니멀리스트 GNU
이 프로젝트는 osdn.net/projects/mingw로 마이그레이션되는 중입니다. 계속해서 그곳에서 우리를 팔로우할 수 있습니다. MinGW: GCC(GNU Compiler Collection)의 기본 Windows 포트로, 기본 Windows 애플리케이션을 구축하기 위한 무료 배포 가능 가져오기 라이브러리 및 헤더 파일로 C99 기능을 지원하는 MSVC 런타임에 대한 확장이 포함되어 있습니다. 모든 MinGW 소프트웨어는 64비트 Windows 플랫폼에서 실행될 수 있습니다.

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

SublimeText3 Linux 새 버전
SublimeText3 Linux 최신 버전

에디트플러스 중국어 크랙 버전
작은 크기, 구문 강조, 코드 프롬프트 기능을 지원하지 않음

DVWA
DVWA(Damn Vulnerable Web App)는 매우 취약한 PHP/MySQL 웹 애플리케이션입니다. 주요 목표는 보안 전문가가 법적 환경에서 자신의 기술과 도구를 테스트하고, 웹 개발자가 웹 응용 프로그램 보안 프로세스를 더 잘 이해할 수 있도록 돕고, 교사/학생이 교실 환경 웹 응용 프로그램에서 가르치고 배울 수 있도록 돕는 것입니다. 보안. DVWA의 목표는 다양한 난이도의 간단하고 간단한 인터페이스를 통해 가장 일반적인 웹 취약점 중 일부를 연습하는 것입니다. 이 소프트웨어는