Add weeks in a query?
Posted on
16th Feb 2014 07:03 pm by
admin
I have a SQL that summarizes the quantity per week. The weeks that has no value does not exist in the table. How can I add these missing weeks with a 0 value in the SQL. Need this to use Avg and stddev functions.
SELECT t.material, t.description,
Sum(t.sales_quantity ) qty, to_char(t.Posting_Date,'IYYYIW') year_week
FROM tblBilling t
Where t.material = 'label900'
And t.Posting_date >= to_date('2008-10-20','yyyy-mm-dd')
And t.Posting_date <= to_date('2009-10-20','yyyy-mm-dd')
Group By t.material, t.description, to_char(t.Posting_Date,'IYYYIW')
This return:
Did you know?Explore Trending and Topic pages for more stories like this.
material descriotion qty year_week
label900 test 20000 200850
label900 test 10000 200910
label900 test 5000 200912
label900 test 6000 200914
label900 test 9000 200920
I want it to complement the missing weeks with 0. Like this:
material descriotion qty year_week
label900 test 0 200843
label900 test 0 200844
label900 test 0 200845
label900 test 0 200846
label900 test 0 200847
label900 test 0 200848
label900 test 0 200849
label900 test 20000 200850
label900 test 0 200851
--and so on
Your Answer:
Login to answer
66
46
Other forums
Why does my crawler script suddenly end with no error?
Hi.
I have written a web crawler script. It will visit a large number of URL's with cURL.
About imagecopyresampled()
Hello,
I am looking to use this function to resize parts of an image to a fixed thumbnail siz
PHP Upload issue
Hi guys,
I have stumble across an interesting issue with my script and is doing my head in.
PHP MySQL Return Results Issue
Hi guys,
I'm running joomla and made a module which is using ajax.
Basically i just have a
Curl timeout breaks script
So im having difficulties with skipping timeout error in curl
my script calls different functions
Namespace Problem
I'm having problem with a section of code with a variable namespace.
This code works fine:
delete comma
HI,
How to delete "," at the end of the string.
Code: $match = 2009/02/03/a2corr
Multi Level Array Problem
hi all,
For example I have array like below:
$temp = array(array('north america', 'us'
Optimize Code
Just started getting into the use of cookies. The following code will redirect users to a set URL s
Retreiving objects from Sessions
Hi all,
I am getting really frustrated with storing and retreiving objects from a session. Bu