Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
jonasdavedomingo
Starting Member
33 Posts |
Posted - 2004-09-11 : 03:03:45
|
Ok, Ive two tables named TBL_REPORTS that has 3 columns which are rep_RefNo, rep_PointID, and rep_Counter, and TBL_POINTS that has 2 columns which are pt_ID and pt_Points.Let's say TBL_REPORTS has 2 rows:rep_RefNo_______rep_PointID_______rep_Counter__0001_____________2_______________7__0002_____________1_______________11and TBL_POINTS has 2 rows:pt_ID_______pt_Points__1___________20__2___________50query = "SELECT * FROM TBL_REPORTS ORDER BY POINTS"; I want to get all the rows in TBL_REPORTS where i will add the points and counter of each row. For row one, the total points must be 50 + 7 = 57 while row 2 has 20 + 11 = 31. and I want to sort the 2 rows in ascending order based on the total points. so in this case, row 2 must be displayed first because the total points is 31 while row 1's total points is 57.I wana know what is the query for that. thanks! |
|
|
mwjdavidson
Aged Yak Warrior
735 Posts |
Posted - 2004-09-11 : 05:19:24
|
| SELECTr.rep_RefNo, r.rep_Counter + p.pt_Points AS PointsFROMdbo.TBL_REPORTS AS rJOIN dbo.TBL_POINTS AS pON r.rep_PointID = p.pt_IDORDER BYr.rep_Counter + p.pt_PointsMark |
 |
|
|
jonasdavedomingo
Starting Member
33 Posts |
Posted - 2004-09-11 : 07:05:53
|
| ok thanks. i got it! |
 |
|
|
|
|
|