Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Urgent help on sql

Author  Topic 

abdulmukhtar
Starting Member

1 Post

Posted - 2011-08-01 : 01:44:06
Hi All,

I have two tables.
Table1 has two columns. First column is the date and second column is the customer ID.
Table2 has two columns. First column is the CustomerId and Second column is the flag which tells whether loan has been offered to the customer or not.

Requiremnt is that i want an output with 3 columns
First column is the date from the first table
Second column is the count of all the rows in the first table
Third Column is the result of inner join of two tables and the count of all the rows of the result where flag is 'Yes'.

Please help me

Acuvate

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-08-01 : 04:18:35
do you mean this?

select t1.date,count(t1.customerid),count(case when t2.flag='yes' then t2.customerid else null end)
from table1 t1
left join table2 t2
on t2.customerid = t1.customerid


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -