The query below works:
SELECT a1.[MONLOG], a1.[MONUNIT], a1.[MONY], a1.[MONE], a1.[MONP], COUNT(*) AS Row
FROM Monday1 AS a1 INNER JOIN Monday1 AS a2 ON a1.[MONLOG] >= a2.[MONLOG]
GROUP BY a1.[MONLOG], a1.[MONUNIT], a1.[MONY], a1.[MONE], a1.[MONP];
Which returns this:
MONLOG..MONUNIT..MONY..MONE..MONP..ROW
A ..............2.....................-1.................1
B ..............3..........-1............................2
C ..............3..........-1............................3
D ..............2...............................-1.......4
E ..............2................................... ......5
F ..............3................................... ......6
MONLOG is the only field that is variable among itself (MONLOG data is all different and not one row will match another within its own column). MONUNIT can only be 0,2 or 3. MONY, MONE, & MONP can only be blank or -1.
I need to sort/ascending by MONUNIT. So I need my query to return the rows by MONUNIT All 0 first, All 2 next & then 3 last. But I need my ROW sequence numbering to coincide with MONUNIT. See example below.
This is what I need it to return:
MONLOG..MONUNIT..MONY..MONE..MONP..ROW
A.............. 2.....................-1....................1
D ..............2..............................-1...........2
E ..............2................................... .........3
B ..............3.........-1................................4
C ..............3.........-1................................5
F ..............3................................... .........6
Ive tried re-arranging the query but got this:
MONLOG..MONUNIT..MONY..MONE..MONP..ROW
A ...............2..................-1.................1
D ...............2.............................-1......4
E ...............2.................................. ....5
B ...............3........-1...........................2
C ...............3........-1...........................3
F ...............3.................................. ....6
I also got something like this:
MONLOG..MONUNIT..MONY..MONE..MONP..ROW
A ...............2..................-1.................27
D ...............2............................-1.......27
E ...............2.................................. ....27
B ...............3........-1...........................27
C ...............3........-1...........................27
F ...............3.................................. ....27
I really appreciate any help.
Thanks