Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Mysql cumulative total
Message
From
18/03/2011 07:29:14
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
01504071
Message ID:
01504073
Views:
43
Hi Sergey its mysql

but between posting and your reply I realised what I had done wrong.

t.pop and s2.pop aren't proper dates they are YYYYMM and that was not giving an error from datediff but was giving the wrong number

Thanks

>I'm confused, is it mysql or MS SQL Server?
>
>>
>>I'm trying to get a monthly cumulative total.
>>
>>I have sql that give me that but I need to refine it to only give me and in warranty cumulative total ie two years.
>>
>>So the cumulative total is a two year snapshot.
>>
>>My sql query is
>>
>>select pop AS yearmonth,
>>   ifnull((select sum(s2.stock_count) AS sum_stock_count
>>  from c_stock_month_model2 s2
>>  where  s2.pop <= t.pop ),0) AS cum_month_stock_count
>>  from c_stock_month_model t
>>  order by pop;
>>
>>
>>I tried adding a condition in the subquery
>>
>>
>>select pop AS yearmonth,
>>   ifnull((select sum(s2.stock_count) AS sum_stock_count
>>  from c_stock_month_model2 s2
>>  where  s2.pop <= t.pop
>>  and datediff(s2.pop,t.pop)<810),0) AS cum_month_stock_count
>>  from c_stock_month_model t
>>  order by pop;
>>
>>
>>but it still includes all the data.
>>
>>Any thoughts on a way to get this
>>
>>Thanks
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform