views:

26

answers:

1

dear all..i have some data at DB.

name        Range
bla     123x9901-123x0000      //it means range 9901 until 10000 = 100
bla     123v0001-123v0100      // 10001-10100 = 100

i want the result like:

   name         Qty  
   bla          200

i counting them use:

SELECT................
      IF(RIGHT(Range,4) = "0000",10000,RIGHT(Range,4)) - MID(Range,5,4) + 1 AS Qty
FROM mytable GROUP BY name;

but the result:

name      Qty
bla       100
+1  A: 

Use:

  SELECT name,
         SUM(IF(RIGHT(Range,4) = "0000",10000, RIGHT(Range,4)) - MID(Range,5,4) + 1) AS Qty
    FROM mytable
GROUP BY name;

...gives me:

name    Qty  
-------------
bla     200
OMG Ponies
that's great..simple answer but usefull.
klox