你可以从这样的事情开始:
SELECT logTypeId, Count(logTypeId) AS nbTotal, -1 * Sum(isResolved) AS nbTrue, Count(logTypeId) + Sum(isResolved) As nbFalse
FROM TLogging
GROUP BY logTypeId;
它给出了与您想要的结果大致相同的结果,但已转置。
编辑:或者这个,它很丑,但我认为它给出了你想要的结果
SELECT 'True' As Resolved, t0.nb As LogType0, t1.nb As LogType1, t2.nb As LogType2, t3.nb As LogType3, t4.nb As LogType4, t5.nb As LogType5
FROM (Select -1 * Sum(isResolved) As nb From TLogging Where logTypeId = 0) AS t0
, (Select -1 * Sum(isResolved) As nb From TLogging Where logTypeId = 1) AS t1
, (Select -1 * Sum(isResolved) As nb From TLogging Where logTypeId = 2) AS t2
, (Select -1 * Sum(isResolved) As nb From TLogging Where logTypeId = 3) AS t3
, (Select -1 * Sum(isResolved) As nb From TLogging Where logTypeId = 4) AS t4
, (Select -1 * Sum(isResolved) As nb From TLogging Where logTypeId = 5) AS t5
Union All
SELECT 'False' As Resolved, t0.nb As LogType0, t1.nb As LogType1, t2.nb As LogType2, t3.nb As LogType3, t4.nb As LogType4, t5.nb As LogType5
FROM (Select Count(*) + Sum(isResolved) As nb From TLogging Where logTypeId = 0) AS t0
, (Select Count(*) + Sum(isResolved) As nb From TLogging Where logTypeId = 1) AS t1
, (Select Count(*) + Sum(isResolved) As nb From TLogging Where logTypeId = 2) AS t2
, (Select Count(*) + Sum(isResolved) As nb From TLogging Where logTypeId = 3) AS t3
, (Select Count(*) + Sum(isResolved) As nb From TLogging Where logTypeId = 4) AS t4
, (Select Count(*) + Sum(isResolved) As nb From TLogging Where logTypeId = 5) AS t5
Union All
SELECT 'All' As Resolved, t0.nb As LogType0, t1.nb As LogType1, t2.nb As LogType2, t3.nb As LogType3, t4.nb As LogType4, t5.nb As LogType5
FROM (Select Count(*) As nb From TLogging Where logTypeId = 0) AS t0
, (Select Count(*) As nb From TLogging Where logTypeId = 1) AS t1
, (Select Count(*) As nb From TLogging Where logTypeId = 2) AS t2
, (Select Count(*) As nb From TLogging Where logTypeId = 3) AS t3
, (Select Count(*) As nb From TLogging Where logTypeId = 4) AS t4
, (Select Count(*) As nb From TLogging Where logTypeId = 5) AS t5
;