summ year bsed agency and date

User avatar
sal21
PlatinumLounger
Posts: 4368
Joined: 26 Apr 2010, 17:36

summ year bsed agency and date

Post by sal21 »

In the sheet attached is the strucure of my access table (in yellow).
I want a query to count how many year are for each agency. (result in green)

User avatar
HansV
Administrator
Posts: 78620
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: summ year bsed agency and date

Post by HansV »

This is called a crosstab query.
- Create a query in design view based on your table.
- Add the Agency field.
- Add a calculated column

A: Year([YEAR])

- Add the YEAR field.
- Select Query | Crosstab Query.
- In the Totals row, select Count for the third column.
- In the Crosstab row, select Row for the first column, Column for the second column, and Value for the third column.
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4368
Joined: 26 Apr 2010, 17:36

Re: summ year bsed agency and date

Post by sal21 »

HansV wrote:This is called a crosstab query.
- Create a query in design view based on your table.
- Add the Agency field.
- Add a calculated column

A: Year([YEAR])

- Add the YEAR field.
- Select Query | Crosstab Query.
- In the Totals row, select Count for the third column.
- In the Crosstab row, select Row for the first column, Column for the second column, and Value for the third column.
TABELLA = my table
TIPO_DATO is a filter
SPORT=Agency
DATA_ACC = date in format dd/mm/yyyy

SQL = "SELECT SPORT, DATA_ACC, COUNT(*) FROM " & TABELLA & " WHERE TIPO_DATO='" & TIPO_DAT & "' GROUP BY SPORT, DATA_ACC ORDER BY SPORT, DATA_ACC"

the query return a value and summ, but not is correct...
in effect the query return agency the day date and count...

User avatar
HansV
Administrator
Posts: 78620
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: summ year bsed agency and date

Post by HansV »

You haven't created a crosstab query.

Please create the query in design view in Access and follow my instructions. Don't forget to make it a crosstab query!
When it works correctly, select View | SQL and look at the SQL generated by Access. You can use this in your SQL string.
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4368
Joined: 26 Apr 2010, 17:36

Re: summ year bsed agency and date

Post by sal21 »

ok... resolved with design view in Access and with a little modify!
tks.