sub_select에서 database_size의 MAX를 사용하여 distinct server_name, date를 선택해야합니다. 고유 한 server_names를 얻을 수 없습니다. 내 쿼리는 다음과 같습니다. 참고 * 날짜는 별개의 database_size는 별개이며 : 항상 (내 테이블에 중복 값이없는 경우에도)subselect에서 MAX와 Distinct를 사용하는 방법
이내 테이블
id server_name database_size received_at
1 [email protected] 271254016 2016-04-28
2 [email protected] 61739776 2016-05-03
3 [email protected] 61438464 2016-05-03
4 [email protected] 280043520 2016-05-03
내가 원하는 결과 중복을 반환 그 rver_name은 구별됩니다 -이 값 중 어느 것도 동일해야합니다.
[email protected] 271254016 2016-04-28
[email protected] 274209280 2016-04-29
[email protected] 268375040 2016-04-30
[email protected] 277126400 2016-05-01
나는이 쿼리 시도 : 이, 내가 DISTINCT 서버 _ 이름을 마우스 오른쪽 버튼으로 원하는되지 않은 (그러나 DISTINCT 두는 것은 도움이되지 않습니다 - 여전히 같은 서버 _ 이름을 반환)
select server_name, sum(data_size) as data_size, date from (select date(received_at) as date, sum(database_size) as data_size,
server_name from schema.db_stats group by date(received_at), server_name) where server_name like '%abc%' group by date, server_name order by date
을하지만 도착 : 나는 server_name을 여러 번 얻었는데, 최대 값 database_size를 가진 server_name 만 필요합니다.
[email protected] 271254016 2016-04-28
[email protected] 274209280 2016-04-29
[email protected] 268375040 2016-04-30
[email protected] 277126400 2016-05-01
[email protected] 277126400 2016-05-02
[email protected] 61739776 2016-05-03
[email protected] 61438464 2016-05-03
[email protected] 280043520 2016-05-03
누군가 도와주세요. 정말 감사하겠습니다.
내가 샘플 데이터와 당신이 찾고있는 결과 사이의 관계를 볼 수 없습니다. –
어떤 DBMS를 사용하고 있습니까? 내가 ** DB2 UDB는을 (내가 찾고 있어요 쿼리는 DB2의 모든 버전에 적용 할 수있는) –
@a_horse_with_no_name하지 ** "SQL 서버"에 대한 - 그것은 SQL, 음, 위해입니다. SQL 서버를위한 것입니다 질문은 SQL-server' – shizuka