Ok - hoping someone can help as I'm struggling here. Have tried using sum(case when), count(*), subqueries with no success. Essentially I have two queries I am trying to combine into one, grouped by the same parameter. The queries:
Query 1:
SELECT
u.username,
count(*) as 'Total'
FROM log1 L1
JOIN users u on u.userref = L1.userref
WHERE L1.date between @FromDate and @ToDate
GROUP BY u.username
ORDER BY u.username
Query 2:
SELECT
u.username,
count(*) as 'Total'
FROM log2 L2
LEFT JOIN users u on u.userref = L2.userref
WHERE L2.date between @FromDate and @ToDate and L2.message like '%None%'
GROUP BY u.username
ORDER BY u.username
What I would like is a single query with a username column (u.username), a column showing the results of query 1, and a column showing the results of query two. Any help appreciated!
You can put a case statement inside the count function to only count when certain criteria is met:
Of note:
EDIT
Completely missed that you had two separate log tables: