Note that there are some explanatory texts on larger screens.

plurals
  1. POSplitting data into a per-year basis using SQL with pivots
    primarykey
    data
    text
    <p>I'm having some trouble figuring out how construct a series of SQL statements to split some data I have into a per-year basis. There are n items which have a recorded quantity for a set of days across so many years. Here's is a a small sample layout for the main data I have.</p> <pre><code> |========|==============|===========| | Name | Date | Quantity | |========|==============|===========| 1 | AAAAA | 10-DEC-2008 | 5 | 2 | AAAAA | 11-DEC-2008 | 2 | 3 | AAAAA | 12-DEC-2008 | 0 | 4 | AAAAA | 09-DEC-2009 | 3 | 5 | AAAAA | 10-DEC-2009 | 2 | 6 | AAAAA | 11-DEC-2009 | 3 | 7 | BBBBB | 10-DEC-2008 | 5 | 8 | BBBBB | 11-DEC-2008 | 2 | 9 | BBBBB | 12-DEC-2008 | 0 | 10 | BBBBB | 09-DEC-2009 | 3 | 11 | BBBBB | 10-DEC-2009 | 1 | 12 | BBBBB | 11-DEC-2009 | 0 | |========|==============|===========| </code></pre> <p>I need to convert this into a table which takes the form.</p> <pre><code> |========|==============|===============|===============| | Name | Date | Quantity 2008 | Quantity 2009 | |========|==============|===============|===============| 1 | AAAAA | 09-DEC | | 3 | 2 | AAAAA | 10-DEC | 5 | 2 | 3 | AAAAA | 11-DEC | 2 | 3 | 4 | AAAAA | 12-DEC | 0 | | 5 | BBBBB | 09-DEC | | 3 | 6 | BBBBB | 10-DEC | 5 | 1 | 7 | BBBBB | 11-DEC | 2 | 0 | 8 | BBBBB | 12-DEC | 0 | | |========|==============|===============|===============| </code></pre> <p>It should be assumed that there are thousands of named items in the database and the start days of recording on each year will be different, E.G., 6th Dec 2010 and 5th Dec 2009.</p> <p>Hope someone can help.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload