Thank NEIL SUNDERLAND for your replie to me!
Sorry I miss something that in my table the number "id" and "codequestion"
is random and have more 700 record with different "codequestion". The result
I want is the same with you are thinking. Onething is importance that is in
my table is so many "codequestion". EX: MS_HR_MS4, MS_HR_MS_RIk3, MS_HR_Rk1
..... but I want to run total cumulative with codequestion that is end with
"MS4". How can I do that? I try with this code but it is wrong!
SELECT Index, Name, CodeQuestion, Mark, (SELECT SUM(Mark)
FROM Owner AS B
WHERE A.[Name] = B.[Name] AND A.CodeQuestion <= B.CodeQuestion) AS Runtotal
FROM Owner AS A
WHERE (CPosition="MHR") and (right([CodeQuestion],3)="MS4")
ORDER BY MARK DESC;
result:
Index Name CodeQuestion Mark Runtotal
642 AAAAAAAAAAAA HIV-RI-MS4 30 457
641 AAAAAAAAAAAA HIII-RI-MS4 15 512
640 AAAAAAAAAAAA HII-RI-MS4 15 497
645 AAAAAAAAAAAA HVII-RI-MS4 10 366
643 AAAAAAAAAAAA HV-RI-MS4 10 351
639 AAAAAAAAAAAA HI-RI-MS4 10 482
646 AAAAAAAAAAAA HVIII-RI-MS4 5 371
644 AAAAAAAAAAAA HVI-RI-MS4 5 356
result that I want is:
Index Name CodeQuestion Mark Runtotal
642 AAAAAAAAAAAA HIV-RI-MS4 30 30
641 AAAAAAAAAAAA HIII-RI-MS4 15 45
640 AAAAAAAAAAAA HII-RI-MS4 15 60
645 AAAAAAAAAAAA HVII-RI-MS4 10 70
643 AAAAAAAAAAAA HV-RI-MS4 10 80
639 AAAAAAAAAAAA HI-RI-MS4 10 90
646 AAAAAAAAAAAA HVIII-RI-MS4 5 95
644 AAAAAAAAAAAA HVI-RI-MS4 5 100
Thanks
Neil Sunderland said:
AN said:
I have a table:
idex name codequestion mark
1 A MS_HR_RI1 45
2 A MS_HR_RI2 30
3 A MS_HR_RI3 15
4 A MS_HR_RI4 5
5 A MS_HR_RI5 5
I want to query result:
idex name codequestion mark
1 A MS_HR_RI1 45
2 A MS_HR_RI2 30
List all record when sum(mark)<80 and sum(mark)>70. How can I do that?
(mark by case is (45+30)) please help me to write query this problem.
Try creating a running total query first (replace 'mytable' to the
name of your table):
SELECT
idex, [name], codequestion, mark,
(SELECT SUM(mark)
FROM mytable AS B
WHERE A.[name] = B.[name] AND
A.codequestion <= B.codequestion) AS runtotal
FROM mytable AS A
This should give you this:
idex name codequestion mark runtotal
1 A MS_HR_RI1 45 45
2 A MS_HR_RI2 30 75
3 A MS_HR_RI3 15 90
4 A MS_HR_RI4 5 95
5 A MS_HR_RI5 5 100
Then you should what you want with this (change 'myquery' to the the
name you gave to the query above):
SELECT * FROM myquery WHERE runtotal BETWEEN 70 AND 80
idex name codequestion mark runtotal
2 A MS_HR_RI2 30 75
--
Neil Sunderland
Braunton, Devon
Please observe the Reply-To address