码迷,mamicode.com
首页 > 数据库 > 详细

SQL Cookbook:检索记录

时间:2017-05-04 11:11:00      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:length   查询   class   short   bsp   concat   优先级   info   where   

1、where子句中,and优先级比or高

1 select * from film where film_id < 10 or title like %ARK and length = 50\G

等同于以下查询:

1 select * from film where film_id < 10 or (title like %ARK and length = 50)\G

 

2、连接列值:concat

1 select concat(title: , title,  description: , description) as info from film\G

 

3、使用case语句

1 select title, 
2 case 
3     when length <= 70 then short 
4     when length > 70 then long 
5 end 
6 as info from film where film_id = 1\G

 

4、随机选择n条数据

1 select film_id, title from film order by rand() limit 5\G

 

5、查找空值

1 select film_id, title from film where title is null\G

null要使用is

 

6、为空值设定默认值

1 select film_id, coalesce(title, ‘‘) as title from film\G

 

SQL Cookbook:检索记录

标签:length   查询   class   short   bsp   concat   优先级   info   where   

原文地址:http://www.cnblogs.com/zcy-backend/p/6805529.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!