Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to create a crosstab query 1

Status
Not open for further replies.

btamsgn

Instructor
Jan 17, 2011
10
0
0
VN
Hi ACE,
I have a table 2 column as follows: dsname and NH
dsName NH
Á Bằng Kim
An Bình Moc
An Khang Kim
Ân Tuấn Thuy
Anh Đức Moc
Anh Duy Kim
......
I want to create a crosstab query as follows:
vd_lfvymw.png

Pls find the attachment for your ref.
Thank you.
 
 https://files.engineering.com/getfile.aspx?folder=5cd85c6d-9e96-450e-9cb9-5b28bb33c7c1&file=Database1.accdb
I would first create a helper query that does a group by and counts to get the STT value which is in alpha order. I don't know where you get the STT values.

Code:
SELECT Count(T_Hs.NH) AS STT, T_Hs.dsName, T_Hs.NH
FROM T_Hs AS T_Hs_1 INNER JOIN T_Hs ON T_Hs_1.NH = T_Hs.NH
WHERE (((T_Hs.dsname)>=[t_hs_1].[dsName]))
GROUP BY T_Hs.dsName, T_Hs.NH;

Then use that query as the source for your crosstab:

Code:
TRANSFORM Min(qgrpForCrosstab.dsName) AS MinOfdsName
SELECT qgrpForCrosstab.STT
FROM qgrpForCrosstab
GROUP BY qgrpForCrosstab.STT
PIVOT qgrpForCrosstab.NH;

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top