Developed the SQL
Fixed some SQL