---
title: "MySQL 程序式写法"
author: "greybeard"
date: "2012-04-28T17:14:21Z"
tags: []
categories: ["数据库"]
slug: "mysql"
draft: false
lastmod: "2012-04-28T17:17:10Z"
id: 1503827
url: "https://greybeard.iteye.com/blog/1503827"
---

1. IF
if (condition, result1, result2)
IF(expr1 is not null, expr1, expr2) 等价于 ifnull(expr1, expr2)
   ifnull()效率胜过if()

2. Case
case 
 when day(MaxDate)<=10 then 1
 when day(MaxDate)<=20 then 2
 else 3
end