Mysql
如何對另一個查詢結果進行查詢操作
如何使用 sql 查詢從以下結果中獲得批准、未批准、已刪除的計數。
SELECT approved,deleted_at,count(id)AS count FROM `payment_voucher` WHERE company_id = 1 GROUP BY approved,deleted_at;
我將上述查詢結果作為圖像附加。
所需輸出:已批准:32 not_approved:4已刪除:7
SELECT SUM(CASE WHEN (approved=1) AND (deleted_at IS NULL) THEN `count` END) approved, SUM(CASE WHEN (approved=0) AND (deleted_at IS NULL) THEN `count` END) not_approved, SUM(CASE WHEN deleted_at IS NOT NULL THEN `count` END) deleted FROM (your subquery) source