筛选 SQL table 以显示基于 "invoice_status" 的总计

Filtering SQL table to display totals based on an "invoice_status"

背景:我正在为一个项目开发一些存储过程,并希望根据我创建的名为 "invoice_status" 的列规定的特定标准显示总收入——该列的数据类型为 ENUM 并且只允许 "Delivered"、"Processing" 和 "Shipping"

这样的名称

我想创建一个程序来显示列为 "Delivered" 的发票的总收入。到目前为止,这是我的 sql:

 select invoice_id, total_cost, invoice_status from invoice
 union
 select count(invoice_id), sum(total_cost), null
 from invoice;

我尝试使用“where invoice_status = "Delivered"”过滤结果,但这不会影响总和和计数值

有什么想法吗?

两个查询都需要条件

 select invoice_id, total_cost, invoice_status from invoice
 where invoice_status = "Delivered"
 union
 select count(invoice_id), sum(total_cost), null
 from invoice
 where invoice_status = "Delivered";