My table StoreCodes holds unique products codes (and their availablity) for each store, eg:
category:integer
code:string
available:boolean
store_id:reference
I'm trying to show a simple table with 3 columns showing how many codes are in each category, AND how many of those codes have available = true
Category_number / Count_Codes_in_category / Count_Codes_in_category_available==TRUE
In my controller, the following attempt to COUNT and GROUP on both category and available throws this error:
SQLite3::SQLException: near "WHERE": syntax error: SELECT category, available, COUNT(*) AS instances GROUP BY category, available WHERE (store_id = 8)
My controller code:
@b2 = StoreCode.find_by_sql ['SELECT category, available, COUNT(*) AS instances GROUP BY category, available WHERE (store_id = ?)', @store.id]