php - SQL: How to select one record per day, assuming that each day contain more than 1 value MySQL -


i want select records '2013-04-01 00:00:00' 'today' but, each day has lot of value, because saving each 15 minutes value, want first or last value each day.

table schema:

create table if not exists `value_magnitudes` (   `id` int(11) not null auto_increment,   `value` float default null,   `magnitude_id` int(11) default null,   `sdi_belongs_id` varchar(255) collate utf8_unicode_ci default null,   `reading_date` datetime default null,   `created_at` datetime default null,   `updated_at` datetime default null,   primary key (`id`) ) engine=innodb  default charset=utf8 collate=utf8_unicode_ci auto_increment=1118402 ; 

bad sql:

select value `value_magnitudes` `value_magnitudes`.`reading_date` between '2013-04-01 00:00:00' , '2013-04-02 00:00:00' , (`value_magnitudes`.magnitude_id = 234) limit 1 select value `value_magnitudes` `value_magnitudes`.`reading_date` between '2013-04-02 00:00:00' , '2013-04-03 00:00:00' , (`value_magnitudes`.magnitude_id = 234) limit 1 select value `value_magnitudes` `value_magnitudes`.`reading_date` between '2013-04-03 00:00:00' , '2013-04-04 00:00:00' , (`value_magnitudes`.magnitude_id = 234) limit 1 select value `value_magnitudes` `value_magnitudes`.`reading_date` between '2013-04-04 00:00:00' , '2013-04-05 00:00:00' , (`value_magnitudes`.magnitude_id = 234) limit 1 select value `value_magnitudes` `value_magnitudes`.`reading_date` between '2013-04-05 00:00:00' , '2013-04-06 00:00:00' , (`value_magnitudes`.magnitude_id = 234) limit 1 etc ... 

i want in 1 if possible...

thank lot.

edit: mean, have query per day, want make single query reading_date >= '2013-04-01 00:00:00'c

edit2: have 64,260 records in table.value_magnitudes , takes sooooooooo long excecute , response query, , timeout conection.

to first entry every date can do

select * value_magnitudes id in  (     select min(id)     value_magnitudes     magnitude_id = 234     , date(reading_date) >= '2013-04-01'     group date(reading_date) ) 

Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -