select products.[name] , sum(orderItems.[price]*orderItems.[quantity]) from orderItems join products on orderItems.[productId] = products.[id] join orders orderItems.orderId = orders.[id] where date like '%27-12-2014%'
I have 3 tables in SQLite database related to each other with a Foreign Key.. Schema is as follows
Table [orderItems]
Fields: 4
[orderId]: INTEGER
[productId]: INTEGER
[quantity]: DOUBLE
[price]: INT
Foreign Keys: 2
[orderId] ([orderId]) REFERENCES [orders]([id]) ON DELETE CASCADE ON UPDATE CASCADE
[productId] ([productId]) REFERENCES [products]([id]) ON DELETE CASCADE ON UPDATE CASCADE
Table [orders]
Fields: 3
[id]: INTEGER
[totalAmount]: INT
[date]: VARCHAR(100)
Foreign Keys: 0
Indexes: 1
[] PRIMARY
[id] AUTOINCREMENT
Table [products]
Fields: 6
[id]: INTEGER
[name]: VARCHAR(1000)
[cost]: INT
[quantity]: DOUBLE
[categoryId]: INTEGER
[type]: VARCHAR(100)
Foreign Keys: 1
[categoryId] ([categoryId]) REFERENCES [productCategories]([id]) ON DELETE CASCADE ON UPDATE CASCADE
Indexes: 1
[] PRIMARY
[id] AUTOINCREMENT
I want to select the amount and quantity of each products sold in one one day but the query is giving error.. Any help will be appreciated
Aucun commentaire:
Enregistrer un commentaire