Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 是否可以编写一个将总和(金额)分为两列的查询?_Sql_Sqlite_Join - Fatal编程技术网

Sql 是否可以编写一个将总和(金额)分为两列的查询?

Sql 是否可以编写一个将总和(金额)分为两列的查询?,sql,sqlite,join,Sql,Sqlite,Join,我有这样的MyTbl Id type amount -- ---- ------ 1 1 100 2 1 200 3 2 300 4 2 400 是否可以在Android中为sqlite编写一个查询来返回这个结果 Amount1 Amount2 ------- ------- 300 700 我编写了以下查询,但它不正常: select SUM(a.amount) as Amount1, SUM(b.am

我有这样的MyTbl

Id  type    amount
--  ----    ------
1   1       100
2   1       200
3   2       300
4   2       400
是否可以在Android中为sqlite编写一个查询来返回这个结果

Amount1 Amount2
------- -------
300     700
我编写了以下查询,但它不正常:

select SUM(a.amount) as Amount1, SUM(b.amount) as Amount2 from MyTbl a inner join MyTbl b
on a.id = b.id
group by a.type
它返回:

Amount1 Amount2
------- -------
300     300
700     700

SELECT
    SUM(CASE WHEN type = 1 THEN amount ELSE 0 END) amount1,
    SUM(CASE WHEN type = 2 THEN amount ELSE 0 END) amount2
FROM MyTbl