A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Crosstab query Help



 
 
Thread Tools Display Modes
  #1  
Old February 23rd, 2007, 07:56 PM posted to microsoft.public.access.queries
Elena
external usenet poster
 
Posts: 105
Default Crosstab query Help

Hi, All
I need help with query for the report;
table has following fields

Plate Location MarkDate MarkTime Shield
-------------------------------------------------------
12AB Main St 02/23/07 11:00 801
34CD West St 02/23/07 12:15 801
12AB Main St 02/23/07 14:00 801
12AB Main St 02/23/07 14:30 801
---------------------------------------------------------

I need to produce output for the report like this:
Date Location Plate MTime1 MTime2 MTime3
------------------------------------------------------------------
02/23/07 Main St 12AB 11:00 14:00 14:30
02/23/07 West St 34CD 12:15

I don't know how to define fields in output from the query...

TRANSFORM First(t.MarkTime) AS FirstOfTime
SELECT t.MarkDate, t.Location, t.Plate
FROM t
GROUP BY t.MarkDate, t.Location, t.Plate
PIVOT t.MarkTime IN ("MTime1", "MTime2", "MTime3")

  #2  
Old February 23rd, 2007, 08:43 PM posted to microsoft.public.access.queries
Michel Walsh
external usenet poster
 
Posts: 2,404
Default Crosstab query Help

A crosstab supply new field based on values stored in a field. Since you
don't have MTime1, MTime2 and MTime3 as values, already, a crosstab is not
really the solution to use. If it was not for MTime2, a possible solution
could have been:


SELECT theDate, Location, Plate, MIN(MarkTime) AS MTime1, MAX(MarkTime) AS
MTime3
FROM myTable
GROUP BY theDate, Location, Plate

(and there will be also the problem that MTime3 can be equal to MTime1,
rather than being null, as you have sketched the desired result, but I
assume this is not a major problem).

Sure, if you can use the AVERAGE rather than a third time, for MTime2, that
would be already almost done:

SELECT theDate, Location, Plate, MIN(MarkTime) AS MTime1, AVG(MarkTime) AS
MTIime2, MAX(MarkTime) AS MTime3
FROM myTable
GROUP BY theDate, Location, Plate


but if there is more than three MarkTIme, for a plate, for a given date,
what we do, as example, if there is a fourth record about Plate=12AB for
02/23/2007 ?


Vanderghast, Access MVP



"elena" wrote in message
...
Hi, All
I need help with query for the report;
table has following fields

Plate Location MarkDate MarkTime Shield
-------------------------------------------------------
12AB Main St 02/23/07 11:00 801
34CD West St 02/23/07 12:15 801
12AB Main St 02/23/07 14:00 801
12AB Main St 02/23/07 14:30 801
---------------------------------------------------------

I need to produce output for the report like this:
Date Location Plate MTime1 MTime2 MTime3
------------------------------------------------------------------
02/23/07 Main St 12AB 11:00 14:00 14:30
02/23/07 West St 34CD 12:15

I don't know how to define fields in output from the query...

TRANSFORM First(t.MarkTime) AS FirstOfTime
SELECT t.MarkDate, t.Location, t.Plate
FROM t
GROUP BY t.MarkDate, t.Location, t.Plate
PIVOT t.MarkTime IN ("MTime1", "MTime2", "MTime3")



  #3  
Old February 23rd, 2007, 09:35 PM posted to microsoft.public.access.queries
Elena
external usenet poster
 
Posts: 105
Default Crosstab query Help

Michel,
Thank you for reply, i agree that it possible to have fourth record with the
same
plate and location and different marktime...
But any way how to achive the output result in that case?

Thank you,


"Michel Walsh" wrote:

A crosstab supply new field based on values stored in a field. Since you
don't have MTime1, MTime2 and MTime3 as values, already, a crosstab is not
really the solution to use. If it was not for MTime2, a possible solution
could have been:


SELECT theDate, Location, Plate, MIN(MarkTime) AS MTime1, MAX(MarkTime) AS
MTime3
FROM myTable
GROUP BY theDate, Location, Plate

(and there will be also the problem that MTime3 can be equal to MTime1,
rather than being null, as you have sketched the desired result, but I
assume this is not a major problem).

Sure, if you can use the AVERAGE rather than a third time, for MTime2, that
would be already almost done:

SELECT theDate, Location, Plate, MIN(MarkTime) AS MTime1, AVG(MarkTime) AS
MTIime2, MAX(MarkTime) AS MTime3
FROM myTable
GROUP BY theDate, Location, Plate


but if there is more than three MarkTIme, for a plate, for a given date,
what we do, as example, if there is a fourth record about Plate=12AB for
02/23/2007 ?


Vanderghast, Access MVP



"elena" wrote in message
...
Hi, All
I need help with query for the report;
table has following fields

Plate Location MarkDate MarkTime Shield
-------------------------------------------------------
12AB Main St 02/23/07 11:00 801
34CD West St 02/23/07 12:15 801
12AB Main St 02/23/07 14:00 801
12AB Main St 02/23/07 14:30 801
---------------------------------------------------------

I need to produce output for the report like this:
Date Location Plate MTime1 MTime2 MTime3
------------------------------------------------------------------
02/23/07 Main St 12AB 11:00 14:00 14:30
02/23/07 West St 34CD 12:15

I don't know how to define fields in output from the query...

TRANSFORM First(t.MarkTime) AS FirstOfTime
SELECT t.MarkDate, t.Location, t.Plate
FROM t
GROUP BY t.MarkDate, t.Location, t.Plate
PIVOT t.MarkTime IN ("MTime1", "MTime2", "MTime3")




  #4  
Old February 23rd, 2007, 09:56 PM posted to microsoft.public.access.queries
Duane Hookom
external usenet poster
 
