|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Comparing rows for given dates. Help!
Hope somebody can help with this, I can't figure out a solution. The data in my table looks something like this, I'll use
footballers and their salaries as an analogy :-) e.g. Call the table TBL_SALARY The table contains data for lots of different players, and their salaries for each date of the year. I need the user to be able to select any dates in the year, and I must return the change in salary for those two dates. Therefore the two dates are passed to the query. Date | Player | Salary 12/05 | Zidane | 20,000 13/05 | Zidane | 30,000 14/05 | Zidane | 40,000 15/05 | Zidane | 50,000 12/05 | Henry | 30,000 15/05 | Henry | 50,000 What I am trying to work out is the DIFFERENCE in the Salary figure for each player, for any given two dates. The user has the choice of the two dates. Do I need to use a dot operator or something like that when comparing rows in the same table? Because I'd have to use something like "SELECT OldSalary.Salary, NewSalary.Salary, (NewSalary-OldSalary) As DIFFERENCE FROM TBL_SALARY WHERE OldSalary.Date = 12/05 AND NewSalary.Date = 15/05" This would need to return Player Old New Difference Zidane 20,000 50,000 30,000 Henry 30,000 50,000 20,000 If theres an easier way to do this, let me know, I'd really appreciate any help. |
|
#2
|
||||
|
||||
|
You could try something like this
Code:
SELECT player, MIN(salary) AS Old_Salary, MAX(salary) AS ' New_Salary ', MAX(salary) - MIN(salary) AS ' Difference ' FROM tblSalary GROUP BY player |
|
#3
|
||||
|
||||
|
Quote:
HJey why you just don't want use <%Salary = RS("NewSalary") - RS("OldSalary")%> <%=Salary%> |
|
#4
|
|||
|
|||
|
beercraft_asp
You need to remember that not everyone is using ASP here, also somethings are better served to be solved in a SQL statement then in ASP/VB/C# Code. IF you have to create this output for 10,000 records you wouldn't want to caclulate each record independent of a quick and easy SQL statement. S- |
![]() |
| Viewing: ASP Free Forums > Database > SQL Development > Comparing rows for given dates. Help! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|