tags:

views:

29

answers:

1

=================

This is my query:

SELECT 
SUM(sub_total) AS sales,
CASE    WHEN (sub_total<100) THEN '0-99'    
    WHEN (sub_total>=100 AND sub_total<200) THEN '100-199'  
    WHEN (sub_total>=200 AND sub_total<300) THEN '200-299'  
    WHEN (sub_total>=300 AND sub_total<400) THEN '300-399'  
    WHEN (sub_total>=400 AND sub_total<500) THEN '400-499'  
    ELSE '500+'
END
AS product_sales_range
FROM order_item 
GROUP BY sub_total

========================

It gives the ressult as:

sales       product_sales_range
-----       -------------------

10398.96        200-299
600         100-199
300         0-99
7699.78     300-399
6799.32     100-199
600         0-99
26599.24        500+

==========================================

I would like to get the result like this :

sales       product_sales_range sales_increase_by_10%   sales_increase_by_20%
-----       ------------------- ------------------  ------------------

10398.96        200-299
600         100-199
300         0-99
7699.78     300-399
6799.32     100-199
600         0-99
26599.24        500+

============

Requirement:

Currently we have sales figures. Need to find out the sales projection as if the sales will be increased by 10%, 20%, 30% etc. Example: today the sales for product_sales_range (0-99) is 300. If the sales is increased by 10%, sales_increase_by_10% should be 330

+2  A: 

Am I missing something, or do you just need to use:

  SELECT SUM(sub_total) AS sales,
         CASE WHEN (sub_total<100) THEN '0-99' 
              WHEN (sub_total>=100 AND sub_total<200) THEN '100-199' 
              WHEN (sub_total>=200 AND sub_total<300) THEN '200-299' 
              WHEN (sub_total>=300 AND sub_total<400) THEN '300-399' 
              WHEN (sub_total>=400 AND sub_total<500) THEN '400-499' 
              ELSE '500+'
         END AS product_sales_range,
         SUM(sub_total) * 1.1 AS sales_increase_by_10Percent,
         SUM(sub_total) * 1.2 AS sales_increase_by_20Percent
    FROM order_item 
GROUP BY sub_total
OMG Ponies
wonderful.. thats what exactly i needed. thanks a lot and greatly appreciate it