我在 SQLITE
中有一个具有以下结构的数据库表Name Count Type
Roy 3 CA
Roy 2 BT
John 2 CA
John 1 BT
需要一个可以显示上述数据的查询(sqlite)
Name count CA BT
Roy 5 3 2
John 3 2 1
感谢
答案 0 :(得分:0)
SQLite中没有透视,但您可以使用大量子查询:
SELECT DISTINCT name,
(SELECT sum([count]) FROM test tst WHERE tst.name = test.name) as count,
(SELECT sum([count]) FROM test tst WHERE tst.name = test.name AND type='CA') as CA,
(SELECT sum([count]) FROM test tst WHERE tst.name = test.name AND type='BT') as BT
FROM test
假设表名为“test”