Whats wrong in the following query --> - SELECT SUM(bookings),SUM(invoices),SUM(segments),SUM(totalgross),SUM(totalsale),SUM(commission),SUM(tax),SUM(SELECT grossfare FROM salesqww where type="cash adjustments" and aircode="UA") FROM summary WHERE aircode='UA'
13 1528
Your thread title should be a synopsis of the problem you have.
Instead of letting our members solve a puzzle, what is the problem you have with the statement?
Ronald :cool:
Your thread title should be a synopsis of the problem you have.
Instead of letting our members solve a puzzle, what is the problem you have with the statement?
Ronald :cool:
I have nested a query inside the SUM .
I want to take the SUM of the column returned by that query.
Is it possible ?
I have nested a query inside the SUM .
I want to take the SUM of the column returned by that query.
Is it possible ?
I know what you want to do!
I want to know what error is returned by MySQL!
Ronald :cool:
Atli 5,058
Expert 4TB
Hi.
First of all let me congratulate you on the least usefull discussion name I've seen in my time here.
That said, I'd try replacing all double quote marks " with single quote marks '
Hi.
First of all let me congratulate you on the least usefull discussion name I've seen in my time here.
That said, I'd try replacing all double quote marks " with single quote marks '
I didn't get you .
May be I got your first line but not the second.
I know what you want to do!
I want to know what error is returned by MySQL!
Ronald :cool:
The error which comes is to use to use the RIGHT syntax near the nested query.
Atli 5,058
Expert 4TB
Sub-queries need to be inside (), and altho your Query is inside a pair of those, that particular pair belongs to the SUM() function.
So adding a second () arround your sub-query might fix the problem.
O yea and what I said before apears to be wrong, I was under the impression that MySQL would slap you in the head for doing "this", rather than 'this'... but apparently it is possible now.
Would be good practice tho to pick one of them and stick to it.
Sub-queries need to be inside (), and altho your Query is inside a pair of those, that particular pair belongs to the SUM() function.
So adding a second () arround your sub-query might fix the problem.
I added a second () but it doesn't work.
Can you give me your table structure
Atli 5,058
Expert 4TB
I think I may have guessed the probblem.
The sub-querie you nested inside the SUM() function returns multiple rows. Sub-queryies (as far as I've seen) may only return one row.
So I belive moving your sub-query out of the SUM function, while placing a SUM function inside your sub-query will give you the results you want.
Somewhat like this: (I reformatted the query to better understand it) -
SELECT
-
SUM(bookings),
-
SUM(invoices),
-
SUM(segments),
-
SUM(totalgross),
-
SUM(totalsale),
-
SUM(commission),
-
SUM(tax),
-
( SELECT
-
SUM(grossfare)
-
FROM
-
salesqww
-
WHERE
-
type="cash adjustments"
-
AND
-
aircode="UA"
-
)
-
FROM
-
summary
-
WHERE
-
aircode='UA'
-
P.S. This had been easilly spotted by myself and many of our friends here if you had added the error message in with your post.
So please, if this does not fix it, give us error messages. We like error messages :)
I think I may have guessed the probblem.
The sub-querie you nested inside the SUM() function returns multiple rows. Sub-queryies (as far as I've seen) may only return one row.
So I belive moving your sub-query out of the SUM function, while placing a SUM function inside your sub-query will give you the results you want.
Somewhat like this: (I reformatted the query to better understand it) -
SELECT
-
SUM(bookings),
-
SUM(invoices),
-
SUM(segments),
-
SUM(totalgross),
-
SUM(totalsale),
-
SUM(commission),
-
SUM(tax),
-
( SELECT
-
SUM(grossfare)
-
FROM
-
salesqww
-
WHERE
-
type="cash adjustments"
-
AND
-
aircode="UA"
-
)
-
FROM
-
summary
-
WHERE
-
aircode='UA'
-
P.S. This had been easilly spotted by myself and many of our friends here if you had added the error message in with your post.
So please, if this does not fix it, give us error messages. We like error messages :)
So which will be more efficient -->
The above query which you mentioned
OR
Two seperate queries ?
Atli 5,058
Expert 4TB
I'd reccomend the sub-query.
Making two queries will require more code in you application and you will have to query the database twice.
I'd reccomend the sub-query.
Making two queries will require more code in you application and you will have to query the database twice.
I don't think the sub query is fast.
I tested it and found out that its slow compared to two seperated queries.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: lawrence |
last post by:
I've been bad about documentation so far but I'm going to try to be
better. I've mostly worked alone so I'm the only one, so far, who's
suffered from my bad habits. But I'd like other programmers...
|
by: Bill |
last post by:
Good Day;
I would appreciate assistance developing a query that I haven't been
able to develop without using a second table. I wish to count the
number of records that are still open on the...
|
by: Dalan |
last post by:
I'm experiencing a Query Syntax Error with an Access 97 Db. Actually,
the query performs as expected when adding any new records or editing
existing ones and even deleting records, EXCEPT when the...
|
by: Kenny G |
last post by:
Below is the code I currently have to either skip a control or go to a
control based on the response in the complications control. The
problem is even when Me.Complications is "None" the cursor...
|
by: ward |
last post by:
Greetings.
Ok, I admit it, I bit off a bit more than I can chew.
I need to complete this "Generate Report" page for my employer and I'm
a little over my head. I could use some additional...
|
by: William Foster |
last post by:
Good morning all,
I was wondering if anyone knows how to modify code whilst debugging in
Miscrosoft Visual Basic 2003 .NET, in Microsoft Excel Visual Basic for
Applications I am able to edit all...
|
by: Scubadude |
last post by:
I am looking for some assistance in 'fine-tuning' my preferences as I set-up
my system to learn PHP.
I am running Komodo professional, version 3.5.3, build 262321, platform
win32-x86.
Under...
|
by: Rnykster |
last post by:
I know a little about Access and have made several single table
databases. Been struggling for about a month to do a multiple table
database with no success. Help!
There are two tables. First...
|
by: DR |
last post by:
What ports do i need to unblock on client and server (running msvsmon.exe)
to debug remotely from my client box with visual studio 2005 pro?
When I attach to remote process a connection shows up...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
| |