sql >> Base de Datos >  >> RDS >> Mysql

Consulta MySQL para el costo del libro de una clase

Prueba esto:

En una sola línea:

SELECT SUM(Class.Students * Books.Cost) AS BookCost  FROM Books INNER JOIN Class       ON Books.ClassId = Class.ClassId WHERE Books.ClassId = <CLASS-ID-VALUE>  GROUP BY Books.ClassId

Con formato:

SELECT SUM(Class.Students * Books.Cost) AS BookCost
  FROM Books INNER JOIN Class
   ON Books.ClassId = Class.ClassId
WHERE Books.ClassId = <CLASS-ID-VALUE>
GROUP BY Books.ClassId