MySQL Forums
Forum List  »  Newbie

Re: Select the most frequent value of each year in the db
Posted by: Peter Brawley
Date: May 07, 2020 09:15AM

A CTE gives the most elegant solution ...

with
 a as (
  select left(date,4) as year, lens, count(*) N
  from tb_exifinfo
  group by year,lens
 ),
 b as (
  select year, max(N) as maxN
  from a
  group by year
 )
select a.year, a.lens, a.N
from a join b on a.year=b.year and a.N=b.maxN;

Options: ReplyQuote


Subject
Written By
Posted
Re: Select the most frequent value of each year in the db
May 07, 2020 09:15AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.