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 |
|
bpsintl
Posting Yak Master
132 Posts |
Posted - 2008-10-27 : 07:22:58
|
| Hi, I need help with a complicated query.I have 2 tables in question, members and swim_times.The tables are joined together on members.member_id = swim_times.memberid but here's where it gets complicated:There are the following fields in the swim_times tableeventid (int)pool_size (int)location (varchar)stroke (int)swim_time (varchar)Now, this table is for storing swimmers swim times. The eventid is from another table and holds the swim distances like 25m, 100m, 200m etcThe pool_size is either 50 or 25The location is a free text field that the user can input when adding the swim timeThe stroke field is either 1, 2, 3, 4 or 5The swim_time is a varchar field storing the swim times like 00:47:71 (mm:ss:ms)I want to be able to select the swimmers best time (one result) for each of the variables like pool_size, stroke, eventid, location etcAny ideas?Here's the query that joins the tablesselect swim_times.*, members.*from members inner join swim_times on members.member_id = swim_times.memberid |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-27 : 07:41:05
|
| [code]select m.memberid,m2.eventid,m2.pool_size,m2.stroke,m2.location,CONVERT(varchar(8),m2.besttime,108)from members minner join (select memberid,eventid,pool_size, stroke,location,min(dateadd(hh,0, swim_time)) as besttimefrom swim_timesgroup by memberid,eventid,pool_size, stroke,location)m2on m.memberid=m2.memberid[/code] |
 |
|
|
bpsintl
Posting Yak Master
132 Posts |
Posted - 2008-10-27 : 08:00:20
|
| I should have said, I know this is not the right forum but my db is MySQL. Do you know the syntax that would work for MySQL? |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-27 : 08:02:50
|
quote: Originally posted by bpsintl I should have said, I know this is not the right forum but my db is MySQL. Do you know the syntax that would work for MySQL?
Nope..i dontIn that case..post this in MySQL forums like www.dbforums.com |
 |
|
|
bpsintl
Posting Yak Master
132 Posts |
Posted - 2008-10-27 : 08:07:57
|
| Cheers |
 |
|
|
|
|
|
|
|