Jump to content

Recommended Posts

Basically ive followed all the coding for finding duplicates in a database and counting them..

 

yet Im using... SELECT *, HORSE, COUNT( * ) AS count FROM ULTIMATEHISTORICAL GROUP BY HORSE ORDER BY DATE DESC

 

 

lets say theres an entry I know is in there 19 times.... and the latest entry was today...  how does it grab all count and show me the lastest entry date?

 

the above I would think would work.. but it only shows all entries from today as the singles..  like  A  2015-06-06 count 1.. B 2015-06-06count 1 C 2015-06-06 count 1   ,,,, but no D 2015-06-06 count 19

 

just all the singles?..  if I do find the entrie manually in the database it grabs an entry from 2015-05-05  meanwhile I see 6 indentical entries created today 2015-06-06..  but its not using them.

 

is this confusing?..  any help would be great thanks!

 

 

Oh and of course it doesn't stop there. lol

 

Im using SELECT HORSE, TRACK, RACE, JOCKEY, TRAINER, OWNER, MAX( DATE ) AS latest, COUNT( * ) AS count FROM ULTIMATEHISTORICAL GROUP BY HORSE ORDER BY latest DESC, TRACK ASC, RACE ASC, COUNT DESC

 

works great..then I noticed..   MAX (DATE) AS latest... how do I get it to grab from that MAX DATE line..  TRACK, RACE, JOCKEY, TRAINER, OWNER from the DB for those lines.. the MAX DATE lines?

 

Its not actually grabbing TRACK, RACE, JOCKEY, TRAINER, OWNER from the same MAX DATE AS latest lines.. Its grabbing them from other lines.. not the same MAX DATE AS LATEST lines..

 

Like lets say LUCKY count 9 and date 2015-06-07 is today.. the track comes up as BELMONT...  meanwhile the last race LUCKY raced was at belmont.. and today 2015-06-07 LUCKY runs at CHURCHILL track.. so   "TRACK" isnt grabbing "TRACK" from the line where MAX(DATE) AS lastest is on.  get me? need it too do that as well as jockey trainer etc.. also.

 

 

Thanks again!

Edited by 0o0o0

Use a table subquery to get the aggregated stuff and match the main table against that on horse and date
 

SELECT uh.HORSE
, uh.TRACK
, uh.RACE
, uh.JOCKEY
, uh.TRAINER
, uh.OWNER
, uh.DATE,
, tots.count
FROM ULTIMATEHISTORICAL uh
INNER JOIN (
    SELECT HORSE,
    , MAX( DATE ) AS DATE
    , COUNT( * ) AS count
    FROM ULTIMATEHISTORICAL
    GROUP BY HORSE  
    ) tots
    USING (HORSE, DATE)
ORDER BY DATE DESC, TRACK ASC, RACE ASC, COUNT DESC

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.