Home > database >  Maximum MySQL query grouped by day every day of time
Maximum MySQL query grouped by day every day of time

Time:10-03

Table: A (time, siteid, pac)
The time is a datetime types, pac is float type

Every day I want to check all the siteid at all time points on the day of the avg (pac) appeared the maximum of the time, could you tell me how to write the SQL?

My original SQL is like this:
Example. Select the t1 time, Max (apac) as mpac from (select time, avg example (Pac) as apac from A where clause time>="2017-09-20" and time<="2017-10-30" group by time) t1 group by DATE_FORMAT (time, "% % Y - m - % d");

But this check out time is wrong, is a day after the start time of

How should I change

CodePudding user response:

Select *
From A a1
Where not exits (select 1 from a2 where A date (a1. Time)=date (a2) time) and a1. SiteidThe order by a1. Time desc;

CodePudding user response:

reference 1st floor rucypli response:
select *
From A a1
Where not exits (select 1 from a2 where A date (a1. Time)=date (a2) time) and a1. SiteidThe order by a1. Time desc;


A1, a2 was bought what ah, see

CodePudding user response:

refer to the second floor xiaxusong response:
Quote: refer to 1st floor rucypli response:

Select *
From A a1
Where not exits (select 1 from a2 where A date (a1. Time)=date (a2) time) and a1. SiteidThe order by a1. Time desc;


A1, a2 was bought what ah, see


A1, a2 is the table of the nickname, because to A table with two times in A row, so make up the individual said a1, a2, to distinguish
  • Related