ROW_NUMBER with PARTITION BY in MS Access [duplicate] - ms-access

This question already has answers here:
Adding a Row Number in Query
(4 answers)
Closed 5 years ago.
How to achieve the Row number over partition by in the MS access .I Google but cant find information can you please how to do this.
My Data looks like this
CID MPay NumGrp
4 139608 1
4 139609 2
4 139610 3
4 139611 4
5 139608 1
5 139609 2
5 139610 3
6 139607 1
6 139608 2
6 139609 3
6 139610 4
6 139611 5
To this output, showing:
CID MPay NumGrp ID
4 139608 1 1
4 139609 2 2
4 139610 3 3
4 139611 4 4
5 139608 1 5
5 139609 2 6
5 139610 3 7
6 139607 1 8
6 139608 2 9
6 139609 3 10
6 139610 4 11
6 139611 5 12
BEST REGARDS
and many thanks for you great help.

Use my RowCounter function. It takes a string as key, thus you can concatenate your first two fields as the key and call it like this:
SELECT RowCounter(CStr([CID]) & CStr([MPay]),False) AS RowID, *
FROM YourTable
WHERE (RowCounter(CStr([CID]) & CStr([MPay]),False) <> RowCounter("",True));
Of course, if a field is text, CStr is not needed, for example:
RowCounter(CStr([CID]) & [MPay],False)

Related

Count the duplicate values on multiple array and sort it to highest

I have a target where I have this DUPLICATE checker with COUNT for multiple arrays. As we can see. Any suggestions on how I make this work? Thank you and have a nice day.
DATA:
id
value
1
[5,6,8,4,2]
2
[2,3,4,1,8]
3
[9,3,2,1,10]
Normal result:
number
count
1
2
2
3
3
2
4
2
5
1
6
1
7
0
8
2
9
1
10
1
This is my target result with sorting (Highest count):
number
count
2
3
1
2
3
2
4
2
8
2
5
1
6
1
10
1
9
1

calculating the average of marks from the beginning to this record

i have a table named test with the below structure like this
id mark join_id
1 5 1
2 4 1
3 9 1
4 5 2
5 7 2
6 12 2
i want to write a query that can get me the average of the marks from the beginning record to this record with the desired result as below
id mark join_id avg_of_previous_marks
1 5 1 5
2 4 1 4.5
3 9 1 6
4 5 2 5.75
5 7 2 6
6 12 2 7
i wrote this query but it doesn't seem to work correctly
SELECT test.id, test.mark, test.join_id, test_avg.avg_of_previous_marks FROM test
LEFT JOIN (SELECT id, join_id, AVG(mark) as avg_of_previous_marks FROM test GROUP BY
join_id) test_avg
ON test_avg.join_id = test.join_id AND test_avg.id <= test.id
and it gives this resault
id mark join_id avg_of_previous_marks
1 5 1 6
2 4 1 6
3 9 1 6
4 5 2 8
5 7 2 8
6 12 2 8
Its a simple running total that you need.
select id,mark,join_id, avg(mark) over (order by id) avg_of_previous_marks from test_avg ;
fiddle here

What is the problem with the size of the moving window (movfun) in octave?

I'm trying to use movfun (moving window) in octave
x = -1000:0.1:1000
y = sin(x)
movfun(#(arg) printf("%d\n", size(arg)), y(1:100), 4)
I expect to see all 4s
However, surprisingly (to me) I get:
4
1
4
97
2
1
3
1
3
1
ans =
Columns 1 through 29:
4 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
Columns 30 through 58:
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
Columns 59 through 87:
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
Columns 88 through 100:
5 5 5 5 5 5 5 5 5 5 5 5 4
What is wrong with my expectations?
This sheds a bit more light (I've increased window size to 8 for more clarity):
movfun( #(x) size(x, 1), y(1:100), 8 )
movfun( #(x) size(x, 2), y(1:100), 8 )
These produce the following outputs respectively:
4 5 6 7 8 8 8 8 [...] 8 8 8 8 7 6 5
1 1 1 1 93 93 93 93 [...] 93 93 93 93 1 1 1
This tells us that, presumably, under the hood, movfun makes sure to pass each 8-element vector in vertical form for processing, and that it treats the edges specially as single inputs, but then grabs all the 'non-edge' elements and performs some form of vectorised calculation involving all 93 columns at the same time.
We can confirm the 'edge' behaviour from the documentation:
"Endpoints"
This property controls how results are calculated at the
boundaries (endpoints) of the window. Possible values are:
"shrink" (default)
The window is truncated at the beginning and end of the array to exclude elements for which there is no source data. For example, with a window of length 3, 'Y(1) = FCN (X(1:2))', and 'Y(end) = FCN (X(end-1:end))'.

Read file in Octave

I need to read a data file into Octave that may have different numbers of
elements in each line, while retaining the line separation.
For example, read in:
1 2 3 4 5
6 7 8 9
1 2 3
4 5 6 7 8
How can I use scanf to obtain something like:
1 2 3 4 5
6 7 8 9 0
1 2 3 0 0
4 5 6 7 8
Your crosspost on the help mailinglist was answered from Przemek: http://permalink.gmane.org/gmane.comp.gnu.octave.general/57521
dlmread("filename")
will do what you want.

Resources needed: Sort 2D array "graphically"

I have a 2D array
1 2 3
4 5 6
7 8 9
and want to sort it like this
Snake
1 2 3
8 9 4
7 6 5
Snake (different)
1 2 3
6 5 4
7 8 9
Rotated
1 4 7
2 5 8
3 6 9
Wipe (diagonal)
1 3 6
2 5 8
4 7 9
Well, you got it, all kinds of sorting.
Searching the interweb for hours now. Any resources (specific language or pseudo code) on that greatly appreciated...
Suggestion: Dump all values in a 1D-array and sort there. Then define the patterns for filling using multiple for loops.