Hi All,
Ok, I know this isn't really a Perl question. Actually it's not a Perl question at all, although I am using the Perl DBI. I wouldn't normally post a question like this here but this is driving me mad and I need to get a project finished tonight for a deadline.
There is always some clever sod here that knows what to do :)
I've been ripping my hair out trying to get this select to return what I want. Here is what I have so far:-
create table paylist (date int(8), username varchar(12), amount real(12,2))
Some example data:-
INSERT into paylist(date, amount, username) values ('20080101', 10, 'bob'), ('20080102', 20, 'bob'), ('20080103', 5, 'bob'), ('20080102, 0, 'laura')
What I want is to get returned is this:-
20080103, 5, bob
20080102, 0, laura
The real table has lots of different users. Now if I use:-
SELECT MAX( date ) AS m, amount, username
FROM `paylist`
WHERE 1
GROUP BY username
ORDER BY m DESC
I Get:-
20080103, 10, bob
20080102, 0, laura
Seems no matter what I try, I cannot get the amount that corrosponds with the MAX( date ).
Please someone help me.
Thank you.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.