mysql学习打卡day20

今日成果:

SELECT * FROM sql_invoicing.invoices;
select count(invoice_id) as invoice_record_total,  -- 统计内容不包括空值
count(payment_date) as payment_date_record,
count(*) as invoice_record_totals,            -- 统计内容包括空值
sum(invoice_total) as invoice_total_sum,
count(distinct client_id) as client_record    -- 去除重复统计内容 
from invoices;

select 
   'First half of 2019' as date_range,
   sum(invoice_total) as total_sales,
   sum(payment_total) as total_payments,
   sum(invoice_total-payment_total) as expect
from invoices
where invoice_date between '2019-01-01' and '2019-06-30'
union
select 
   'Second half of 2019' as date_range,
   sum(invoice_total) as total_sales,
   sum(payment_total) as total_payments,
   sum(invoice_total-payment_total) as expect
from invoices
where invoice_date between '2019-07-01' and '2019-12-31'
union
select 
   'Total' as date_range,
   sum(invoice_total) as total_sales,
   sum(payment_total) as total_payments,
   sum(invoice_total-payment_total) as expect
from invoices
where invoice_date between '2019-01-01' and '2019-12-31'
-- 综合使用

感谢各位读者查阅,欢迎各位点赞✍评论⭐收藏+关注!

你可能感兴趣的:(linux,运维,服务器)