php - Select min value with specific where filters MYSQL -


i have little trouble subquery. try take nearest event in table min value, need confirmed (confirmed = 1 , cancelled = 0)

there's table :

uid | location | date         | open    | close  | confirmed |  1   |  aaa     |  2015-05-11  |  12:00  |  14:30 |  1        | 2   |  aaa     |  2015-05-12  |  15:00  |  22:30 |  0        | 3   |  aaa     |  2015-05-15  |  11:00  |  18:30 |  0        | 4   |  aaa     |  2015-05-16  |  09:00  |  16:00 |  1        | 

and there query : ($now php date of current hour (h:i) , $today php date in format y-m-d)

select location, min(date)  table confirmed = 1 , if (     (close > '$now' , date = '$today') or (date> '$today'), 1, 0 ) group location 

so in test format, may 11 @ 17:00. first 1 shouldn't selected because happened in past (this morning) , second 1 should not selected because put confirmed 0

the expected result is

aaa  | 2015-05-16 

because nearest confirm true,

but returns me

aaa  | 2015-05-12 

it doesn't care statement of confirmed = 1, cares if (close > '$now' , date = '$today') or (date> '$today'), 1, 0 because returns me second one.

can provide me please?

p.s.: it's in mysql

thank you.

-- carlos

edit :::

i tried add value in select (select *, min(date))

and returns me asymetric data ???

i got

| 4  | aaa  | 2015-05-16 | 09:00 | 16:00 | 1 | 2015-05-12 

so first date 1 , second 1 (with min()) isn't one.

last edit :::

as suggested spencer7593 (thanks him/her), removed min(date) , automatically returns me data want, sql :

select *  table confirmed = 1 , if (     (close > '$now' , date = '$today') or (date> '$today'), 1, 0 ) group location 

try this:

select location, min(date)  table confirmed = 1 , ((close > '$now' , date = '$today') or (date> '$today')) group location 

maybe if statement making behavior wrong.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -