SQL queries for matrix multiplication