Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.databases.ms-sqlserver > #1397
| Path | csiph.com!usenet.pasdenom.info!news.albasani.net!eternal-september.org!feeder.eternal-september.org!mx05.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | tony@mountifield.org (Tony Mountifield) |
| Newsgroups | comp.databases.ms-sqlserver |
| Subject | Re: How do I write this sql statement |
| Date | Wed, 20 Feb 2013 14:42:07 +0000 (UTC) |
| Organization | Software Insight Ltd., Winchester, UK |
| Lines | 32 |
| Sender | tony@softins.clara.co.uk |
| Message-ID | <kg2nbv$tph$1@softins.clara.co.uk> (permalink) |
| References | <kg2mau$13a$1@dont-email.me> |
| Injection-Info | mx05.eternal-september.org; posting-host="09af9bc7e07dd1219c95b5a7ae50821c"; logging-data="6917"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18YWg4RqVh4FmMPujyBIbhgD8VGW0Ql2D4=" |
| X-Newsreader | trn 4.0-test76 (Apr 2, 2001) |
| Cancel-Lock | sha1:YIy452z+Z909B7hKnhdEE9aTwis= |
| Xref | csiph.com comp.databases.ms-sqlserver:1397 |
Show key headers only | View raw
In article <kg2mau$13a$1@dont-email.me>, Tony <tony.johansson@inport.com> wrote: > In the database we have a column called grefnr and loopnr. > Each record could have something like the following se below. I want to > select the record with the highest loopnr number for every grefnr. > In this example I would get the following three record 1 78 and 2 95 and 3 > 99 > How can I write this sql > grefnr loopnr > 1 34 > 1 12 > 1 78 > 1 35 > 2 4 > 2 72 > 2 70 > 2 95 > 3 11 > 3 16 > 3 99 > 3 7 Try this: SELECT grefnr,MAX(loopnr) FROM yourtable GROUP BY grefnr Cheers Tony -- Tony Mountifield Work: tony@softins.co.uk - http://www.softins.co.uk Play: tony@mountifield.org - http://tony.mountifield.org
Back to comp.databases.ms-sqlserver | Previous | Next — Previous in thread | Find similar
How do I write this sql statement "Tony" <tony.johansson@inport.com> - 2013-02-20 15:25 +0100 Re: How do I write this sql statement tony@mountifield.org (Tony Mountifield) - 2013-02-20 14:42 +0000
csiph-web