I have 2 tables in my sqlite3 database. Can someone help me with the sql command below:
tbltrans:
transid | transdate | discountpercentage | Bank
12345 10/09/2011 5 20.00
tbltrans2:
transid | itemnr |price | btwpercentage | qty
12345 205 10.11 12 5
12345 302 15.00 6 7
12345 501 20.00 21 3
My first question is:
-
I want to get a query table with total amount of sale for each transid’s and calculated cash, like:
Select Sum(tbltrans2.qty * tbltrans2.price) as TotalAmount, (Totalamount - tbltrans.Bank) as Cash where tbltrans.transid = tbltrans2.transid and transdate = '10/09/12'Can someone please correct this SQL statement ?
— This question below is already solved —
So, can anyone correct my sql code to work with this table layout:
select
sum(price * qty - (price * qty) * (tbltrans.discountpercentage / 100)
from
tbltrans2
where
btwpercentage = 6) as total6 ,
sum(price * qty - (price*qty)*(tbltrans.discountpercentage /100) from tbltrans2 where btwpercentage =12) as total12,
sum(price * qty - (price*qty)*(tbltrans.discountpercentage /100) from tbltrans2 where btwpercentage =21) as total21
where transdate = date('10/09/2011')
You should be able to join the tables and use something like this:
See SQL Fiddle with Demo
Based on your comments, you can also use: