我是一个新的Android开发人员,我想从三个表中获取sqlite数据库中的数据,例如ItemMaster,ItemGroupMaster,SalesDetail
使用此查询后:选择sd.salesDate,igm.groupName,im.itemName,im.itemprice from salesdetails sd inner join itemmaster im on sd.itemId = im.itemId inner join itemgroupmaster igm on im.groupId = igm.groupId
结果
请帮帮我 提前致谢
答案 0 :(得分:0)
试试这个。 Qty
和NetAmount
列都是聚合,NetAmount
依赖于Qty
,因此我使用了几个嵌套查询:
SELECT Y.salesDate
, Y.GroupName
, Y.ItemName
, Y.Qty
, Y.Price
, Y.Price * Y.Qty AS NetAmount
FROM
(SELECT X.salesDate
, X.groupName AS GroupName
, X.itemName AS ItemName
, X.itemprice AS Price
, COUNT(*) AS Qty
FROM
(SELECT sd.salesDate
,igm.groupName
,im.itemName
,im.itemprice
FROM salesdetails sd
INNER JOIN itemmaster im
ON sd.itemId = im.itemId
INNER JOIN itemgroupmaster igm
ON im.groupId = igm.groupId
) X
GROUP BY 1,2,3
) Y
GROUP BY 1,2,3,4,5
ORDER BY 1,2,3,4,5