sql - Pivoting data in MS Access -


i have query i've created pull student ids , meal items have taken on month long period. count numbers of each item (breakfast, lunch, snack) taken student on course of month.

it appears there's data access handle in pivot table report, hoping there sql query run instead.

here's current query i've created:

select april2013.sid, menuitems.mealtype apr2013meal   april2013 left join menuitems on menuitems.item=april2013.item;   

current output:

+-----+-----------+   | sid |   meal    |   +-----+-----------+   | 001 | lunch     |   | 002 | lunch     |   | 003 | breakfast |   | 004 | snack     |   | 005 | lunch     | | 006 | lunch     |   | 001 | breakfast |   | 003 | snack     |   | 004 | breakfast |   +-----+-----------+ 

here's how i'd look:

+-----+-----------+-------+---------+   | sid | breakfast | lunch | snack   |   +-----+-----------+-------+---------+   | 001 |         3 |    10 |     1   |   | 002 |         4 |     8 |    10   |   | 003 |        18 |     2 |     7   |   | 004 |         6 |     7 |     2   |   +-----+-----------+-------+---------+   

you can pivot data using transform:

transform count(menuitems.mealtype) select april2013.sid, menuitems.mealtype april2013  left join menuitems    on menuitems.item=april2013.item group april2013.sid pivot menuitems.mealtype;  

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -