我们有一个像这样的表:
Customer ItemNumber Item_Name Qty FOCQty
C1 I1 ABC 10 2
C2 I2 BCA 12 2
C3 I1 ABC 3 3
C4 I2 BCA 05 1
但是我们希望它是这样的:
ItemNumber Item_Name Qty FOCQty
I1 ABC 13 5
I2 BCA 17 3
我们尝试了以下方法:
tx.executeSql('SELECT ItemNumber,Item_Name,sum(Qunatity) as Qunatity1 ,sum(FOCQty) as FOCQty1\
from toCSV5\
Where ItemNumber=?',[this.UpdateItemNumber],SumSuccess,errorCB);
但这对我们没有用。请告诉我们代码中的错误。
最佳答案
固定
调整动态SQL字符串以在ItemNumber,Item_Name
字段上添加分组依据,如下所示
静态查询
SELECT ItemNumber,Item_Name,sum(Qunatity) as Qunatity1 ,sum(FOCQty) as FOCQty1
from toCSV5
where ItemNumber = 'I1'
group by ItemNumber,Item_Name
;
输出
+------------+-----------+-----------+---------+
| ItemNumber | Item_Name | Qunatity1 | FOCQty1 |
+------------+-----------+-----------+---------+
| I1 | ABC | 13 | 5 |
+------------+-----------+-----------+---------+
sqlfiddle链接
关于sqlite - SUM()函数在sqLite中不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30421331/