MySQL Query for book cost of a class

后端 未结 6 773
清酒与你
清酒与你 2021-01-21 17:39

I just need a single MySQL line query for the following.

Lets say there are 2 simple tables: Class and Books<

6条回答
  •  感情败类
    2021-01-21 18:09

    This should do the trick:

    SELECT SUM(cost) AS cost FROM Books WHERE ClassId=? GROUP BY ClassId

    Where the question makr is either the ID of the class or part of a prepared statement where you feed it the class ID.

    You can retrieve the sum with column name "cost".

提交回复
热议问题