Yet another SQL question
December 20, 2010 8:14 AM Subscribe
How can I change this SQL query?
posted by jfricke to computers & internet (6 answers total) 1 user marked this as a favorite
Our inventory management program allows the export of data via SQL. We already have a script which to display the sales of all items within a certain time period (see below). I would like to modify this script so that I can use it to show within one table how much we sold of an item within every week or every day of a year.
Note: My SQL skills are very limited, so please explain to me this as simple as possible.
The current script:
SELECT ARTIKEL.KURZNAME AS ITEM, SUM(JOURNALPOS.MENGE) AS SOLD
INNER JOIN ARTIKEL
ON ARTIKEL.REC_ID = JOURNALPOS.ARTIKEL_ID
INNER JOIN JOURNAL
ON JOURNAL.REC_ID = JOURNALPOS.JOURNAL_ID
WHERE JOURNAL.RDATUM BETWEEN '2010-12-01' AND '2011-12-15' AND JOURNAL.STADIUM = 2
GROUP BY ARTIKEL.REC_ID
ORDER BY ARTIKEL.KURZNAME
ITEM | SOLD
Item 1 | 8393
Item 2 | 8997
What I want is this:
ITEM | 2010-12-01 | 2010-12-02 | 2010-12-03 | ...
Item 1 | 87 | 89 | 67 | ...
Item 2 | 997 | 89 | 88 | ...
Thanks a lot!