I have a CodeIgniter website and i’m building some stats for the retailer. I need to find the sum of product_cost for all products sold, where the product ‘category1’ is equal to 1.
The data structure below shows ‘products’ and ‘order_items’, which as the name suggests contains all the items sold.
products
---
product_id
category1
product_price
product_cost
order_items
---
order_id
product_id
quantity
So basically I am trying to get the correct SQL statement in CodeIgniter to form a function in my orders_model.
Grateful for any help. 🙂
Assuming you are not using Active Record and just want a simple query, this should give you the result you need:
Active Record will look something like this: