关于数据库:mysql面试DQL

0次阅读

共计 579 个字符,预计需要花费 2 分钟才能阅读完成。

查问表中的数据

语法

select 
      字段列表
from 
      表名列表
where
      条件列表
group by
      分组字段
having
      分组之后的条件
order by
      排序
limit
      分页限定;

根底查问

-- 查问 姓名 和 年龄
SELECT 
    NAME, -- 姓名
    age -- 年龄
FROM 
    student; -- 学生表
    
-- 去除反复的后果集
SELECT DISTINCT address FROM student;
SELECT DISTINCT address,NAME FROM student;

-- 计算 math 和 english 分数之和

SELECT NAME,math,english,math+english FROM student;
-- 如果有 null 参加的运算,计算结果都为 null
SELECT NAME,math,english,math+IFNULL(english,0) FROM student;
-- 起别名
SELECT NAME,math,english,math+IFNULL(english,0) AS 总分 FROM student;
SELECT NAME,math 数学,english 英语,math+IFNULL(english,0) 总分 FROM student;

条件查问

1.where 字句后跟条件
2. 运算符
    >、<、<=、>=、=、<>
    between and
    in (汇合)
    like
    is null
    and 或 &&
    or 或 ||
    not 或 !

例子

含糊查问

正文完
 0