churn=# select count(cust_cod) from churn where no_of_mon=7 and cust_cod not in
(select distinct(cust_cod) from churn where no_of_mon<=6 );
count
-------
86
(1 row)
churn=# select count(cust_cod) from churn where no_of_mon=8 and cust_cod not in
(select distinct(cust_cod) from churn where no_of_mon<=7 );
count
-------
69
(1 row)
churn=# select count(cust_cod) from churn where no_of_mon=9 and cust_cod not in
(select distinct(cust_cod) from churn where no_of_mon<=8 );
count
-------
17
(1 row)
churn=# select count(cust_cod) from churn where no_of_mon=10 and cust_cod not in
(select distinct(cust_cod) from churn where no_of_mon<=9 );
count
-------
18
(1 row)
churn=# select count(cust_cod) from churn where no_of_mon=11 and cust_cod not in
(select distinct(cust_cod) from churn where no_of_mon<=10 );
count
-------
18
(1 row)
churn=# select count(cust_cod) from churn where no_of_mon=12 and cust_cod not in
(select distinct(cust_cod) from churn where no_of_mon<=11 );
count
-------
65
(1 row)
the above query looks like a loop, how can i make a query like a loop
i want a query which displays like
month count
7 86
8 69
9 17
10 18
11 18
12 65