Advanced searches using SQL

I am interested in creating searches with actual SQL. For example, I would like to create a seach using “count” or “join”. These searches will eventually be used in dashboards. If possible, I’d like to make some charts out of these searches as well. Any ideas?