473,386 Members | 1,790 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Multiple Functions

daniel aristidou
491 256MB
hi guys what i am trying to do with my query is to for all of the workers in the database calculate their sales and return only their personal best. (within a certain time period)

so there are two basic steps calculate the sale total-
Expand|Select|Wrap|Line Numbers
  1. SUM((ProductSale.Amount * ProductSale.CRPrice) * ((100 - ProductSale.Discount) / 100))
but then only return the Max Value calculated for each worker.
So i assume i need a Max Function on this calculation. thus giving me
Expand|Select|Wrap|Line Numbers
  1. SELECT        Customer.CCompany, Worker.WName, Sale.SID, Sale.SDate, MAX(SUM((ProductSale.Amount * ProductSale.CRPrice) * ((100 - ProductSale.Discount) / 100))) 
  2.                          AS SOLD
  3. FROM            Sale Left JOIN
  4.                          ProductSale ON Sale.SID = ProductSale.SID Left JOIN
  5.                          Customer ON Sale.CID = Customer.CID Left JOIN
  6.                          Worker ON Sale.WID = Worker.WID
  7. WHERE        (Sale.SDate BETWEEN @StartDate AND @EndDate)
  8. GROUP BY Sale.SID, Sale.WID, Sale.CID, Sale.SDate, Customer.CCompany, Worker.WName
  9. ORDER BY SOLD DESC
However the Sql is returning an error:
---------------------------
Microsoft Visual Studio
---------------------------
SQL Execution Error.

Executed SQL statement: SELECT Customer.CCompany, Worker.WName, Sale.SID, Sale.SDate, MAX(SUM((ProductSale.Amount * ProductSale.CRPrice) * ((100 - ProductSale.Discount) / 100))) AS SOLD FROM Sale LEFT OUTER JOIN ProductSale ON Sale.SID = ProductSale.SID LEFT OUTER JOIN Cust...
Error Source: .Net SqlClient Data Provider
Error Message: Cannot perform an aggregate function on an expression containing an aggregate or a subquery.
---------------------------
---------------------------

Any help with this is greatly appreciated
Jun 12 '09 #1
3 1361
Dormilich
8,658 Expert Mod 8TB
maybe you want to go for a stored function?
Jun 12 '09 #2
ck9663
2,878 Expert 2GB
Use a subquery instead. Here's the pseudo-code:

Expand|Select|Wrap|Line Numbers
  1. select Customer.CCompany, Worker.WName, Sale.SID, Sale.SDate, max(total_sale) from 
  2. (select Customer.CCompany, Worker.WName, Sale.SID, Sale.SDate, sum(sale1+ sale2 + blah + blah) from yourtable JOIN anothertable on key1 = key2 group by Customer.CCompany, Worker.WName, Sale.SID, Sale.SDate) subquery
  3. group by Customer.CCompany, Worker.WName, Sale.SID, Sale.SDate
  4.  
That's just a pseudo-code so I hope you know what I'm getting at.

Happy coding!


--- CK
Jun 12 '09 #3
daniel aristidou
491 256MB
Thanks CK - That has helped alot :)
Jun 14 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

66
by: Darren Dale | last post by:
Hello, def test(data): i = ? This is the line I have trouble with if i==1: return data else: return data a,b,c,d = test()
5
by: IvDČ | last post by:
During a project I ran into trouble when using multiple inheritance. I was able to resolve the problem, but was unable to really understand the reasons for the error. Here is a short example of...
4
by: Andrew | last post by:
Hello, I am recieving a multiple definition error from the linker when I try to build a project I am working on. The message states that the functions I defined within an external .c source file...
10
by: PCHOME | last post by:
Hi! Would someone please help me thess C error(in gcc on Linux)? The compiler continues to give me: readLP.o: In function `Input_Problem': readLP.o(.text+0x0): multiple definition of...
24
by: sureshjayaram | last post by:
In some functions where i need to return multiple error codes at multiple places, I use multiple return statements. Say for ex. if (Found == 1) { if (val == -1) return error1; } else { if...
16
by: Randy Harris | last post by:
I was inspired by the recent discussion of returning multiple recordsets to ADO from a stored procedure. (Amazed is probably more accurate). I asked about how to accomplish same with Oracle and...
17
by: nergal | last post by:
What is a good programming style in C to handle multiple returns in a function that returns different values? - To have a variable that is set to the return value, which is in the end of the...
6
by: Gaijinco | last post by:
I'm having a weird error compiling a multiple file project: I have three files: tortuga.h where I have declared 5 global variables and prototypes for some functions. tortuga.cpp where I...
11
by: John | last post by:
Hi All, Although C# has Generics, it still does not support the generic programming paradigm. Multiple inheritance is required to support real generic programming. Here is a simple design pattern...
2
by: Immortal Nephi | last post by:
You may have heard diamond shape. You create one base class. One base class has member functions and member variables. You create two derived classes. All member functions and member variables...
0
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$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
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,...
0
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...
0
Oralloy
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.