473,385 Members | 2,028 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,385 software developers and data experts.

distinct + sum

hi
i have a table with several fields

Field1(area), Field2(Quantity), Field3(cost), field4(date)

area Quantity cost date
office 10 50 6/4/04
gym 50 90 9/4/04
office 100 2000 9/4//04
what i need to do is return the total for an area over a date range

ie
area Quantity cost
office 110 2050
gym 50 90

the user will select the date range from a combobox

i have the following code

strSQL = "SELECT DISTINCT ([DataTable].[Area]),
Sum([DataTable].Quantity) AS [SumOfTotal Quantity],
Sum([DataTable].TotalPrice) AS [SumOfTotal Price] " & _
"FROM datatable " & _
"WHERE DataTable.Dates Between" &
SQLDate(Me.cboStartDate.Value) & "And" & SQLDate(cboEndDate.Value)

this code works fine until i include the date range

How do i adapt this code to return the distinct area along with the
total quantity and total cost for the area
thanks in advance
kevin
Nov 13 '05 #1
1 2256
Hi Kevin

Same as my reply to your last post, use GROUP BY DataTable.Area only

Stewart

"Kevin Carter" <kc******@ford.com> wrote in message
news:2a**************************@posting.google.c om...
hi
i have a table with several fields

Field1(area), Field2(Quantity), Field3(cost), field4(date)

area Quantity cost date
office 10 50 6/4/04
gym 50 90 9/4/04
office 100 2000 9/4//04
what i need to do is return the total for an area over a date range

ie
area Quantity cost
office 110 2050
gym 50 90

the user will select the date range from a combobox

i have the following code

strSQL = "SELECT DISTINCT ([DataTable].[Area]),
Sum([DataTable].Quantity) AS [SumOfTotal Quantity],
Sum([DataTable].TotalPrice) AS [SumOfTotal Price] " & _
"FROM datatable " & _
"WHERE DataTable.Dates Between" &
SQLDate(Me.cboStartDate.Value) & "And" & SQLDate(cboEndDate.Value)

this code works fine until i include the date range

How do i adapt this code to return the distinct area along with the
total quantity and total cost for the area
thanks in advance
kevin

Nov 13 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: ben | last post by:
This is a PHP / MySQL kind of question. I am making a script which simply pulls information from a database and displays it on screen. BUT there will be entries where fields could be the same, and...
5
by: Martin Feuersteiner | last post by:
Dear Group I'm having trouble with the clause below. I would like to select only records with a distinct TransactionDate but somehow it still lists duplicates. I need to select the...
2
by: mfyahya | last post by:
I have two tables, both containing an 'authors' column. Is there a way to get a unique list of authors from the two tables? I tried SELECT DISTINCT `authors` from `table1`, `table2`; but I got an...
4
by: Johnson, Shaunn | last post by:
Howdy: Can someone tell what the difference (and why you would use it) is between the following: select distinct on (col_1, col_2), col_1, col_2, col_3
18
by: mathilda | last post by:
My boss has been adamant that SELECT DISTINCT is a faster query than SELECT all other factors being equal. I disagree. We are linking an Access front end to a SQL Server back end and normally are...
1
by: nfrodsham | last post by:
In Microsoft's help literature, it states: "You can filter out non-unique rows by using the DISTINCT option of an aggregate function" I am trying to do this in Access 2003 with the COUNT...
3
by: orekinbck | last post by:
Hi There Our test database has duplicate data: COMPANYID COMPANYNAME 1 Grupple Group 2 Grupple Group 5 Grupple Group 3 Yada Inc 4 Yada...
6
by: Bob Stearns | last post by:
I am getting unwanted duplicate rows in my result set, so I added the DISTINCT keyword to my outermost SELECT. My working query then returned the following message: DB2 SQL error: SQLCODE: -214,...
4
by: monomaniac21 | last post by:
hi! is it possible to do the aforementioned query - selecting only distinct in 1 col but retrieving all other cols at the same time. regards marc
2
by: Techhead | last post by:
I need to run a SELECT DISTINCT query across multiple fields, but I need to add another field that is NON-DISTINCT to my record set. Here is my query: SELECT DISTINCT lastname, firstname,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
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...
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
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,...

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.