sorkIndustries
Technical User
Hi, I'm posting in General because I didn't see a specific forum for SQLite. Here's my question:
I am having difficulty using SQLite. I have a table, let's say it's called Inventory and its fields are Product and Store, like this:
Product+Store
---------|---------
Pen | Bookstore
Soda | Drugstore
Journal | Bookstore
Pen | Supermarket
Paper | Drugstore
Paper | Bookstore
etc., and I want to produce a query that shows, for each object, how many of them there are in each store.
I know I can make a bunch of Case statements, like so:
but this isn't good because if I ever add another type of store then I have to change the code.
If I was using Access I could use Transform and Pivot to build the query how I want it, but these don't seem to be available in SQLite, as using them produces syntax errors.
I am having difficulty using SQLite. I have a table, let's say it's called Inventory and its fields are Product and Store, like this:
Product+Store
---------|---------
Pen | Bookstore
Soda | Drugstore
Journal | Bookstore
Pen | Supermarket
Paper | Drugstore
Paper | Bookstore
etc., and I want to produce a query that shows, for each object, how many of them there are in each store.
I know I can make a bunch of Case statements, like so:
Code:
Select Product,
sum(case store when bookstore then 1 else 0) as Bookstore,
sum(case store when drugstore then 1 else 0) as Drugstore,
sum(case store when supermarket then 1 else 0) as Supermarket
From Inventory
Group By Product;
but this isn't good because if I ever add another type of store then I have to change the code.
If I was using Access I could use Transform and Pivot to build the query how I want it, but these don't seem to be available in SQLite, as using them produces syntax errors.