Statistics of the total number of a SQL statement and the number of states

Demand: There are X copies of agreement, XX copies have been signed, X copies to be signed

sql:

 select count(1) 总记录数,
 sum(case when XY_STATUS='1' then 1 else 0 end)待签,
 sum(case when XY_STATUS='2' then 1 else 0 end)已签  
 from  YG.T_ZHGL

result:

count(1): all data,

case when XY_STATUS='1' then 1 else 0 end: If XY_STATUS=1, return 1 otherwise return 0

sum: accumulate the return value.

Guess you like

Origin blog.csdn.net/qq_36802726/article/details/90177673
Recommended