• SQL Cookbook:检索记录


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

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

    等同于以下查询:

    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 filmG

    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 = 1G

    4、随机选择n条数据

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

    5、查找空值

    1 select film_id, title from film where title is nullG

    null要使用is

    6、为空值设定默认值

    1 select film_id, coalesce(title, '') as title from filmG
  • 相关阅读:
    hdu 2222 Keywords Search
    Meet and Greet
    hdu 4673
    hdu 4768
    hdu 4747 Mex
    uva 1513 Movie collection
    uva 12299 RMQ with Shifts
    uva 11732 strcmp() Anyone?
    uva 1401
    hdu 1251 统计难题
  • 原文地址:https://www.cnblogs.com/zcy-backend/p/6805529.html
Copyright © 2020-2023  润新知