sql - Using distinct and case for two separate columns -


i counting cases year using following code:

count(case when year(filingdate)=2008 1 else null end) '2008' 

and want count these cases when column distinct. other column called 'filingdate' imagine this:

count(case distinct (docketnumber) when year(filingdate)=2008 1 else null end) '2008', 

the sample records:

docketnumber filingdate

123 2008

123 2008

123 2008

111 2009

112 2009

i recieve = 1 ideas?

thanks

use option subquery , group by clause

select count(case when yearfilingdate = 2008 1 end) '2008'  (         select year(filingdate) yearfilingdate, docketnumber   dbo.test55   group year(filingdate), docketnumber   ) x 

demo on sqlfiddle


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -