hello, I am a kind of new to sql and I am struggling to automatize a report.
I have 2 tables. I need to fill the Count column in table1 based on tabl2
i need to count every ID from table1 to see how many times appears in table 2 but based on some criterias:
- the value from table2 mut be >50000 and
- the start date from table 1 must be <= than the date from table2
for instance the ID=7264451 from table 1 it repeats 4 times in table 2 but only 2 times matches the criterias mentioned above.
I only could count how many times the ID repeats in table2:
select table1 ID, count(table2 ID) as count
from table1 left join table2
on table1 ID=table2 ID
group by table1 ID
i have no idea how to put those clauses. It would be great if someone could help or give me a hint.