RE: Mode Function in Access

Tech-Archive recommends: Speed Up your PC by fixing your registry

From: ChrisJ (ChrisJ_at_discussions.microsoft.com)
Date: 11/17/04


Date: Wed, 17 Nov 2004 15:05:01 -0800

If you can send me the name of the table and the names of the fields and
perhaps some sample data, I can write the query for you and try it against
the sample data.

Send to
chris
at
mercury-projects
dot
co
dot
nz

"QVCJDN" wrote:

> Sorry for the delay, I just got back to this project. This looks like the
> direction that I need to go, but I'm afraid that I don't now SQL (it appears
> that that's your notation). My data looks just like you laid it out. A
> primary key (Control Number), followed by fields for Saturday through Friday.
> In each field will be a value for a work shift (1, 2, or 3). Depending on
> what shift the employee is assigned the most, the correct value would be
> returned. Could you explain your queries a bit more?
>
> Dave
>
> "ChrisJ" wrote:
>
> > Let's assume that your table has the fields
> >
> > PrimaryKey,
> > Field1
> > Field2
> > Field3
> > Field4
> > Field5
> > Field6
> > Field7
> >
> > I would create a query
> >
> > Select PrimaryKey, 'F1' as SourceField, Field1 as FieldData from YourTable
> > Union
> > Select PrimaryKey, 'F2' as SourceField, Field2 as FieldData from YourTable
> > Union
> > Select PrimaryKey, 'F3' as SourceField, Field3 as FieldData from YourTable
> > Union
> > Select PrimaryKey, 'F4' as SourceField, Field4 as FieldData from YourTable
> > Union
> > Select PrimaryKey, 'F5' as SourceField, Field5 as FieldData from YourTable
> > Union
> > Select PrimaryKey, 'F6' as SourceField, Field6 as FieldData from YourTable
> > Union
> > Select PrimaryKey, 'F7' as SourceField, Field7 as FieldData from YourTable
> >
> > Save this as qrySource
> >
> > Then create a second query
> >
> > Select PrimaryKey, FieldData, count(SourceField) as Occurance from qrySource
> > Group by PrimaryKey, FieldData
> >
> > Save this as qry Source1
> >
> > Then a third query
> >
> > Select PeimaryKey, FieldData, max(Occurance) from qrySource1
> > Group by PrimaryKey, FieldData
> >
> > This should give you what you are looking for.
> > Note that if in one of your source rows you have 3 ones, 3 twos and 1 three,
> > you may get either returned
> >
> >



Relevant Pages

  • Re: SQL Statement
    ... I want to run a query which returns the top 4 records in the result ... definition and some sample data. ... employee ID's, excluding the one passed in, and then create the ... A basic stab will involve UNION unless ...
    (comp.databases.oracle.misc)
  • Re: SQL Statement
    ... query results without a UNION? ... Say I have a parameter, like and employee ID, passed to a procedure. ... I want to run a query which returns the top 4 records in the result ... definition and some sample data. ...
    (comp.databases.oracle.misc)
  • Re: Combining records from two queries
    ... combining UNION and SELECT queries to best effect. ... The list in each case has to have the same number & types of fields (for example, if the first Query begins with a Date/Time field, the second one should do so as well). ... I like to keep my Union Queries short and simple and do the rest of the work elsewhere. ... tblMentors comprises Subject Mentors and Professional Mentors and the Placement subform has a combo for each - the Subject Mentor combo puts the chosen MentorID in the SubjectMentorID field and the Professional Mentor combo puts the chosen MentorID in the ProfessionalMentorID field. ...
    (microsoft.public.access.queries)
  • Re: Graphical Union-Query Builder?
    ... If you are limiting the input in each of the sub-queries in your Union ... Use the filtered queries as the input to your Union query: ... Most "functional IT users" will not know anything about SQL. ... I didn't know that fields of subsequent queries in a Union could have ...
    (microsoft.public.access.queries)
  • Re: Help! Union Query has started crashing!
    ... It's tblSupport on the RLR_SUPPORT_INFOTERRA.mdb database. ... I think I have tracked the problem down to the query ... I also tried a UNION ALL, ... the actual structure of the queries as they have been running fine for weeks. ...
    (microsoft.public.access.queries)