Posts: 7,177
Default Crosstab query Help

Try this SQL

TRANSFORM First(t.MarkTime) AS FirstOfMarkTime
SELECT t.MarkDate, t.Location, t.Plate
FROM t
GROUP BY t.MarkDate, t.Location, t.Plate
PIVOT "MTime" & DCount("*","t","Location='" & [Location] & "' AND
MarkDate=#" & [MarkDate] & "# AND MarkTime =#" & [MarkTIme] & "#");

--
Duane Hookom
Microsoft Access MVP


"elena" wrote:

Michel,
Thank you for reply, i agree that it possible to have fourth record with the
same
plate and location and different marktime...
But any way how to achive the output result in that case?

Thank you,


"Michel Walsh" wrote:

A crosstab supply new field based on values stored in a field. Since you
don't have MTime1, MTime2 and MTime3 as values, already, a crosstab is not
really the solution to use. If it was not for MTime2, a possible solution
could have been:


SELECT theDate, Location, Plate, MIN(MarkTime) AS MTime1, MAX(MarkTime) AS
MTime3
FROM myTable
GROUP BY theDate, Location, Plate

(and there will be also the problem that MTime3 can be equal to MTime1,
rather than being null, as you have sketched the desired result, but I
assume this is not a major problem).

Sure, if you can use the AVERAGE rather than a third time, for MTime2, that
would be already almost done:

SELECT theDate, Location, Plate, MIN(MarkTime) AS MTime1, AVG(MarkTime) AS
MTIime2, MAX(MarkTime) AS MTime3
FROM myTable
GROUP BY theDate, Location, Plate


but if there is more than three MarkTIme, for a plate, for a given date,
what we do, as example, if there is a fourth record about Plate=12AB for
02/23/2007 ?


Vanderghast, Access MVP



"elena" wrote in message
...
Hi, All
I need help with query for the report;
table has following fields

Plate Location MarkDate MarkTime Shield
-------------------------------------------------------
12AB Main St 02/23/07 11:00 801
34CD West St 02/23/07 12:15 801
12AB Main St 02/23/07 14:00 801
12AB Main St 02/23/07 14:30 801
---------------------------------------------------------

I need to produce output for the report like this:
Date Location Plate MTime1 MTime2 MTime3
------------------------------------------------------------------
02/23/07 Main St 12AB 11:00 14:00 14:30
02/23/07 West St 34CD 12:15

I don't know how to define fields in output from the query...

TRANSFORM First(t.MarkTime) AS FirstOfTime
SELECT t.MarkDate, t.Location, t.Plate
FROM t
GROUP BY t.MarkDate, t.Location, t.Plate
PIVOT t.MarkTime IN ("MTime1", "MTime2", "MTime3")




  #5  
Old February 26th, 2007, 02:28 PM posted to microsoft.public.access.queries
Elena
external usenet poster
 
Posts: 105
Default Crosstab query Help

Duane,
Thank you so much, it works the way i needed, thank you again!

"Duane Hookom" wrote:

Try this SQL

TRANSFORM First(t.MarkTime) AS FirstOfMarkTime
SELECT t.MarkDate, t.Location, t.Plate
FROM t
GROUP BY t.MarkDate, t.Location, t.Plate
PIVOT "MTime" & DCount("*","t","Location='" & [Location] & "' AND
MarkDate=#" & [MarkDate] & "# AND MarkTime =#" & [MarkTIme] & "#");

--
Duane Hookom
Microsoft Access MVP


"elena" wrote:

Michel,
Thank you for reply, i agree that it possible to have fourth record with the
same
plate and location and different marktime...
But any way how to achive the output result in that case?

Thank you,


"Michel Walsh" wrote:

A crosstab supply new field based on values stored in a field. Since you
don't have MTime1, MTime2 and MTime3 as values, already, a crosstab is not
really the solution to use. If it was not for MTime2, a possible solution
could have been:


SELECT theDate, Location, Plate, MIN(MarkTime) AS MTime1, MAX(MarkTime) AS
MTime3
FROM myTable
GROUP BY theDate, Location, Plate

(and there will be also the problem that MTime3 can be equal to MTime1,
rather than being null, as you have sketched the desired result, but I
assume this is not a major problem).

Sure, if you can use the AVERAGE rather than a third time, for MTime2, that
would be already almost done:

SELECT theDate, Location, Plate, MIN(MarkTime) AS MTime1, AVG(MarkTime) AS
MTIime2, MAX(MarkTime) AS MTime3
FROM myTable
GROUP BY theDate, Location, Plate


but if there is more than three MarkTIme, for a plate, for a given date,
what we do, as example, if there is a fourth record about Plate=12AB for
02/23/2007 ?


Vanderghast, Access MVP



"elena" wrote in message
...
Hi, All
I need help with query for the report;
table has following fields

Plate Location MarkDate MarkTime Shield
-------------------------------------------------------
12AB Main St 02/23/07 11:00 801
34CD West St 02/23/07 12:15 801
12AB Main St 02/23/07 14:00 801
12AB Main St 02/23/07 14:30 801
---------------------------------------------------------

I need to produce output for the report like this:
Date Location Plate MTime1 MTime2 MTime3
------------------------------------------------------------------
02/23/07 Main St 12AB 11:00 14:00 14:30
02/23/07 West St 34CD 12:15

I don't know how to define fields in output from the query...

TRANSFORM First(t.MarkTime) AS FirstOfTime
SELECT t.MarkDate, t.Location, t.Plate
FROM t
GROUP BY t.MarkDate, t.Location, t.Plate
PIVOT t.MarkTime IN ("MTime1", "MTime2", "MTime3")




 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 10:34 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.