mysql - Getting all items without open end date -


i need solve following problem using (my)sql, given example table:

id | item | start      | end 1  | 100  | 2015-01-01 | 2015-01-14 2  | 100  | 2015-01-01 | null 3  | 101  | 2015-03-01 | 2015-04-15 4  | 101  | 2015-04-17 | 2015-04-22 5  | 101  | 2015-04-27 | 2015-05-11 

i need query gives me items there no open end date. above i'd expect 101.

i tried group , sub-selects didn't show expected. on this?

you can using group by , having:

select item example group item having count(end) = count(*); 

count() column names counts number of non-null values. if equal number of rows, no values null.

you use:

having sum(end null) = 0 

edit:

i should add following might faster, assuming have right indexes , table items:

select i.item items not exists (select 1                   example e                   i.item = e.item , e.end null                  ); 

for performance, want index on example(item, end).


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -