IBM developerWorks
           ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion 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 Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old March 7th, 2005, 10:50 AM
jpixel jpixel is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 47 jpixel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 50 m 41 sec
Reputation Power: 4
this simple query question making my life hell!

What is needed: The system should provide the facility to view a list of vehicles currently under auction, together with their reserve prices, the number of bids for each vehicle and the current highest bid for each one.

These are the access tables:



reserve price is a column in the stock table, the owner checks a box AuctionCar to make it visible to the auction and enters the reserve price there.

Moving onto the bids table, here we see auction cars being bid on, there is an auctionID, id(this is the carID), userID and their bid. Simple.

So why on earth am I having so much trouble trying to create a simple report page that list all cars from the bids table, tells me how many bids they have and the highest bid placed for that car?? I can't even seem to understand how to do it as a concept, any help appreciated! thanks

Reply With Quote
  #2  
Old March 7th, 2005, 11:44 AM
FALCONSEYE FALCONSEYE is offline
Permanently Banned
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 377 FALCONSEYE Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 1 Day 16 h 57 m 14 sec
Warnings Level: 15
Number of bans: 1
Reputation Power: 0
The system should provide the facility to view a list of vehicles currently under auction, together with their reserve prices, the number of bids for each vehicle and the current highest bid for each one.

how do you track if the auction for a particular vehicle has ended or not? also the number of bids for each vehicle? i couldn't see any field to represent these info on your tables.

Reply With Quote
  #3  
Old March 7th, 2005, 12:15 PM
jpixel jpixel is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 47 jpixel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 50 m 41 sec
Reputation Power: 4
at the moment the owner concludes the auction whenever he wants, just to keep it simple, so there's no time element yet.

number of bids each vehicle should work like this: basically in the bids table the vehicle no 47 occurs twice, so that would mean it has two bids, simple as that, and the rest have one bid each.

My problem is that I don't know how to sum up these occurences for each distinct id number...

Highest bid would be, for example in the case of vehicle 47, 6400 (out of 5000 and 6400 it is the largest bid placed), so this is pretty simple too but dont know how to query it...thats it

Reply With Quote
  #4  
Old March 7th, 2005, 02:55 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,618 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 9 h 44 m 33 sec
Reputation Power: 53
First, it should be noted that things that sound simple to explain can sometimes be difficult to write SQL for. That said, I think something like this might work (not tested though, obviously):

select s.ID, s.makeID, s.modelID, max(b.highBid) as highestBid, count(b.id) as bidCount
from
stock s,
bids b
where s.id = b.id
group by s.ID, s.makeID, s.modelID
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian.
How to Post a Question in the Forums

Reply With Quote
  #5  
Old March 7th, 2005, 05:45 PM
jpixel jpixel is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 47 jpixel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 50 m 41 sec
Reputation Power: 4
I just tried it, I think it's pretty close, but for some reason no results are displayed (i got cfoutput query setup don't worry!).

if possible could you briefly explain this query, in particular the groupings? I think it's very close!

Reply With Quote
  #6  
Old March 7th, 2005, 06:50 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,618 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 9 h 44 m 33 sec
Reputation Power: 53
To test whether the query is working or not just dump it:

<cfdump var="#myQueryName#">

Info on SQL's GROUP BY operator: http://www.w3schools.com/sql/sql_groupby.asp

Reply With Quote
  #7  
Old March 7th, 2005, 08:04 PM
jpixel jpixel is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 47 jpixel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 50 m 41 sec
Reputation Power: 4
thanks man, ur amazing, i got it working, ur sql just needed a few tweaks:

<cfquery name="getids" datasource="hj">
SELECT s.id, s.makeID, s.modelID, s.AuctionReserve, s.AuctionCar, MAX(b.highBid) as highestBid, COUNT(b.id) as bidCount
FROM
stock s LEFT JOIN bids b
ON s.id = b.id
WHERE s.AuctionCar = 1
GROUP BY s.id, s.makeID, s.modelID, s.AuctionReserve, s.AuctionCar
</cfquery>

the s.AuctionCar is a checkbox, if it's checked then the car is an auction car (also just want auction cars listed...)

and left join seemed to do the trick...I'm amazed that all that information can be taken from just one query!! I honestly thought it would be impossible

Reply With Quote
  #8  
Old March 7th, 2005, 09:21 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,618 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 9 h 44 m 33 sec
Reputation Power: 53
Not sure why you'd need to use a LEFT JOIN because I can't imagine a situation where you would have bids with no corresponding ID in the stock table. But whatever works.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > this simple query question making my life hell!


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