SELECT
c.customer_Id, SUM(total_amt), DATEDIFF(YEAR, DOB, GETDATE()) as DOB
FROM
Transactions T
INNER JOIN
Customer C ON T.cust_id = C.customer_Id
GROUP BY
c.customer_Id, DATEDIFF(YEAR, DOB, GETDATE())
HAVING
(DATEDIFF(YEAR, DOB, GETDATE()) BETWEEN 25 AND 35)
AND (SELECT tran_date
FROM Transactions
HAVING tran_date BETWEEN DATEADD (DAY , -30, MAX(tran_date)) AND MAX(tran_date))
I am getting this error while executing the above code:
Msg 4145, Level 15, State 1, Line 136
An expression of non-boolean type specified in a context where a condition is expected, near ')'
SELECT tran_date ...
subquery returns some dataset, not boolean. MaybeEXISTS
operator is lost? But it is non-correlated, "always true" in general, and it uses explicit GROUP BY.\ – Akina