Я положил в базу данных много строк, и у меня есть это:
+----+---------------------+-------------+----------------+-----------+ | ID | time | os_name | program | last_line | +----+---------------------+-------------+----------------+-----------+ | 14 | 2019-01-04 14:00:00 | titi | roro | 109 | | 15 | 2019-01-04 14:00:00 | titi | roro | 109 | | 16 | 2019-01-04 14:00:00 | gege | fefe | 109 |
я хочу:
+---------------------+-------------------------+-------------+-----------+-----------+ | time | nb_os_name_program | os_name | program | last_line | +---------------------+-------------------------+-------------+-----------+-----------+ | 2019-01-04 14:00:00 | 2 | titi | roro | 109 | | 2019-01-04 14:00:00 | 1 | gege | fefe | 109 |
Простой GROUP BY с агрегацией поможет вам:
GROUP BY
SELECT time, os_name, count(*) as nb_os_name, program, lastline, FROM table t GROUP BY time, os_name, program, lastline