我有两个用于查询表中行的SQL查询tContentNode,具体取决于类型2或3。 Query 1:
tContentNode
SELECT count(*) _countA FROM TCONTENTNODE WHERE type = '2' AND parentid ='02b3abc2-4983-485a-ab09-1a8cb328b9b5';
Query 2:
SELECT count(*) _countB FROM TCONTENTNODE WHERE type = '3' AND parentid ='02b3abc2-4983-485a-ab09-1a8cb328b9b5';
现在,我只想获取_countA和_countB使用一个查询的值。如何使用一个查询获得计数。有没有办法做到这一点。我正在使用SQLite数据库。
_countA和_countB
编辑:我想要分别为_countA和的值,而_countB不是两者都在一起(不使用IN)。
_countA
尝试使用 group by
group by
SELECT type,count(*) as cnt FROM TCONTENTNODE WHERE parentid ='02b3abc2-4983-485a-ab09-1a8cb328b9b5'; group by type
for two variables:
SELECT COUNT(case TCONTENTNODE.type when '2' then 1 end) as _countA, COUNT(case TCONTENTNODE.type when '3' then 1 end) as _countB FROM TCONTENTNODE WHERE TCONTENTNODE.parentid ='02b3abc2-4983-485a-ab09-1a8cb328b9b5';