SQL queries to join static and real-time data