这是我的疑问:
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
如何让它看起来像这样?
答案 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