sql基础之select语句(一)

sql语句是专门与数据库交互的语言,支持多种DBMS,不区分大小写!

一、检索语句

1.检索单列所有行数据:select user_name from users;

2.检索多个列所有数据:select user_id,user_name,user_sex from users;

3.检索所有列:select * from users;

4.检索不同的值:select distinct user_name from users;

5.检索指定前5行的数据:

    ①sqlServer/Access:select top 5 user_name from users;

    ②DB2:select user_name from users fetch first 5 rows only;

    ③Oracle: select user_name from users where rownum <= 5;

    ④Mysql:select user_name from users limit 5;

        1>返回从第五行起的5行数据:select user_name from users limit 5 offset 5;

6.排序语句:select user_age from users order by user_age;  

    ①使用order by 语句是,必须保证其是sql语句中的最后一条字句

    ②对多列进行排序:select user_age,user_name from users order by user_age desc,user_name;(user_age倒序,user_age正序)

7.where语句:select user_name from users where user_age = 18;

    ①范围查询:select user_name from users where user_age between 18 and 20;

    ②空值查询:select user_name from users where user_age is null;

    ③组合查询:select user_name from users where user_age = 18 and user_sex = '男';

    ④求值查询:select user_name from users where (user_age = 18 or user_age = 20) and user_sex = '男'

        1>在sql语句中,连接条件的执行顺序为:()> and > or

        2>上述语句还可改为:select user_name from users where user_age in (18,20) and user_sex = '男'

8.通配符过滤查询:select * from users where user_name like '张%';(查询所有姓名为张开头的所有用户信息)

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值