如何大写一件事但留下另一件事情不敏感?

时间:2017-09-14 17:13:42

标签: mysql sql

这是我的疑问:

select invoice_number, invoice_date, invoice_total, invoice_due_date, date_format(invoice_due_date, 'Due in %M %Y') as month_due
from active_invoices

order by invoice_total desc

Here's my output

如何让它看起来像这样?

Wanted output

1 个答案:

答案 0 :(得分:1)

使用案例陈述在7月6月过滤并应用不同的大写条件。

SELECT invoice_number
    , invoice_date
    , invoice_total
    , invoice_due_date
    , CASE 
        WHEN month(invoice_due_date) = 7
            THEN date_format(invoice_due_date, 'Due in %M %Y')
        WHEN month(invoice_due_date) = 6
            THEN date_format(invoice_due_date, 'DUE IN %M %Y')
        END AS month_due
FROM active_invoices
ORDER BY invoice_total DESC