I have two tables that have data that I need a count from
Login History
and
Login Attempts
One is a Login History table that does not include Login Attemtps.
The primary key of Login History is REF_ID, but also contains Customer_ID. The Login Attempts table’s also includes Customer_ID
I’m trying to get a count of login attempts and login history for specific Customer_id’s. I’ve gotten a list of Customer_ID’s and placed them in a temporary table “#a”
Here’s the query I’m trying to use to get this count.
SELECT COUNT (la.customer_ID) as login_attempts FROM
LOGIN_ATTEMPTS la
JOIN LOGIN_HISTORY lh
on la.Customer_ID = lh.customer_ID
where la.customer_ID in (select Customer_ID from #a)group by la.customer_ID
The result set I would need is the Customer_ID’s, and the count for each Customer’s login attempts and history next to it. I’ve tried a few different ways, and I always end up with errors with my GROUP BY or COUNT syntax.
I’m also assuming I could add a SUM function in here somewhere but I’m not sure how I would need to structure it. Thanks for the help in advance!
This is a variation on @bummi’s second approach, without the additional subqueries: