I have 2 queries, for the sake of this post I will refer to them as
query1 and query2. Basically query1 returns a number of results from
tables which are grouped and then query2 queries query1 and is
expected to sum the number of hours.
query1 returns the following rows:
PersonID StartDate EndDate Hours
=============== =============== =============
801 07/09/06 11/12/06 420
801 05/09/06 11/12/06 429
801 13/12/06 04/04/07 651
query2 comprises of the following query:
SELECT [query1].[PersonID], Min([Query1].[StartDate]) AS MinStartDate,
Max([Query1].[EndDate]) AS MaxEndDate, Sum([Query1].[Hours]) AS
SumOfHours
FROM [Query1]
GROUP BY [Query1].[PersonID], [Query1].[EndDate]
The outcome I currently get from query2 is:
PersonID StartDate EndDate Hours
=============== =============== =============
801 13/12/06 04/04/07 651
What I am after is:
PersonID StartDate EndDate Hours
=============== =============== =============
801 05/09/06 04/04/07 1500
Can anyone see why I am not getting this result??
Any advice would be appreciated.
Thanks 2 3860
On 10 Apr 2007 19:40:59 -0700, gl**********@gm ail.com wrote:
I intuitively feel this sql is wrong, but I can't quite explain why.
My implementation is to create several queries, for example:
select PersonID, Min(StartDate)
from query1
group by PersonID
same for Max
And then create a third query, joining these two queries on PersonID.
-Tom.
>I have 2 queries, for the sake of this post I will refer to them as query1 and query2. Basically query1 returns a number of results from tables which are grouped and then query2 queries query1 and is expected to sum the number of hours.
query1 returns the following rows:
PersonID StartDate EndDate Hours ============== =============== ============== 801 07/09/06 11/12/06 420 801 05/09/06 11/12/06 429 801 13/12/06 04/04/07 651
query2 comprises of the following query:
SELECT [query1].[PersonID], Min([Query1].[StartDate]) AS MinStartDate, Max([Query1].[EndDate]) AS MaxEndDate, Sum([Query1].[Hours]) AS SumOfHours FROM [Query1] GROUP BY [Query1].[PersonID], [Query1].[EndDate]
The outcome I currently get from query2 is:
PersonID StartDate EndDate Hours ============== =============== ============== 801 13/12/06 04/04/07 651
What I am after is:
PersonID StartDate EndDate Hours ============== =============== ============== 801 05/09/06 04/04/07 1500
Can anyone see why I am not getting this result??
Any advice would be appreciated.
Thanks
On Apr 10, 10:40 pm, glen.ridd...@gm ail.com wrote:
I have 2 queries, for the sake of this post I will refer to them as
query1 and query2. Basically query1 returns a number of results from
tables which are grouped and then query2 queries query1 and is
expected to sum the number of hours.
query1 returns the following rows:
PersonID StartDate EndDate Hours
=============== =============== =============
801 07/09/06 11/12/06 420
801 05/09/06 11/12/06 429
801 13/12/06 04/04/07 651
query2 comprises of the following query:
SELECT [query1].[PersonID], Min([Query1].[StartDate]) AS MinStartDate,
Max([Query1].[EndDate]) AS MaxEndDate, Sum([Query1].[Hours]) AS
SumOfHours
FROM [Query1]
GROUP BY [Query1].[PersonID], [Query1].[EndDate]
The outcome I currently get from query2 is:
PersonID StartDate EndDate Hours
=============== =============== =============
801 13/12/06 04/04/07 651
What I am after is:
PersonID StartDate EndDate Hours
=============== =============== =============
801 05/09/06 04/04/07 1500
Can anyone see why I am not getting this result??
Any advice would be appreciated.
Thanks
Don't GROUP BY [EndDate], just GROUP BY [PersonID]. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: david liu |
last post by:
access 2000 query:
here's what i want to do. from an asp page, perform a search on a
table in access. i have used sql code in the asp page itself, but i'd
rather execute a query in access. i have success in running any query
(basic SELECT, SELECT with conditions _other_ than LIKE, etc..) for
some reason, when i execute the query below from the asp page, i get
no results.
the search.asp page just has a text box in a form that submits...
|
by: Puneet Murgai |
last post by:
I am trying to run an access query which works when I write it
directly in the database. However, it fails when an SQL script
containing it is run from C++.
It doesn't recognize the Iff and Nz functions when run through ODBC.
Query is as follows:
INSERT INTO PROJECT_LINK_DEFN (LD_LINKID,
LD_FROM_PROJECTNAME,LD_TO_PROJECTNAME, LD_FROM_TASKUNIQUEID,
LD_TO_TASKUNIQUEID, LD_LINKTYPE, LD_MODELTYPE ) SELECT
|
by: Art |
last post by:
Hi,
Can anyone point me to an example of how I would execute a query I've created in an Access DB. I've copied the SQL down to my VB.net application and that works fine, but it's ugly. I'd like to direcly execute the query that I created in Access - if possible.
Also, I would like to be able to add a parameter to that query. For example, if I'm in Access and put an unknown field in the query, I get prompted to enter that info when the...
|
by: s_wadhwa |
last post by:
SELECT DISTINCTROW "01C" AS dummy, Buildings.BuildingNumber,
UCASE(Buildings.BuildingName) AS BuildingName,
Buildings.MasterPlanCode, Buildings.UniformBuildingCode,
Buildings.FunctionalCategoryCode, Buildings.OwnershipCode,
Buildings.ConditionCode, Format$(,"0000000") AS
dBasicGrossArea, Format$(,"0000000") AS
dCoveredUnenclosedGrossArea,
IIf(Month()>9,Month(),"0" &
Month()) & Year() AS dDateOccupancy,
Buildings.YearConstructed,...
|
by: ShastriX |
last post by:
Getting a weird error while trying out a query from Access 2003 on a
SQL Server 2005 table.
Want to compute the amount of leave taken by an emp during the year.
Since an emp might be off for half a day (forenoon or afternoon), have
the following computed field:
SessionOff: ( And )
The query works fine when there's no criterion on SessionOff.
| |
by: zwasdl |
last post by:
Hi,
I'm using MS Access to query against Oracle DB via ODBC. Is it
possible to use HINT in Access?
Thanks,
Wei
|
by: =?Utf-8?B?bXNjZXJ0aWZpZWQ=?= |
last post by:
Has anyone successfully used an Access query from .NET? I am trying to do
this and am getting a weird error. .NET calls queries 'stored procedures'.
The error I am getting says "Schema could not be retrieved for this stored
procedure' ... "The underlying enumerator did not support enumerating objects
of type 'ProcedureParamater'". .Net does recognize the stored procedure i.e.
it does appear in the drop-sdown list.
|
by: k-man |
last post by:
Hi:
I have an MS Access query for a table called MyTable. One of my
fields in the query is a custom field that looks like "MyField: =
MyFunction(ID)" where ID is a field in MyTable.
I have ASP code and I can use it to read the query OK when "MyField"
is not part of the query. If I add in MyField and then run my ASP
code to try to read all the query fields, I get an error message on my
web browser which says something to the effect...
|
by: jsacrey |
last post by:
Hey everybody, got a secnario for ya that I need a bit of help with.
Access 97 using linked tables from an SQL Server 2000 machine.
I've created a simple query using two tables joined by one field
between them. The join field in both tables are indexed and I'm
selecting 1 field from each table to lookup. The Access query is
taking more than 60 second to retrieve 1 record and if I execute the
same query within the Query Analyzer, it...
|
by: OzNet |
last post by:
I have a query (with calculated fields) in Access (2007) and the data changes depending on the dates and staff person selected. I need to produce a series of graphs based on the data in this query and it seems to me that Excel is far easier to create graphs than Access.
When I use the Get External Data feature of Excel and the dialog box with the tables and queries appears, the query I need is not listed. Is this because the query has...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |