MS Acess Cross Tab Query - Row to Column Transpose
up vote
0
down vote
favorite
Using cross tab query in MS Access SQL
how to transform table like this
===========================
|IND |LBL |TICKETS|
===========================
|1 |AM |101 |
|2 |AM |1 |
|1 |HR |102 |
|1 |TV |100 |
|2 |TV |2 |
===========================
to this
=======================
|LBL |IND1 |IND2|
=======================
|AM |101 |1 |
|HR |102 |0 |
|TV |100 |2 |
=======================
this is the query that i tried.
I think I have made some mistake in the crosstab query, if you could point out, it would be helpful
TRANSFORM First(TBL1.TICKETS) AS TCK
SELECT TBL1.LBL, First(TBL1.TICKETS) AS TCK1
from
(
SELECT IIF(A.AM= '[AM]' OR A.AM='[AM2]',1,2) AS IND
, 'AM' AS LBL
, COUNT(A.AM) AS TICKETS
FROM shree_main AS A GROUP BY IIF(A.AM='[AM]' OR A.AM='[AM2]',1,2), 'AM'
union all
SELECT IIF(A.Newpri= '[HR]' OR A.Newpri='[NML]' OR A.Newpri='[N2H]',1 ,2) AS IND, 'HR' AS LBL,
count([A].Newpri) AS TICKETS FROM shree_main AS A
GROUP BY IIF(A.Newpri= '[HR]' OR A.Newpri='[NML]' OR A.Newpri='[N2H]',1,2), 'HR'
union all
SELECT IIF(A.TV= '[SC]' OR A.TV='[TV]' OR A.TV='[TV][SC]' OR A.TV='[VE]',1 ,2) AS IND, 'TV' AS LBL, COUNT(A.TV) AS TICKETS FROM shree_main AS A GROUP BY IIF(A.TV= '[SC]' OR A.TV='[TV]' OR A.TV='[TV][SC]' OR A.TV='[VE]',1 ,2), 'TV'
) AS TBL1
GROUP BY TBL1.LBL, TBL1.LBL, TBL1.LBL, TBL1.LBL
PIVOT TBL1.LBL;
and this is the result of the query
LBL TCK1 AM HR TV
AM 1 101
HR 102 102
TV 2 100
ms-access-2010 crosstab
add a comment |
up vote
0
down vote
favorite
Using cross tab query in MS Access SQL
how to transform table like this
===========================
|IND |LBL |TICKETS|
===========================
|1 |AM |101 |
|2 |AM |1 |
|1 |HR |102 |
|1 |TV |100 |
|2 |TV |2 |
===========================
to this
=======================
|LBL |IND1 |IND2|
=======================
|AM |101 |1 |
|HR |102 |0 |
|TV |100 |2 |
=======================
this is the query that i tried.
I think I have made some mistake in the crosstab query, if you could point out, it would be helpful
TRANSFORM First(TBL1.TICKETS) AS TCK
SELECT TBL1.LBL, First(TBL1.TICKETS) AS TCK1
from
(
SELECT IIF(A.AM= '[AM]' OR A.AM='[AM2]',1,2) AS IND
, 'AM' AS LBL
, COUNT(A.AM) AS TICKETS
FROM shree_main AS A GROUP BY IIF(A.AM='[AM]' OR A.AM='[AM2]',1,2), 'AM'
union all
SELECT IIF(A.Newpri= '[HR]' OR A.Newpri='[NML]' OR A.Newpri='[N2H]',1 ,2) AS IND, 'HR' AS LBL,
count([A].Newpri) AS TICKETS FROM shree_main AS A
GROUP BY IIF(A.Newpri= '[HR]' OR A.Newpri='[NML]' OR A.Newpri='[N2H]',1,2), 'HR'
union all
SELECT IIF(A.TV= '[SC]' OR A.TV='[TV]' OR A.TV='[TV][SC]' OR A.TV='[VE]',1 ,2) AS IND, 'TV' AS LBL, COUNT(A.TV) AS TICKETS FROM shree_main AS A GROUP BY IIF(A.TV= '[SC]' OR A.TV='[TV]' OR A.TV='[TV][SC]' OR A.TV='[VE]',1 ,2), 'TV'
) AS TBL1
GROUP BY TBL1.LBL, TBL1.LBL, TBL1.LBL, TBL1.LBL
PIVOT TBL1.LBL;
and this is the result of the query
LBL TCK1 AM HR TV
AM 1 101
HR 102 102
TV 2 100
ms-access-2010 crosstab
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Using cross tab query in MS Access SQL
how to transform table like this
===========================
|IND |LBL |TICKETS|
===========================
|1 |AM |101 |
|2 |AM |1 |
|1 |HR |102 |
|1 |TV |100 |
|2 |TV |2 |
===========================
to this
=======================
|LBL |IND1 |IND2|
=======================
|AM |101 |1 |
|HR |102 |0 |
|TV |100 |2 |
=======================
this is the query that i tried.
I think I have made some mistake in the crosstab query, if you could point out, it would be helpful
TRANSFORM First(TBL1.TICKETS) AS TCK
SELECT TBL1.LBL, First(TBL1.TICKETS) AS TCK1
from
(
SELECT IIF(A.AM= '[AM]' OR A.AM='[AM2]',1,2) AS IND
, 'AM' AS LBL
, COUNT(A.AM) AS TICKETS
FROM shree_main AS A GROUP BY IIF(A.AM='[AM]' OR A.AM='[AM2]',1,2), 'AM'
union all
SELECT IIF(A.Newpri= '[HR]' OR A.Newpri='[NML]' OR A.Newpri='[N2H]',1 ,2) AS IND, 'HR' AS LBL,
count([A].Newpri) AS TICKETS FROM shree_main AS A
GROUP BY IIF(A.Newpri= '[HR]' OR A.Newpri='[NML]' OR A.Newpri='[N2H]',1,2), 'HR'
union all
SELECT IIF(A.TV= '[SC]' OR A.TV='[TV]' OR A.TV='[TV][SC]' OR A.TV='[VE]',1 ,2) AS IND, 'TV' AS LBL, COUNT(A.TV) AS TICKETS FROM shree_main AS A GROUP BY IIF(A.TV= '[SC]' OR A.TV='[TV]' OR A.TV='[TV][SC]' OR A.TV='[VE]',1 ,2), 'TV'
) AS TBL1
GROUP BY TBL1.LBL, TBL1.LBL, TBL1.LBL, TBL1.LBL
PIVOT TBL1.LBL;
and this is the result of the query
LBL TCK1 AM HR TV
AM 1 101
HR 102 102
TV 2 100
ms-access-2010 crosstab
Using cross tab query in MS Access SQL
how to transform table like this
===========================
|IND |LBL |TICKETS|
===========================
|1 |AM |101 |
|2 |AM |1 |
|1 |HR |102 |
|1 |TV |100 |
|2 |TV |2 |
===========================
to this
=======================
|LBL |IND1 |IND2|
=======================
|AM |101 |1 |
|HR |102 |0 |
|TV |100 |2 |
=======================
this is the query that i tried.
I think I have made some mistake in the crosstab query, if you could point out, it would be helpful
TRANSFORM First(TBL1.TICKETS) AS TCK
SELECT TBL1.LBL, First(TBL1.TICKETS) AS TCK1
from
(
SELECT IIF(A.AM= '[AM]' OR A.AM='[AM2]',1,2) AS IND
, 'AM' AS LBL
, COUNT(A.AM) AS TICKETS
FROM shree_main AS A GROUP BY IIF(A.AM='[AM]' OR A.AM='[AM2]',1,2), 'AM'
union all
SELECT IIF(A.Newpri= '[HR]' OR A.Newpri='[NML]' OR A.Newpri='[N2H]',1 ,2) AS IND, 'HR' AS LBL,
count([A].Newpri) AS TICKETS FROM shree_main AS A
GROUP BY IIF(A.Newpri= '[HR]' OR A.Newpri='[NML]' OR A.Newpri='[N2H]',1,2), 'HR'
union all
SELECT IIF(A.TV= '[SC]' OR A.TV='[TV]' OR A.TV='[TV][SC]' OR A.TV='[VE]',1 ,2) AS IND, 'TV' AS LBL, COUNT(A.TV) AS TICKETS FROM shree_main AS A GROUP BY IIF(A.TV= '[SC]' OR A.TV='[TV]' OR A.TV='[TV][SC]' OR A.TV='[VE]',1 ,2), 'TV'
) AS TBL1
GROUP BY TBL1.LBL, TBL1.LBL, TBL1.LBL, TBL1.LBL
PIVOT TBL1.LBL;
and this is the result of the query
LBL TCK1 AM HR TV
AM 1 101
HR 102 102
TV 2 100
ms-access-2010 crosstab
ms-access-2010 crosstab
edited Nov 11 at 18:19
asked Nov 11 at 18:05
user2959433
247
247
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53251651%2fms-acess-cross-tab-query-row-to-column-transpose%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown