sadxasds

July 13, 2017 | Author: mohit_bansal_15 | Category: Data Management, Sql, Data Management Software, Databases, Software
Share Embed Donate


Short Description

saddasdas...

Description

Assignment Questions

1. Select only those IMS_ids with specialty group “OTHER” mapped to territory “C60401” and “C60402” Solution: As per my understanding, we have to filter out those ims ids which are in speacilaty group ‘other’ and are mapped to either of ‘C60401’ or ‘C60402’.

Select d2.ims_id from training_data2 as d2 Inner join training_data4 on as d4 On d2.spec = d4.ims_specialty Where d4.specialty_group = ‘Other’ And d2.territory_id in (‘C60401’ , ‘C60402’)

2. Generate a table to map TRx_Qtys to territories. Use this table to sum the sales at territory level for different months. Solution:

Select d2.territory_id, d3.TRX_Qty, 3.cal_dt from training_data2 as d2 Inner join training_data3 as d3 On d2.ims_id = d3.ims_id Into q2 Select territory_id, sum (TRX_Qty), month (cal_dt) From q2 Group by territory_id, month (cal_dt)

3. Average the sales for all territories after including IMS_IDs only with specialty “ADM” and “AI” month-wise Solution:

Select d2.territory_id, d2.spec, sum (d3.TRX_Qty), d3.cal_dt from training_data2 as d2 Inner join training_data3 as d3 On d2.ims_id = d3.ims_id Where d2.spec in (‘ADM’, ‘AI’) Group by d2.territory_id, d2.spec , month (d3.cal_dt)

4. Sum the sales for all territories with target_flag “Y” and cal_dt greater than June 2012 Solution: Select d2.territory_id, d3.trgt_flg, sum (d3.TRX_Qty), d3.cal_dt from training_data2 as d2 Inner join training_data3 as d3 On d2.ims_id = d3.ims_id Where d3.trgt_flg = ‘Y’ And d3.cal_dt > ‘7/1/2012’ Group by d2.territory_id, d3.trgt_flg, d3.cal_dt

5. Get the count of IMS IDs in various specialty groups Solution: Select count (d2.ims_id), d4.specialty_group from training_data2 as d2 Inner join training_data4 as d4 On d2.spec = d4.ims_specialty Group by d4.specialty_group

6. Get a unique list of IMS_IDs listed in these data-sets. Map sales for Oct-2012 to these IMS_Ids Solution: Select d2.ims_id, d3.ims_id, sum (d3.TRX_Qty), d3.cal_dt from training_data2 as d2 outer join training_data3 as d3 On d2.ims_id = d3.ims_id Into q6 Where d3.cal_dt = ‘10/1/2012’ Group by d2.ims_id, d3.ims_id

7. Count the number of Targets in territory “C60401”. Solution: Select count (d2.ims_id), d2.territory_id, d3.trgt_flg from training_data2 as d2 inner join training_data3 as d3 On d2.ims_id = d3.ims_id

Where d3.territory_id = ‘c60401’ And d3.trgt_flg = ‘y’ Group by d2.territory_id, d3.trgt_flg

8. Find the Territory with maximum number of Targets. Also report its total TRx_Qty Solution: Select count(d2.ims_id), d2.territory_id, sum(d3.TRX_Qty), d3.trgt_flg from training_data2 as d2 inner join training_data3 as d3 On d2.ims_id = d3.ims_id Into q_8 Where d3.trgt_flg = ‘y’ Group by d2.territory_id, d3.trgt_flg Order by sum(d3.TRX_Qty) desc Select top 1 * from q_8

9. Update table “training_data3” to include a column of Specialty codes. Solution: Update training_data3 Set d3.specialty_group = d5.specialty_group from training_data3 as d3 inner join (Select d2.ims_id, d4.specialty_group from training_data2 as d2 Inner join training_data4 on as d4 On d2.spec = d4.ims_specialty) as d5

10. Get the Territory_Id and Specialty code for the IMS_id which have maximum TRx_Qty Solution: Select d2.ims_id, d2.territory_id, d2.spec, sum(d3.TRX_Qty) from training_data2 as d2 right outer join training_data3 as d3 On d2.ims_id = d3.ims_id Into q_10 Where d3.trgt_flg = ‘y’ Group by d2.ims_id, d2.territory_id, d2.spec Order by sum(d3.TRX_Qty) desc

Select top 1 * from q_10

11. List all the IMS_IDs that have no sales. Solution: Select d2.ims_id, d3.ims_id, isnull(sum(d3.TRX_Qty),’0’) from training_data2 as d2 full outer join training_data3 as d3 On d2.ims_id = d3.ims_id Group by d2.ims_id, d3.ims_id having sum(d3.trx_qty) = ‘0’

12. Count the number of territories with no sales. Solution: Select count (d12.territory_id) from (Select d2.territory_id, isnull(sum(d3.TRX_Qty),’0’) from training_data2 as d2 left outer join training_data3 as d3 On d2.ims_id = d3.ims_id Group by d2.territory_id having sum(d3.trx_qty) = ‘0’) as d12

13. Count the total no of Territories, where sales is greater than 500. Solution: Select count (d13.territory_id) from (Select d2.territory_id, isnull(sum(d3.TRX_Qty),’0’) from training_data2 as d2 left outer join training_data3 as d3 On d2.ims_id = d3.ims_id Group by d2.territory_id having sum(d3.trx_qty) > 500) as d13

14. Count the no of sales in Territory “C60402”, where sales are greater than 50 Solution: Select count (d14.sales) from (Select d2.territory_id, isnull (d3.TRX_Qty),’0’) from training_data2 as d2 left outer join training_data3 as d3 On d2.ims_id = d3.ims_id Where d2.territory_id = ‘c60402’ And d3.trx_qty > 50) as d14

15. List All IMS_ids with their sales. If there are no sales report it as Zero. Solution: Select d2.ims_id, d3.ims_id, isnull(sum(d3.TRX_Qty),’0’) from training_data2 as d2 full outer join training_data3 as d3 On d2.ims_id = d3.ims_id Into q_11 Group by d2.ims_id, d3.ims_id

View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF