DQL知识总结

- 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 ‘%裤%';

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值