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

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 February 26th, 2004, 12:40 PM
neoprem neoprem is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 37 neoprem User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
creating a SQL Query

Hi friends!
I am facing a difficulty in creating a query in SQL.
I have a table name as master which has fields
------------------------------------------------------------------
pid | pretailPrice | pourPrice | cat
------------------------------------------------------------------
1 10 8 1
2 8 7 1
3 7 5 1
------------------------------------------------------------------

I am trying to create a query, which calculates discount between pretailprice and pourprice and the output should give the maximum discount from all the records for a particular category i.e 1.


Please help
Thank you.

Reply With Quote
  #2  
Old February 27th, 2004, 03:45 AM
Kris_Vanherck's Avatar
Kris_Vanherck Kris_Vanherck is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Belgium, Antwerp
Posts: 177 Kris_Vanherck User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 24 sec
Reputation Power: 5
SELECT MAX(pourPrice - pretailPrize) as Discount
FROM master
GROUP BY cat

Reply With Quote
  #3  
Old February 27th, 2004, 04:34 AM
neoprem neoprem is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 37 neoprem User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Thanx Kris,
The output comes as the max diffrence,
but we need to calculate the maximum percentage of discount

If we have 3 records for a single category..
---------------------------------------------------------------------------
for eg1 Retail Price is 10, Our Price is 8
equation is 10-8/10 % ---- out put is 20%

for eg2 Retail Price is 8, Our Price is 8
equation is 8-7/7 % ---- out put is 12.5%

for eg2 Retail Price is 7, Our Price is 5
equation is 7-5/7 % ---- out put is 28.57%
---------------------------------------------------------------------------

Now the max is 28.57% correct...I need to prepare a SQL statement which gived the max discounted percentage.
I am Sorry for not mentioning percentage before.
Thank u.

Reply With Quote
  #4  
Old February 27th, 2004, 06:27 AM
Kris_Vanherck's Avatar
Kris_Vanherck Kris_Vanherck is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Belgium, Antwerp
Posts: 177 Kris_Vanherck User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 24 sec
Reputation Power: 5
SELECT MAX((1 - (pourPrice / pretailPrize))*100) as Discount
FROM master
GROUP BY cat

Reply With Quote
  #5  
Old February 28th, 2004, 05:09 AM
neoprem neoprem is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 37 neoprem User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Thanx Kris.
Thanks for your help..
I modified your query a bit and got the result..
Thank you.
Thanx a lot for your time.
Thanx again

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft SQL Server > creating a SQL Query


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 2 hosted by Hostway
Stay green...Green IT