mysql流程函数存储引擎InnoDB简单特性(一)

2015-07-24 11:32:16 · 作者: · 浏览: 14
建表及插入数据语句:

mysql> create table salary(userid int,salary decimal(9,2));
Query OK, 0 rows affected (0.11 sec)
mysql> insert into salary values(1,1000),(2,2000),(3,3000),(4,4000),(5,5000),(1,
null);
Query OK, 6 rows affected (0.13 sec)
Records: 6 Duplicates: 0 Warnings: 0

1.if(value,t,f)函数:这里认为高于2000就是'high',其他都是low

mysql> select if(salary>2000,'high','low') from salary;
+------------------------------+
| if(salary>2000,'high','low') |
+------------------------------+
| low |
| low |
| high |
| high |
| high |
| low |
+------------------------------+
6 rows in set (0.00 sec)

2.ifnull(value1,value2)函数:这个函数可以用来将NULL值换成0

mysql> select ifnull(salary,0) from salary;
+------------------+
| ifnull(salary,0) |
+------------------+
| 1000.00 |
| 2000.00 |
| 3000.00 |
| 4000.00 |
| 5000.00 |
| 0.00 |
+------------------+
6 rows in set (0.00 sec)

3.case when [value1] then [result]...else [default] end函数:

mysql> select case when salary<=2000 then 'low' else 'high' end from salary;
+---------------------------------------------------+
| case when salary<=2000 then 'low' else 'high' end |
+---------------------------------------------------+
| low |
| low |
| high |
| high |
| high |
| high |
+---------------------------------------------------+
6 rows in set (0.00 sec)

4.case [expr] when [value1] then [result] ... else [default] end函数:

mysql> select case salary when 1000 then 'low' when 2000 then 'mid' else 'high'e
nd from salary;
+----------------------------------------------------------------------+
| case salary when 1000 then 'low' when 2000 then 'mid' else 'high'end |
+----------------------------------------------------------------------+
| low |
| mid |
| high |
| high |
| high |
| high |
+----------------------------------------------------------------------+
6 rows in set (0.02 sec)

5.关于mysql存储引擎的一些东西:

存储引擎是mysql不同于其他
数据库的一个重要特性,用户可以根据实际需要利用这个特性定制自己的存储引擎. mysql的引擎有: mysql> show engines \G; *************************** 1. row *************************** Engine: MyISAM Support: YES Comment: Default engine as of MySQL 3.23 with great performance *************************** 2. row *************************** Engine: MEMORY Support: YES Comment: Hash based, stored in memory, useful for temporary tables *************************** 3. row *************************** Engine: InnoDB Support: DEFAULT Comment: Supports transactions, row-level locking, and foreign keys *************************** 4. row *************************** Engine: BerkeleyDB Support: NO Comment: Supports transactions and page-level locking *************************** 5. row *************************** Engine: BLACKHOLE Support: NO Comment: /dev/null storage engine (anything you write to it disappears) *************************** 6. row *************************** Engine: EXAMPLE Support: NO Comment: Example storage engine *************************** 7. row *************************** Engine: ARCHIVE Support: YES Comment: Archive storage engine *************************** 8. row *************************** Engine: CSV Support: NO Comment: CSV storage engine *************************** 9. row *************************** Engine: ndbcluster Support: NO Comment: Clustered, fault-tolerant, memory-based tables *************************** 10. row *************************** Engine: FEDERATED Support: NO Comment: Federated MySQL storage engine *************************** 11. row *************************** Engine: MRG_MYISAM Support: YES Comment: Collection of identical MyISAM tables *************************** 12. row *************