sql - Column 'ITEMS_MASTER.QUANTITY' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause -
select id.item_model, sum(id.amount) total_amount, avg(id.rate) avg_rate, im.quantity item_details id inner join items_master im on id.item_model = im.item_model im.item_model='keyboard' group id.item_model
i wrote above query, want extract data 2 tables item_details
, items_masters
when run showing me error:
column 'items_master.quantity' invalid in select list because not contained in either aggregate function or group clause.
can suggest me correct way of doing this.
try this:
select im.item_model, im.quantity, sum(id.amount) total_amount, avg(id.rate) avg_rate items_master im inner join item_details id on id.item_model = im.item_model im.item_model = 'keyboard' group im.item_model, im.quantity
generally speaking, when have parent table (items_master) has multiple rows child table (item_details), want group columns in parent table. more logical , on databases performs better.
Comments
Post a Comment