Sunday 15 January 2012

mysql - Select rows where total elapsed value is less than or equal to -



mysql - Select rows where total elapsed value is less than or equal to -

id | name | elapsed 1 james 0 2 john 60 3 kerry 60 4 janet 60 5 katie 60

based on results above , how can select names 'elapsed' value total less or equal 120? results, involve selecting names 'james', 'john' , 'kerry'. if changed total elapsed 180 select 'janet'.

how can build query returns this?

this should work:

select t1.id, t1.name, t1.elapsed your_table t1 inner bring together your_table t2 on (t1.id >= t2.id) grouping t1.id, t1.name, t1.elapsed having sum(t2.elapsed) <= 120

mysql sql innodb

No comments:

Post a Comment