473,461 Members | 1,375 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Grouping aggregate functions

Hi.

I have this SQL:
Expand|Select|Wrap|Line Numbers
  1. SELECT  distinct ARTIK.BEN as Namn, art_nr as nr, ISNULL(A_PRIS,0) as pris, lev_datum
  2. FROM ordra, ARTIK
  3. where ARTIK.NR = ORDRA.art_nr and lev_datum >= '2009-06-01' and lev_datum <= '2010-11-30' and kund_nr = '150'
  4. and ARTIK.NR = '011'
  5. order by art_nr,lev_datum
  6.  
  7.  
Output:
Expand|Select|Wrap|Line Numbers
  1. XL POTATIS     011       5.65    2010-06-11
  2. XL POTATIS     011       5.65    2010-06-14 
  3. XL POTATIS     011        5.65    2010-06-15 
  4. XL POTATIS     011       5.65    2010-06-17 
  5. XL POTATIS     011        6.15    2010-09-10 
  6. XL POTATIS     011     6.15    2010-09-16 
  7. XL POTATIS      011       6.15    2010-09-21 
  8. XL POTATIS     011        6.15    2010-09-22 
  9. XL POTATIS     011      5.65    2010-09-27 
  10. XL POTATIS     011        5.65    2010-09-30
  11.  
But I want to track the price-changes so the output to be :
Expand|Select|Wrap|Line Numbers
  1. XL POTATIS 011     5.65    2010-06-11 (first date 5.65)
  2. XL POTATIS 011     5.65    2010-06-17 (last date 5.65)
  3. XL POTATIS 011     6.15    2010-09-10 (first date 6.15)
  4. XL POTATIS 011     6.15    2010-09-22 (last date 6.15)
  5. XL POTATIS 011    5.65    2010-09-27 (first date 5.65 again)
  6. ....
  7.  
How to manage that?
(The problem is that the price 5.65 has been used before, otherwise is possible with group by)
Pelle
Nov 17 '10 #1
1 1189
NeoPa
32,556 Expert Mod 16PB
Apart from telling you that you probably want to link your tables using a JOIN, there is little I can say.

Your explanation of what you are doing or want to do tells me very little I'm afraid.
Nov 17 '10 #2

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

Similar topics

1
by: Jason | last post by:
I have a complex statement that is used in a SELECT statement. After all my calculations I need to do an additional filter on the results. Can I use an alias anywhere or is the AS clause just for...
6
by: Steven An | last post by:
Howdy, I need to write an update query with multiple aggregate functions. Here is an example: UPDATE t SET t.a = ( select avg(f.q) from dbo.foo f where f.p = t.y ), t.b = ( select sum(f.q)...
1
by: Job Lot | last post by:
Is it possible to use Aggregate functions with GROUP BY Clauses on DataTable. I have a DataTable with following values: Date Amount Int Balance 1/1/2004 5000.00 50.00 5050.00...
2
by: jc | last post by:
Hi. Just as we have AVG(COLUMN_NAME) and MAX(COLUMN_NAME) how can I write my own variation of a such a function. If I can appreciate how to do this, then I hopefully I can write a...
3
by: eddiec | last post by:
hi everyone, I have a report in an adp that uses aggregate functions in its record source and I am trying to figure out how to filter the records displayed in the report: DoCmd.OpenReport...
10
by: neb | last post by:
Dear member of the forum, Ms access has built-in aggregate function like: -Sum, Max, First, Avg, ... Is it possible to build user-defined aggregate? (if you have any clue, do not hesitate to...
0
by: Not Me | last post by:
Hey, I have a report featuring a handful of subreports, a field taking values from the main record source, and a field in the report footer which displays the sum of values in said field. The...
5
by: David Garamond | last post by:
What do people think of adding some more aggregate functions. These are the ones that MySQL has and PG doesn't: - STD/STDDEV - VARIANCE - BIT_OR - BIT_AND - GROUP_CONCAT (for strings, added...
5
by: Dean | last post by:
Has anyone toiled with creating/using alternate domain aggregate functions? I have been messing with that a little. The one recordsource I have been working indicates I get 20 to 40% savings in...
3
by: gobwash | last post by:
Do aggregate functions (sum, count, min, max) inherently cause table locks? More concretely, would the following query typically result in a table lock? select sum(quantity) as total from...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
1
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...
0
isladogs
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.