mysql - How to SUM from another table in SQL in one view? -
mysql - How to SUM from another table in SQL in one view? -
i have 2 tables maintable , secondtable
in sec table column maintable_id , price.
i have bulided view in workbench this:
create view test select maintable.id id, maintable.name name, maintable.date date, secondtable.price price, maintable left bring together secondtable on maintable.id=secondtable.maintable_id
i have thought create like:
sum(price) gprice secondtable maintable.id=secondtable.maintable_id
how can find out total cost items in secondtable secondtable.maintable_id= maintable.id
thank help.
try this..
create view test select maintable.id id, maintable.name name, maintable.date date, sum (secondtable.price) gprice, maintable left bring together secondtable on maintable.id=secondtable.maintable_id grouping maintable.id id, maintable.name name, maintable.date date
mysql sql sql-server mysql-workbench
Comments
Post a Comment