Код: Выделить всё
mysql> describe tb_exifinfo;
+--------------+--------------+------+-----+---------+-------+
| 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 | |
| fìle_size | decimal(3,1) | YES | | NULL | |
| orientation | tinytext | YES | | NULL | |
+--------------+--------------+------+-----+---------+-------+
12 rows in set (0.00 sec)
Код: Выделить всё
with a as (
select model as model, lens, count(*) N
from tb_exifinfo
group by model,lens
order by model )
, b as (
select model, max(N) as maxN
from a
group by model)
select a.model, a.lens, a.N
from a join b on a.model=b.model and a.N=b.maxN;
Код: Выделить всё
+------------------------+------------------------------+------+
| model | lens | N |
+------------------------+------------------------------+------+
| Canon EOS 350D DIGITAL | Sigma 18-50f/2.8 EX DC HSM | 3959 |
| Canon EOS 600D | Canon EF 24-70mm f/2.8L USM | 2480 |
| Canon EOS 6D Mark II | Canon EF 16-35mm f/4L IS USM | 1017 |
| Canon EOS R6 Mark III | Sigma 50mm f/1.4 DG HSM | A | 45 |
+------------------------+------------------------------+------+
4 rows in set (0.02 sec)
Подробнее здесь: https://stackoverflow.com/questions/798 ... m-a-select
Мобильная версия