php - finding the total number of records for a given location -
i have following mysql query:
select sku, quantity, inventory.isbn13, author, title, pub_date, binding, defect.defect, source, location inventory left join location on inventory.location_id = location.location_id left join source on inventory.source_id = source.source_id left join book on inventory.isbn13 = book.isbn13 left join defect on inventory.defect_id = defect.defect_id left join book_condition on book_condition.condition_id = defect.condition_id quantity > '0' , location.location_id >= '986' , location.location_id <= '989' order inventory.location_id, sku which works perfectly, need show total number of books each location id. example location_id 986 has 17 books, location_id 987 has 34 books etc. need run second query information or there way in query have?
jim
here go:
select sku, quantity, inventory.isbn13, author, title, pub_date, binding, defect.defect, source, location, t.cnt inventory inner join ( select inventory.location_id, count(book.isbn13) `cnt` inventory left join book on inventory.isbn13 = book.isbn13 group inventory.location_id ) t on t.location_id = i.location_id inner join location l on i.location_id = l.location_id left join source on i.source_id = source.source_id left join defect on i.defect_id = defect.defect_id left join book_condition on book_condition.condition_id = defect.condition_id i.quantity > '0' , l.location_id >= '986' , l.location_id <= '989'
Comments
Post a Comment