I have two tables that I am trying to use to create a report by using
a join. When the query is executed, the SUM on the second table is 4
times the expected amount. As a stand alone query on the second table,
this works:
SELECT `Last_Name`, `First_Name`, `Employee_SSN`,
SUM(`id_es_inv` .`Total_Amount` ) AS `Expense Amount`
FROM `id_es_inv`
GROUP BY `Last_Name`
But when I attempt the same operation using a JOIN on the first table,
the SUM then comes out as 4x the expected value:
SELECT
SUM(`id_es_inv` .`Total_Amount` ) AS `Expense Amount`,
CONCAT_WS(', ',id_ts_inv.`La st_Name`,id_ts_ inv.`First_Name `) AS
`Name`, SUM(id_ts_inv.T otal_Amount) As `Total`,
SUM(id_ts_inv.` Hours_Reg`) AS `REG Hrs`, SUM(id_ts_inv.` Hours_OT`) AS
`OT Hrs`, SUM(id_ts_inv.` Hours_DT`) AS `DT Hrs`,
id_ts_inv.`Rate _Regular_Bill` AS `Bill Rate`,
SUM(id_ts_inv.` Hours_Reg`* id_ts_inv.`Rate _Regular_Bill`) AS `Amount
ST`,
SUM(id_ts_inv.` Hours_OT`* id_ts_inv.`Rate _Regular_Bill`) AS `Amount
OT`,
SUM(id_ts_inv.` Hours_DT`* id_ts_inv.`Rate _Regular_Bill`) AS `Amount
DT`
FROM `id_ts_inv`
`id_ts_inv` LEFT JOIN `id_es_inv` USING (`Employee_SSN` )
GROUP By id_ts_inv.`Last _Name`, `id_es_inv`.`La st_Name`
The tables are not identicle in structure, i.e `id_es_inv` contains a
smaller number of columns and rows than `id_ts_inv`, so I can't use a
UNION with 2 selects. I've also tried changing the JOIN columns, but
that just made things worse.
I've poured over the Internet, gone through everything relevant in
Paul DuBois's MySQL CookBook, asked friends who have more MySQL
experience that I do, but no luck yet.
Can anybody help with a useful suggestion as to why this behavior is
happening?
TIA 2 2049
"Richard J Lacroix" <ri**********@c omcast.net> wrote in message
news:20******** *************** ***@posting.goo gle.com...
[snip]
What is the purpose of repeating `id_ts_inv` in the FROM? FROM `id_ts_inv` `id_ts_inv` LEFT JOIN `id_es_inv` USING (`Employee_SSN` )
--
Eric Lafontaine
That's just a cut-and-paste error.
Richard
"ventre-à-pattes" <ne**@ventre-a-pattes.com> wrote in message news:<be******* **@imsp212.netv igator.com>... "Richard J Lacroix" <ri**********@c omcast.net> wrote in message news:20******** *************** ***@posting.goo gle.com... [snip] What is the purpose of repeating `id_ts_inv` in the FROM?
FROM `id_ts_inv` `id_ts_inv` LEFT JOIN `id_es_inv` USING (`Employee_SSN` ) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Hunter Hillegas |
last post by:
I have just added a third table to a query and I am no longer getting
the results I am expecting.
Three Tables:
CUSTINVOICEJOUR (Header Table)
CUSTINVOICETRANS (Line Item Table)
MARKUPTRANS (Additional Header Info)
CUSTINVOICEJOUR has a one to many relationship to CUSTINVOICETRANS.
|
by: smauldin |
last post by:
Why does the execution plan have a nested loop join for a simple select
with an UDF in the where clause?
Here is the query:
select * from test_plan where vCol = my_udf('test')
Here is the table definition:
create table test_plan(iCol integer, vCol varchar(20))
|
by: Robert |
last post by:
I built a query in Query Analyzer and mapped it to Access 2002. The result
set returned is identical except cells in some records in the Access result
have #Deleted. This cast a shadow of doubt on the reliability of Access.
Am I doing something incorrect? Comments?
Access query
SELECT .Account, .Region_nm, .Site,
dbo_Results.
FROM INNER JOIN ( INNER JOIN (
|
by: Ken |
last post by:
I wrote a function to use in queries that takes a date and adds or
subtracts a certain length time and then returns the new value. There
are times when my function needs to return Null values.
Function DateCalc (blah...) As Variant
Do Stuff...
If Not IsNull(varNewDate) Then
DateCalc = varNewDate
End If
End Function
|
by: Richard Gregory |
last post by:
Hi,
I have the wsdl below, for an Axis web service, and when I select Add Web
Refernce in Visual Studio the proxy is missing a class representing the
returnedElementsType (see reference.cs below the wsdl). This complex type is
a collection of another complex type(elementType), and the Reference.cs has
an array of these rather than the single returnedElementsType. If If I want
to be able to obtain these elements from the SOAP response I...
| |
by: genc_ymeri |
last post by:
Hi over there,
Propably this subject is discussed over and over several times. I did google
it too but I was a little bit surprised what I read on internet when it
comes 'when to use what'.
Most of articles I read from different experts and programmers tell me that
their "gut feelings" for using stringBuilder instead of string concatenation
is when the number of string concatunation is more then N ( N varies between
3 to max 15 from...
|
by: salad |
last post by:
I'm curious about your opinion on setting relationships.
When I designed my first app in Access I'd go to Tools/Relationships and
set the relationships. Over time I'd go into the window and see
relationship spaghetti....tables/queries all overthe place with lots of
relationship lines between here and there.
After that first app I didn't do relationships. If I had a query, I
defined the relationship. Many of the times when I create a...
|
by: Peter Michaux |
last post by:
Hi,
I'm thinking about code minimization. I can think of a few places where
whitespace matters
a + ++b
a++ + b
a - --b
a-- -b
when a line ends without a semi-colon in which case the new line
|
by: KTosser |
last post by:
I have two tables, one contains contacts and the other has all the
events and years that the contacts participated in. What I want is to
be able to choose the years, say 2005 and 2006, and get all the
contacts that attended in both 2005 and 2006.
Table1
ContactID ContactName
1 John
2 Bob
3 Amy
|
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: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |