|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
cumulative problemI would like to calculate the cumulative summation by ordering the descending type from htese below data, Id Status Item Description Score Amount 9/16/2006 5:00:02 PM DD 1 Topic 1 Good 1 9/16/2006 5:00:02 PM DD 2 Topic 2 Fair 1 9/16/2006 5:00:02 PM DD 3 Topic 3 Good 1 9/16/2006 5:00:02 PM DD 4 Topic 4 Good 1 9/16/2006 5:06:11 PM DMG 1 Topic 1 Fair 1 9/16/2006 5:06:11 PM DMG 2 Topic 2 Fair 1 9/16/2006 5:06:11 PM DMG 3 Topic 3 Good 1 9/16/2006 5:06:11 PM DMG 4 Topic 4 Fair 1 9/16/2006 5:22:31 PM MGR 1 Topic 1 Fair 1 9/16/2006 5:22:31 PM MGR 2 Topic 2 Poor 1 9/16/2006 5:22:31 PM MGR 3 Topic 3 Fail 1 9/16/2006 5:22:31 PM MGR 4 Topic 4 Fair 1 9/16/2006 5:27:29 PM Supervisor 1 Topic 1 Good 1 9/16/2006 5:27:29 PM Supervisor 2 Topic 2 Good 1 9/16/2006 5:27:29 PM Supervisor 3 Topic 3 Good 1 9/16/2006 5:27:29 PM Supervisor 4 Topic 4 Excellent 1 9/16/2006 8:48:23 PM DMG 1 Topic 1 Good 1 9/16/2006 8:48:23 PM DMG 2 Topic 2 Poor 1 9/16/2006 8:48:23 PM DMG 3 Topic 3 Poor 1 9/16/2006 8:48:23 PM DMG 4 Topic 4 Fail 1 9/16/2006 8:50:09 PM Chief 1 Topic 1 Excellent 1 9/16/2006 8:50:09 PM Chief 2 Topic 2 Fair 1 9/16/2006 8:50:09 PM Chief 3 Topic 3 Good 1 9/16/2006 8:50:09 PM Chief 4 Topic 4 Good 1 9/16/2006 9:31:19 PM DD 1 Topic 1 Good 1 9/16/2006 9:31:19 PM DD 2 Topic 2 Fair 1 9/16/2006 9:31:19 PM DD 3 Topic 3 Fair 1 9/16/2006 9:31:19 PM DD 4 Topic 4 Poor 1 9/16/2006 10:35:34 PM Supervisor 1 Topic 1 Good 1 9/16/2006 10:35:34 PM Supervisor 2 Topic 2 Good 1 9/16/2006 10:35:34 PM Supervisor 3 Topic 3 Fair 1 9/16/2006 10:35:34 PM Supervisor 4 Topic 4 Fair 1 9/17/2006 9:39:47 AM MGR 1 Topic 1 Fair 1 9/17/2006 9:39:47 AM MGR 2 Topic 2 Fair 1 9/17/2006 9:39:47 AM MGR 3 Topic 3 Fair 1 9/17/2006 9:39:47 AM MGR 4 Topic 4 Fair 1 9/17/2006 12:01:28 PM Supervisor 1 Topic 1 Excellent 1 9/17/2006 12:01:28 PM Supervisor 2 Topic 2 Excellent 1 9/17/2006 12:01:28 PM Supervisor 3 Topic 3 Excellent 1 9/17/2006 12:01:28 PM Supervisor 4 Topic 4 Excellent 1 9/17/2006 9:42:56 PM DMG 1 Topic 1 Good 1 9/17/2006 9:42:56 PM DMG 2 Topic 2 Fair 1 9/17/2006 9:42:56 PM DMG 3 Topic 3 Fair 1 9/17/2006 9:42:56 PM DMG 4 Topic 4 Good 1 9/17/2006 10:24:00 PM MGR 1 Topic 1 Good 1 9/17/2006 10:24:00 PM MGR 2 Topic 2 Fair 1 9/17/2006 10:24:00 PM MGR 3 Topic 3 Poor 1 9/17/2006 10:24:00 PM MGR 4 Topic 4 Good 1 9/17/2006 10:24:00 PM MGR 1 Topic 1 Fail 1 9/17/2006 10:24:00 PM MGR 2 Topic 2 Fail 1 9/17/2006 10:24:00 PM MGR 3 Topic 3 Fail 1 9/17/2006 10:24:00 PM MGR 4 Topic 4 Fail 1 ****************************** I write the sql statement as below. SELECT A.Score, COUNT(A.Score) AS Qty, ( SELECT COUNT(B.Score) FROM dbo_Tbl_Questionare as B WHERE B.Score <= A.Score ) AS Acc FROM dbo_Tbl_Questionare AS A GROUP BY A.Score; ****************************** It seems OK Score Qty Acc Excellent 6 6 Fail 6 12 Fair 18 30 Good 17 47 Poor 5 52 ****************************** but i want to order the result SELECT A.Score, COUNT(A.Score) AS Qty, ( SELECT COUNT(B.Score) FROM dbo_Tbl_Questionare as B WHERE B.Score <= A.Score ) AS Acc FROM dbo_Tbl_Questionare AS A GROUP BY A.Score ORDER BY COUNT(A.Score) DESC ; ***************************** The result does not correct Score Qty Acc Fair 18 30 Good 17 47 Excellent 6 12 Fail 6 6 Poor 5 52 ***************************** Actually, I need the calculated result as following Score Qty Acc Fair 18 18 Good 17 35 Excellent 6 41 Fail 6 47 Poor 5 52 How can I solve this problem? Thanks in advance. Gogzilla |
|||||||||||||||||||||||