mysql必知必会(四、检索数据,五、排序检索数据,六、过滤数据,七、数据过滤)
四、select语句
1、检索单个列
select prod_name from products;
2、检索多个列
select prod_name, prod_price from products;
3、检索所有列
select * from products;
4、检索不同的行
select distinct vend_id from products;(vend_id只返回不同的值)
5、限制结果
select prod_name from products limit 开始位置,检索行数;
6、使用完全限定的表名
select products.prod_name from products;
select products.prod_name from crashcourse.products;
五、排序检索数据
1、根据prod_name排序
select prod_name from products order by prod_name;
2、按多个列排序
select prod_id, prod_price, prod_name from products order by prod_price, prod_name;
3、指定排序方向
select prod_id, prod_price, prod_name from products order by prod_price desc;(desc降序,asc升序)
select prod_id, prod_price, prod_name from products order by price_price desc, prod_name;
select prod_price from products order by prod_price desc limit 1;
六、过滤数据
1、使用where子句
select prod_name, prod_price from products where prod_price=2.50;
where支持
=,<>,!=,<,<=,>,>=,between
2、检查单个值
select prod_name, prod_price from products where prod_name = 'fuses';
3、范围检查
select prod_name, prod_price from products where prod_price between 5 and 10;
4、空值检查
select prod_name from products where prod_price is null;
七、数据过滤
1、and操作符
select prod_id, prod_price, prod_name from products where vend_id = 1003 and prod_price <= 10;
2、or操作符
select prod_name, prod_price from product where vend_id = 1002 or vend_id = 1003;
3、计算次序
select prod_name, prod_price from products where vend_id = 1002 or vend_id = 1003 and prod_price >= 10;(先and在or)
select prod_name, prod_price from products where (vend_id = 1002 or vend_id = 1003 )and prod_price >= 10
4、in操作符
select prod_name, prod_price from products where vend_id in (1002, 1003) order by prod_name;
5、not操作符
select prod_name, prod_price from products where vend_id not in (1002, 1003) order by prod_name;
最新文章
- Zabbix(二)--第一台主机监控及触发器
- TAR命令详解
- SVN使用教程总结[转]
- OC基础--Hello Shit
- iOS5可能会删除本地文件储存 - Caches 也不安全
- MSF溢出实战教程
- Atmega8型号细分区别
- php 实现文件下载,兼容IE、Firefox、Chrome等浏览器
- 【USACO 1.4.2】时钟
- (原)mkl的cblas_sgemm和cblas_dgemm
- 允许Android随着屏幕转动的控制自由转移到任何地方(附demo)
- deeplearning.ai 卷积神经网络 Week 4 特殊应用:人脸识别和神经风格转换 听课笔记
- LNK2026	模块对于 SAFESEH 映像是不安全的
- ●BZOJ 3551 [ONTAK2010]Peaks(在线)
- ERROR: Cannot change version of project facet Dynamic Web Module to 3.0?
- This application failed to start because it could not find or load the Qt platform plugin异常
- SSM商城项目(十一)
- [leetcode]200. Number of Islands岛屿个数
- c# WPF 设置窗口一直在其中窗口后面/底层窗口
- MCU编程_基础
热门文章
- java技术选型
- JAVA单向链表实现
- JAVA基础知识之jdk下载与安装
- iOS 9应用开发教程之ios9的视图
- iOS 9应用开发教程之定制应用程序图标以及真机测试
- [ 转载 ] Java开发中的23种设计模式详解(转)
- [ 原创 ] Java基础5--abstract class和interface的区别
- Java 中的浮点数取精度方法
- luoguP4279 [SHOI2008]小约翰的游戏 Anti-SG 博弈论
- luoguP4208 [JSOI2008]最小生成树计数 矩阵树定理