Click here to Skip to main content
15,892,480 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
İ cant use theese codes in may access query
i can use it oracle query but it doesnt work in access query

SUM(SalePrice) OVER(PARTITION BY OrderCategory order BY orderDate)


i have a table lıke this and i want last column sum(saleprice)lıke ,
OrderCategory orderDate SalePrice sum(saleprice)
xxxx 01.01.2020 50 50
xxxx 10.02.2020 150 200
xxxx 01.03.2020 175 375

What I have tried:

<pre>SUM(SalePrice) OVER(PARTITION BY OrderCategory order BY orderDate)
Posted
Updated 22-Mar-20 2:43am
v2
Comments
Richard MacCutchan 22-Mar-20 4:13am    
What do you mean by "İ cant use theese codes in may access query"?
OriginalGriff 22-Mar-20 4:19am    
"It doesn't work" is probably the most useless problem report we get - and we get it a lot. It tells us nothing about what is happening, or when it happens.
So tell us what it is doing that you didn't expect, or not doing that you did.
Tell us what you did to get it to happen.
Tell us any error messages.
Use the "Improve question" widget to edit your question and provide better information.
Member 14588284 22-Mar-20 4:36am    
https://yadi.sk/d/JrEWUe9Jd8U-dQ
error lıke this
OriginalGriff 22-Mar-20 4:49am    
I'm not going near a random website to find out what you posted there.
You want to show us an error? Copy'n'paste, then post the text here.
Member 14588284 22-Mar-20 5:13am    
run-time error '-2147217900 (80040e14)';

 
Share this answer
 
Comments
Member 14588284 22-Mar-20 6:03am    
i read but there for all rows only sum of row
but i want like this
A B c sum(c)
xxxx 01.01.2020 50 50
xxxx 10.02.2020 150 200
xxxx 01.03.2020 175 375
Member 14588284 22-Mar-20 6:12am    
but that gives me an idea and i find my solution
thanks a lot
Member 14588284 22-Mar-20 6:34am    
But it gives me wrong total when more then one ıd in same date
Richard MacCutchan 22-Mar-20 6:40am    
What is "it"?
Member 14588284 22-Mar-20 6:43am    
SORGU = "SELECT CARKOD,TARIH,KAYITNO," & BORC & " AS BORC," & ALACAK & " AS ALACAK," & _
" (SELECT SUM(" & BORC & "-" & ALACAK & ") FROM CARTH001 WHERE TARIH<=A.TARIH AND CARKOD=A.CARKOD )AS BAKIYE " & _
" FROM CARTH001 A GROUP BY " & ALACAK & "," & BORC & ",CARKOD,TARIH,KAYITNO ORDER BY CARKOD,TARIH,KAYITNO"
Well, you need to change only one value to get correct result:

CARKOD		ISLTARIH			TARIH		KAYITNO	BORC	ALACAC	BAKYIE
12001001	2020-03-21 15:41:19	2020-03-01	3		500				500
12001001	2020-03-21 16:09:16	2020-03-05	4		600				1700
12001001	2020-03-21 16:09:16	2020-03-03	8		600				1700
12001001	2020-03-21 22:20:51	2020-03-20	5				-500	1200
12001001	2020-03-21 23:03:44	2020-03-30	6				-500	700
12001001	2020-03-21 23:03:45	2020-03-30	7				-500	200


In your original file underscored value is: 2020-03-21 23:03:44, so SUM(TUTAR) for the financial operation made in the same second is 1000! That's why you've got the value of 200 instead of 700.

Here is a query used by me:
SQL
SELECT src.CARKOD, src.ISLTARIH, src.TARIH, src.KAYITNO, IIF(src.BA='B', src.TUTAR, NULL) AS BORC, IIF(src.BA='A', src.TUTAR*-1, NULL) AS ALACAC, (SELECT SUM(IIF(ps.BA='B', ps.TUTAR, ps.TUTAR *-1)) 
    FROM CARTH001 AS ps
    WHERE ps.ISLTARIH <= src.ISLTARIH) AS BAKYIE
FROM CARTH001 AS src
ORDER BY src.ISLTARIH, src.KAYITNO;



[EDIT]
Accordingly to the comments to this answer...

A query should looks like:
SQL
SELECT src.CARKOD, src.ISLTARIH, src.TARIH, src.KAYITNO, IIF(src.BA='B', src.TUTAR, NULL) AS BORC, IIF(src.BA='A', src.TUTAR*-1, NULL) AS ALACAC
FROM CARTH001 AS src
ORDER BY src.TARIH, src.ISLTARIH;

The rest have to be done in MS Excel, because MS Access does not support ROW_NUMBER(PARTITION BY ... ORDER BY ...). Although it is available to achieve by several subqueries, but final solution is - at least - ugly...

I've created MS Excel file, which gets data from Access database and "calculate" pending sum based on it.
Excel - pending sum on Access data[^]
File is available to download between 07:00AM and 10:59.59PM UTC+1 (Warsaw)

Result:
CARKOD 	ISLTARIH	 TARIH 	 KAYITNO 	 BORC 	ALACAC	BAKYIE
 12001001 	2020-03-11	2020-03-01	 3,00    	 500,00    		500
 12001002 	2020-03-15	2020-03-01	 1,00    		-500	0
 12001001 	2020-03-10	2020-03-03	 8,00    	 600,00    		600
 12001001 	2020-03-12	2020-03-05	 4,00    	 600,00    		1200
 12001001 	2020-03-22	2020-03-05	 13,00    		-400	800
 12001001 	2020-03-20	2020-03-15	 12,00    	 300,00    		1100
 12001001 	2020-03-13	2020-03-20	 5,00    		-500	600
 12001001 	2020-03-18	2020-03-20	 10,00    	 750,00    		1350
 12001001 	2020-03-19	2020-03-20	 11,00    	 30,00    		1380
 12001001 	2020-03-14	2020-03-30	 7,00    		-500	880
 12001001 	2020-03-16	2020-03-30	 9,00    		-500	380
 12001001 	2020-03-17	2020-03-30	 6,00    		-500	-120
 
Share this answer
 
v2
Comments
Member 14588284 22-Mar-20 9:39am    
Thank u very much Maciej Los
i changed theese codes and i did my want
again thank you very much :)
Maciej Los 22-Mar-20 9:44am    
You're very welcome.
Richard MacCutchan 22-Mar-20 10:08am    
I think your 5 from me is much more well deserved.
Maciej Los 22-Mar-20 10:09am    
Thank you, Richard.
:)
Member 14588284 22-Mar-20 10:40am    
Hi again
can you look again codes ?
i changed order by date and totals are not true

https://yadi.sk/d/4q_RDVxb2JEqtg

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900