0

Example of my data:

+----------+--------+------------+-------------------+
| Category | Orders |   Units    |       Value       |
+----------+--------+------------+-------------------+
| RED      |    165 | 9,376,638  | $723,544,659.20   |
| BLUE     |    106 | 6,709,972  | $421,713,725.59   |
| ORANGE   |    136 | 6,118,278  | $229,171,543.85   |
| GREEN    |     25 | 1,281,459  | $52,194,155.69    |
| OTHER    |     17 | 301,056    | $9,493,416.87     |
| Totals   |    449 | 23,787,403 | $1,436,117,501.20 |
+----------+--------+------------+-------------------+

This works:

, SUM(red) *1.0 / count(*) as red_perc

But when I try to find the percentage of each based on the value instead of the Units, I don't get a percentage, the number comes out to 1710688.272437

, SUM(red_total) *1.0 / count(*) as red_value_perc

Can anybody spot where I'm going wrong? I don't understand why one works and one doesn't.

SqlZim
  • 37,248
  • 6
  • 41
  • 59
EP31121PJ
  • 95
  • 2
  • 9
  • Which DBMS are you using? Postgres? Oracle? DB2? Firebird? –  Apr 27 '17 at 20:32
  • 3
    `red` isn't a column name, so I don't understand how the first one works. – SqlZim Apr 27 '17 at 20:33
  • I was using the wrong divisor in the second equation, I needed to use the sum instead of count. I figured it out, thanks for taking a look! – EP31121PJ Apr 29 '17 at 13:51

0 Answers0