Код: Выделить всё
+--------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+--------------+------+-----+---------+-------+
| filename | char(18) | NO | PRI | | |
| iso | mediumint | YES | | NULL | |
| aperture | decimal(3,1) | YES | | NULL | |
| exposuretime | tinytext | YES | | NULL | |
| focal_length | smallint | YES | | NULL | |
| lens | tinytext | YES | | NULL | |
| date | date | NO | PRI | NULL | |
| time | time | NO | PRI | NULL | |
| model | tinytext | YES | | NULL | |
| flash | tinyint(1) | YES | | NULL | |
+--------------+--------------+------+-----+---------+-------+
Код: Выделить всё
with a as (
select date_format(date, '%M') as month,
lens,
count(\*) N
from tb_exifinfo
group by month,lens order by month
), b as (
select month,
max(N) as maxN
from a group by month
) select a.month,
a.lens,
a.N
from a
join b on a.month=b.month and a.N=b.maxN;
Код: Выделить всё
+-----------+------------------------------+-----+
| month | lens | N |
|-----------|------------------------------|-----|
| April | Sigma 18-50f/2.8 EX DC HSM | 554 |
| August | Sigma 18-50f/2.8 EX DC HSM | 461 |
| December | Sigma 18-50f/2.8 EX DC HSM | 228 |
| February | Canon EF 24-70mm f/2.8L USM | 344 |
| January | Sigma 18-50f/2.8 EX DC HSM | 266 |
| July | Sigma 18-50f/2.8 EX DC HSM | 738 |
| June | Sigma 18-50f/2.8 EX DC HSM | 690 |
| March | Sigma 18-50f/2.8 EX DC HSM | 243 |
| May | Canon EF 70-200mm f/4L USM | 747 |
| November | Sigma 18-50f/2.8 EX DC HSM | 539 |
| October | Canon EF 24-70mm f/2.8L USM | 536 |
| September | Canon EF 16-35mm f/4L IS USM | 202 |
+-----------+------------------------------+-----+
С уважением,
Питер
Подробнее здесь: https://stackoverflow.com/questions/798 ... l-database
Мобильная версия