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 |
|
omega1983
Starting Member
40 Posts |
Posted - 2010-06-17 : 10:49:28
|
| SELECT giftid, Max(giftjntamt) AS MaxOfgiftjntamt,gifteffdat FROM gifts_VIEWWHERE (((gifteffdat)>= '7/1/2005') AND ((giftacctdv)='5' Or (giftacctdv)='15'))and giftid = '0000054529'GROUP BY giftid,gifteffdat ORDER BY giftidI am trying to get the largest gift and the gifteffective date associated with that gift. I am okay when I leave out the gifteffective date. When I add the gifteffective date I get all dates in which the person gave. I only want one row, the largest amount and the gifteffective date associated with it. Any ideas on how I can rewrite my formula |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2010-06-17 : 11:06:55
|
| [code]select a.giftid,a.MaxOfgiftjntamt,b.gifteffdatfrom(select giftid, Max(giftjntamt) AS MaxOfgiftjntamtFROM gifts_VIEWWHERE gifteffdat > '20050701'AND giftacctdv in ('5','15')and giftid = '0000054529') ainner join gifts_VIEW b on a.giftid = b.giftid and a.MaxOfgiftjntamt = b.giftjntamt[/code] |
 |
|
|
omega1983
Starting Member
40 Posts |
Posted - 2010-06-17 : 11:47:44
|
When I run the query I get an error giftid' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause. I inserted group by giftid and still get the errorquote: Originally posted by vijayisonly
select a.giftid,a.MaxOfgiftjntamt,b.gifteffdatfrom(select giftid, Max(giftjntamt) AS MaxOfgiftjntamtFROM gifts_VIEWWHERE gifteffdat > '20050701'AND giftacctdv in ('5','15')and giftid = '0000054529') ainner join gifts_VIEW b on a.giftid = b.giftid and a.MaxOfgiftjntamt = b.giftjntamt
|
 |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2010-06-17 : 13:36:27
|
quote: Originally posted by omega1983 When I run the query I get an error giftid' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause. I inserted group by giftid and still get the errorquote: Originally posted by vijayisonly
select a.giftid,a.MaxOfgiftjntamt,b.gifteffdatfrom(select giftid, Max(giftjntamt) AS MaxOfgiftjntamtFROM gifts_VIEWWHERE gifteffdat > '20050701'AND giftacctdv in ('5','15')and giftid = '0000054529') ainner join gifts_VIEW b on a.giftid = b.giftid and a.MaxOfgiftjntamt = b.giftjntamt
Oops..it should beselect a.giftid,a.MaxOfgiftjntamt,b.gifteffdatfrom(select giftid, Max(giftjntamt) AS MaxOfgiftjntamtFROM gifts_VIEWWHERE gifteffdat > '20050701'AND giftacctdv in ('5','15')and giftid = '0000054529'GROUP BY giftid) ainner join gifts_VIEW b on a.giftid = b.giftid and a.MaxOfgiftjntamt = b.giftjntamt |
 |
|
|
|
|
|
|
|