Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Greatest_N_Per_Group
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
--Sql Server 2014 Express Edition --Batches are separated by 'go' CREATE TABLE CitizenPowerLevel ("KeyID" int, "CitizenID" int, "RandomSystemID" int, "ParentID" int, "Quality" varchar(8), "Begin" DateTime, "End" DateTime, "Power" decimal(8,4)) ; INSERT INTO CitizenPowerLevel ("KeyID", "CitizenID", "RandomSystemID", "ParentID", "Quality", "Begin", "End", "Power") VALUES (98554, 40, 0, 0, 'Mediocre', '2010-02-19 02:00:00', '2010-02-19 02:00:00', 3), (98632, 40, 11, 309, 'Special', '2010-10-05 19:21:00', '2010-10-05 19:21:00', 4.2), (98704, 40, 11, 322, 'Special', '2010-10-05 19:22:00', '2010-10-05 19:22:00', 5), (99208, 40, 11, 309, 'Special', '2011-02-15 19:56:00', '2011-02-15 19:56:00', 3.9), (99279, 40, 11, 322, 'Special', '2011-02-15 19:56:00', '2011-02-15 19:56:00', 6), (106337, 40, 11, 309, 'Special', '2015-02-27 15:25:00', '2015-02-27 15:25:00', 4.8), (106406, 40, 11, 322, 'Special', '2015-02-27 15:25:00', '2015-02-27 15:25:00', 5.4), (98545, 172, 0, 0, 'Mediocre', '2010-02-19 02:00:00', '2010-02-19 02:00:00', 0.5), (98622, 172, 11, 309, 'Special', '2010-10-05 19:21:00', '2010-10-05 19:21:00', 1.1), (98694, 172, 11, 322, 'Special', '2010-10-05 19:22:00', '2010-10-05 19:22:00', 1.3), (99340, 172, 11, 309, 'Special', '2011-04-29 20:08:00', '2011-04-29 20:08:00', 1.4), (99409, 172, 11, 322, 'Special', '2011-04-29 20:08:00', '2011-04-29 20:08:00', 1.02), (65923, 187, 0, 0, 'System', '2008-12-17 03:00:00', '2008-12-17 03:00:00', 1.3) ; WITH CTE AS ( SELECT *, RN = ROW_NUMBER() OVER(PARTITION BY CitizenID, ParentID ORDER BY [End] DESC) FROM citizenPowerLevel WHERE Quality = 'Special' ) SELECT [Power], CitizenID, ParentID FROM CTE WHERE RN = 1;
View schema
Execution time: 0,02 sec, rows selected: 4, rows affected: 13, absolute service time: 0,17 sec
fork mode
|
history
|
discussion
Power
CitizenID
ParentID
1
4,8000
40
309
2
5,4000
40
322
3
1,4000
172
309
4
1,0200
172
322