- DQL基础查询-- 简化版语法:-- select *|列名 from 表 where 条件-- 准备数据库和表create database mydb2;use mydb2;-- 创建商品表create table product(pid int primary key auto_increment, -- 商品编号pname varchar(20) not null , -- 商品名字price double, -- 商品价格category_id varchar(20) -- 商品所属分类);-- 简单查询-- 1.查询所有的商品. select pid,pname,price,category_id from product;select * from product;-- 2.查询商品名和商品价格. select pname,price from product;-- 3.别名查询.使用的关键字是as(as可以省略的). -- 3.1表别名: select*from product as p;select*from product p;-- 3.2列别名:select pname as '商品名',price'商品价格' from product;-- 4.去掉重复值. distinct(去重)select distinct pname from product;select distinct *from product;-- 5.查询结果是表达式(运算查询):-- 运算符操作-算数运算符-- 将每件商品的价格加10select pname,price+10 as new_price from product;-- 将所有商品的价格上调10%select pname,price*1.1 as new_price from product;-- 运算符操作-条件运算符-- 查询商品名称为“海尔洗衣机”的商品所有信息:select * from product where pname='海尔洗衣机';-- 查询价格为800商品select * from product where price=800; -- 查询价格不是800的所有商品select * from product where price!=800;select * from product where price <> 800;select * from product where not (price = 800);-- 查询商品价格大于60元的所有商品信息select * from product where price >=60; -- 查询商品价格在200到1000之间所有商品-- 查询商品价格是200或800的所有商品select * from product where price = 200 or price = 800;select * from product where price in (200,800); -- 查询含有‘裤'字的所有商品select * from product where pname like ‘%裤%';
DQL知识总结
最新推荐文章于 2024-09-29 08:44:52 发布