문제

Hi I want to GROUP BY file_serial but only when file_serial > 1 that mean no duplicate file_serial with value bigger than 1

Current Table

so it should look like

Wanted Table

Any idea how, would be great. Thanks.

도움이 되었습니까?

해결책

One way would be

select * from table
where  file_serial > 1
group by file_title
having count(*) > 1

UNION

select * from table

UPDATE

The above will work only if all the selecting columns with the same value. In this case you may need to change as since file_id is different for the same title.

    select * from table
    where  file_serial > 1
    group by file_title
    having count(*) > 0 

    UNION

    select * from table
    file_serial <= 1 

DEMO

다른 팁

Try below query, where no need of extra having clause-

SELECT 
file_id,file_title,file_serial 
FROM mytable 
WHERE file_serial<=1 
UNION ALL 
SELECT 
file_id,file_title,file_serial 
FROM mytable 
WHERE file_serial>1 
GROUP BY file_serial;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top