select column name in mysql table -


hi have table named 'target_hours'. targets , given levels- field names (l1,l2,l3,l4,l5) have allocated , mentioned in table in hours follows.

|l1 | l2  | l3 | l4 | l5  | |---| --- | ---|--- |---  | |192| 168 | 144| 120| 96  | 

i need level (filed name) of specific work has been completed in specific hours using mysql query following below conditions. example lets take x hours.

l5 -->  l5 >= x hours  l4 -->  l4 >= x hours > l5  l3 -->  l3 >= x hours > l4  l2 -->  l2 >= x hours > l3   l1 -->  l1 >= x hours > l2  

as example if specific task completed in 135 hours, query should output l3.

while agree being symptom of poor design, 1 way solve bunch of unions:

select   lvl (   select l1 lvl limits   union   select l2 limits   union   select l3 limits   union   select l4 limits   union   select l5 limits   order     lvl asc ) x   lvl > 135 limit    0, 1 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -