i'm getting error "error near from" in sqlite, couldn't find faults in query. doing wrong?
select tbltrans2_temp.itemcode, tbltrans2_temp.itemname, sum(tbltrans2_temp.qty) qty tbltrans_temp inner join tbltrans2_temp on tbltrans2_temp.transid = tbltrans_temp.transid tbltrans_temp.saledate='11/07/2013' group tbltrans2_temp.itemcode union select tbltrans2.itemcode, tbltrans2.itemname, sum(tbltrans2.qty) qty, tbltrans inner join tbltrans2 on tbltrans2.transid = tbltrans.transid tbltrans.saledate='11/07/2013' group tbltrans2.itemcode
there ,
before second from
remove it:
select tbltrans2_temp.itemcode, tbltrans2_temp.itemname, sum(tbltrans2_temp.qty) qty tbltrans_temp inner join tbltrans2_temp on tbltrans2_temp.transid = tbltrans_temp.transid tbltrans_temp.saledate='11/07/2013' group tbltrans2_temp.itemcode union select tbltrans2.itemcode, tbltrans2.itemname, sum(tbltrans2.qty) qty, <<<<------------------- tbltrans inner join tbltrans2 on tbltrans2.transid = tbltrans.transid tbltrans.saledate='11/07/2013' group tbltrans2.itemcode
update
to sum of qty
both table, put query in subquery , sum in outer one, can omit sum
in inner query , in outer one:
select itemcode, itemname, sum(qty) totalqty ( select tbltrans2_temp.itemcode, tbltrans2_temp.itemname, sum(tbltrans2_temp.qty) qty tbltrans_temp inner join tbltrans2_temp on tbltrans2_temp.transid = tbltrans_temp.transid tbltrans_temp.saledate='11/07/2013' group tbltrans2_temp.itemcode union select tbltrans2.itemcode, tbltrans2.itemname, sum(tbltrans2.qty) qty tbltrans inner join tbltrans2 on tbltrans2.transid = tbltrans.transid tbltrans.saledate='11/07/2013' group tbltrans2.itemcode ) t group itemcode, itemname;
Comments
Post a Comment