Re: make table query that totals from several tables

Tech-Archive recommends: Fix windows errors by optimizing your registry



Hi,


Normalize your data with the following query:


SELECT 0 as Shift, [date], CallLost FROM shift_0
UNION ALL
SELECT 1, [date], CallLost FROM shift_1
UNION ALL
....
UNION ALL
SELECT 5, [date], CallLost FROM shift_5



Then,

SELECT Month([date]), shift, SUM(CallLost)
FROM savedQuery
GROUP BY Month([date]), shift


as example, produce the desired stat, quite simply, by month, by shift.


Working with normalized data always help to produce simple SQL statements.
In your case, using 6 different tables for the same kind of data, where
information (the shift) is store not as DATA but as part of the table NAME
is not really appropriate. SQL works with DATA, not with encoded
information... held in a table name. The first query retrieves the
information back as data, and in one "table" (the query). You can make that
query a permanent table (create table), so you can benefit of indexes (on
shift and [date]), if appropriate.



Hoping it may help,
Vanderghast, Access MVP


"HeatherShores" <HeatherShores@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:4712EE19-6353-4261-A6DC-53A004538B9E@xxxxxxxxxxxxxxxx
>I am stumped here. I am setting up a make table query titled 'total calls
> lost' The fields are date and calls lost.
>
> I have 6 tables shift 0, shift 1, shift 2, shift 3, shift 4, shift 5. They
> each have date and calls lost columns.
>
> I need to make a total of all the calls lost per per day for any range of
> dates specified by the user.


.



Relevant Pages

  • Re: Combined Query of 3 Queries
    ... you may want to consider using a Union query. ... > I have a table with Staff Names and a table with Shift ...
    (microsoft.public.access.forms)
  • 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: Monthly Totals Query
    ... The shifts have to come from somewhere, so you would need a table of shifts, and a query that outer-joins this to your existing table. ... If you don't already have one, create a table of the valid shift numbers. ... Turn this into into a crosstab query. ... In the Crosstab row, choose Row Heading. ...
    (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)