sql - Finding the least in Count(*) -


i'm trying find lid have committed least during given time period. following table:

| requestdate |    bid    |    lid    | percentagecontributed | datecomitted | 1/10/2016   | s7444319c | s2262450a |           0.25        |   18/10/2016 | 1/10/2016   | s7444319c | s4495282i |           0.25        |   7/10/2016 | 1/10/2016   | s7444319c | s4792394d |           0.25        |   28/10/2016 | 1/10/2016   | s7444319c | s7173102k |           0.25        |   9/10/2016 | 25/10/2016  | s9981233w | s2848191x |           1.00        |   13/11/2016 | 28/10/2016  | s7611209x | s2848191x |           0.33        |   13/11/2016 | 28/10/2016  | s7611209x | s4792394d |           0.33        |   4/11/2016 | 28/10/2016  | s7611209x | s7145303q |           0.33        |   5/11/2016 

i have tried following code:

select lid, count(*) totalnumcommitte commits datecommitted between '2015-11-03' , '2017-01-09' group lid 

but managed following:

|    lid    | totalnumcommitte | s2262450a |        1 | s2848191x |        2 | s4495282i |        1 | s4792394d |        2 | s7145303q |        1 | s7173102k |        1 

what want achieve following:

|    lid    | totalnumcommitte | s2262450a |        1 | s4495282i |        1 | s7145303q |        1 | s7173102k |        1 

i have tried following:

select min(totalnumcommitted) (     select lid, count(*) totalnumcommitted     commits     datecommitted >= '2015-11-03'     , datecommitted <= '2017-01-09'     group lid ) t1 

but 1 (which minimum) thank help.

assuming modern sql support common table expressions , ranking functions, this:

;with counts (     select lid, count(*) totalnumcommitte     commits     datecommitted between '2015-11-03' , '2017-01-09'     group lid ), rankedcounts (     select *,rank() on (order totalnumcommitte) rk     counts ) select * rankedcounts rk=1 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -