SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseSQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old June 1st, 2004, 05:31 AM
dkitt dkitt is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 1 dkitt User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #2  
Old June 1st, 2004, 09:59 AM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,776 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 8 h 27 m 42 sec
Reputation Power: 470
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

Reply With Quote
  #3  
Old June 1st, 2004, 03:13 PM
beercraft_asp's Avatar
beercraft_asp beercraft_asp is offline
Spell Breaker
ASP Free Novice (500 - 999 posts)
 
Join Date: May 2004
Posts: 990 beercraft_asp User rank is Lance Corporal (50 - 100 Reputation Level)beercraft_asp User rank is Lance Corporal (50 - 100 Reputation Level)beercraft_asp User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 3 Days 8 h 33 m 42 sec
Reputation Power: 5
Send a message via AIM to beercraft_asp Send a message via MSN to beercraft_asp
Arrow

Quote:
Originally Posted by dkitt
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.

HJey why you just don't want use <%Salary = RS("NewSalary") - RS("OldSalary")%>
<%=Salary%>

Reply With Quote
  #4  
Old June 1st, 2004, 05:04 PM
sbaxter sbaxter is offline
Moderator: Access, SQL
ASP Free God (5000 - 5499 posts)
 
Join Date: Oct 2003
Posts: 5,126 sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 1 h 2 m 51 sec
Reputation Power: 13
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-

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseSQL Development > Comparing rows for given dates. Help!


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT