Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
max3elements
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
create table x(element varchar(10), group_value int, value int); insert into x values ('a', 1, 2000),('a', 2, 1500),('a', 2, 2500),('b', 1, 1000); with maxgv as ( select element, max(group_value) maxg from x group by element ) select x.element, x.group_value, x.value from maxgv inner join x on x.element = maxgv.element and x.group_value = maxgv.maxg ; with grp as ( select element, group_value, value, rank() over (partition by element order by element, group_value desc) rn from x ) select element, group_value, value from grp where rn = 1; drop table x;
absolute service time: 0,43 sec
edit mode
|
history
element
group_value
value
1
a
2
1500
2
a
2
2500
3
b
1
1000
element
group_value
value
1
a
2
1500
2
a
2
2500
3
b
1
1000