Answer the question
In order to leave comments, you need to log in
How to set the desired grouping in MySQL?
Hello. I have no idea how to select.
Let's say there is a table tbl1 and tbl2. In the first, as it were, extended data, in the second, you need to save the summarized result.
That is, tbl1 contains statistics, for example, nick, time, summa, id:
vovka1 1451353490 112.6 239
Jaguar 1451353504 112.7 239
vovka1 1451353518 112.8 239
Jaguar
1451353533 112.9 239
To get something, nick, summa, id, count (the number of all entries in the nick and id fields):
Jaguar 1451353533 112.9 239 2
vovka1 1451353518 112.8 239 2
Answer the question
In order to leave comments, you need to log in
INSERT INTO tbl2(nick, summa, id, count )
SELECT nick,MAX(summa),id,COUNT(1) FROM tbl1
GROUP BY id,nick
select tbl1.nick tbl1.summa, tbl1.id, tmp2.cnt
from tbl1
inner join (
select nick, max(summa) as summa from tbl1 group by nick
) as tmp using (nick, summa)
inner join (
select nick, id, count(*) as cnt from tbl1 group by nick, id
) as tmp2 using (nick, id)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question