sql - Help! MySQL Query -
i need single line query. must dumb or over-thinking mysql query. please solving following query.
lets there 2 simple tables: class
, books
class
id--name-----students
1------kg-----------20
2------grade(3)---25
3------grade(5)---30
books
id--classid--title-------------cost
1-----1--------------drawing------------------5
2-----3--------------history--------------------25
3-----1--------------a-to-z--------------------10
4-----2--------------alphabets---------------20
5-----3--------------maths--------------------15
6-----2--------------english-------------------30
lets say:
know -----> id
of class
have find ---> book cost of class. (books each students in class)
can have single line of query?
try this:
in single line:
select sum(class.students * books.cost) bookcost books inner join class on books.classid = class.classid books.classid = <class-id-value> group books.classid
with formatting:
select sum(class.students * books.cost) bookcost books inner join class on books.classid = class.classid books.classid = <class-id-value> group books.classid
Comments
Post a Comment