sql - logic to split revenue data by account if there are multiple data points -
First of all, the SQL Noob is here so that I do not understand my question.
In Table 1 there is an ID and the name (table I want to add data) is a large table with 2 million data points, from which I need to draw revenue information.
There is a detidency in Table 2, which I change in months and years. In some way, I want to gather months and years in a quarter year and how far I have got it. I need to keep this script as below, but have just modified a bit.
So in the end I have to get revenue on the basis of product and quarterly basis. What am I missing? Month period_idtoid (t1.date_id, DATEID, MONTHOFYEAR) month, - - year period_idtoid
here my script
select t1.nameid, t1.date_id, As the year (T1.date_id, DATEID, YEARID), select t1.month, t1.year in case when month (1,2,3) and year = 2012 then 'Q1 2012' WHEN in month (4, 5, 6) and year = 2012 then 'Q2 2012' when month (7,8,9) and year = 2012 then 'Question 3 2012' month (10, 11, 12) and year = 2012 again 'Question 4 2012 'Where in the month (1,2,3) and year = 2013 then' Q1 2013 'when month (4,5,6) and year = 2013 then' Q2 2013 'when month (7,8,9) and Year = 201 3 'Q3 2013' in months (10, 11, 12) and year = 2013 then 'Q4 2013' month (1,2,3) and year = 2013 then 'Q1 2014' when in the month (4,5, 6) and year = 2013 then 'Kwa 2 2014' as 'Quarter' from ADS 'Big Table T1' (cases when product_group = 'dog food' revenues then revenues other 0 end) dog_food_spend, sum (case when product_grou P = 'Cat food' then revenues any other end), in the form of cat_food_spend, the sum is the case (when product_group = 'parrot meal' then any other revenues end) as parrot_food_spend, table 2 t1 to t1.nameid = t2 Joining Table 1 t2 on nameid Group of 1,2,3,4,5
T-SQL and SQL assuming the server and Det_aid a SQL Dettaim:
SELECT Product_group, the amount as revenue (revenue), quarter + '+ convert (considered (4), as the summer) quarter (SELECT bt.product_group, amount (isnull (bt.revenue, 0)), year in the form of year (r.date_id), month (r.date_id) as the month, when the month (r. Date_id) ('1,2,3)' in 'Q1' month (r.date_id) (4,5,6) then 'Q2' when month (r.date_id (7,8,9) then 'Q3' and 'Q4' in the form of Quarter end with revenue R LEFT JOIN BigTable BT on R. IDEED = BT. NAID Group by B.T.Product_Group, Year (RD Ate_id), Month (r.date_id)) Group by ProductGroup, Year, Quarter
Comments
Post a Comment