• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • MsSql
  • Mysql
  • oracle
  • MariaDB
  • DB2
  • SQLite
  • PostgreSQL
  • MongoDB
  • Redis
  • Access
  • 数据库其它
  • sybase
  • HBase
您的位置:首页 > 数据库 >Mysql > 【MySQL 01】查询--总结

【MySQL 01】查询--总结

作者:匿名 字体:[增加 减小] 来源:互联网 时间:2018-12-05

匿名通过本文主要向大家介绍了MySQL,查询,总结等相关知识,希望本文的分享对您有所帮助
【MySQL 01】查询--总结

/*
 * 本程序专为总结MySQL而写!
 * @author kevinelstri
 * @time 2016/7/14
 * */
package Database;

public class Database01 {

    public static void main(String[] args){
        System.out.println("本程序专为总结MySQL而写!");

    /* 
     * --------------------------------------------MySQL基本操作-------------------------------------------------
     * 
     * mysql的启动:mysql -u root -p
     * mysql服务开启:net start mysql
     * mysql服务关闭:net stop mysql
     * 
     * 创建数据库:create database db_name;
     * 
     * 查看所有数据库:show databases;
     * 
     * 查看某一个数据库:show create database db_name;
     * 
     * 删除数据库:drop database db_name;
     * 
     * 修改数据库:alter database db_name[修改指令];
     * 
     * 创建表:create table db_name;
     *     在表的创建过程中,至少包括一个属性:
     *     create table test.class( //使用test.class表示在数据库test中创建一个class表
     *     class_no varchar(20);    //创建表的过程中,至少要创建一个属性
     *     data_time date
     *     );
     *     
     * 使用数据库:use db_name;//表示在接下来的过程中都会使用这个数据库
     * 
     * 查看数据库中的表:show tables;//查看使用的数据库中的所有的表
     * 
     * 获取具有某种规则的表:show table [like '%'];
     * 
     * 查看某个表的创建信息:show create table exam_student;
     *                      show create table exam_student\G;
     * 
     * 查看表的结构:describe table_name;
     *              desc table_name;
     *              
     * 删除表:drop table table_name;
     * 
     * 修改表名:rename table old_table_name to new_table_name;
     * 
     * crud:增删改查(create、retrieve、update、delete)
     * 
     * 创建数据/插入数据:insert into 表名 (字段列表) values (值列表)
     *         insert into exam_table (name,stu_no) values ('Mary',001);
     *         
     * 查询数据:select (字段列表) from 表名  查询条件
     *          select (name,stu_no) from exam_student where stu_no > 002;
     *          select * from exam_student;
     *          
     *          
     * 删除数据:delete from exam_student where stu_no=1;   
     * 
     * 修改数据:update 表名 set 字段=新值....条件
     *          update exam_student set score=90 where stu_no='002';
     *          update exam_student set name='Lily' where stu_no='001';
     * 
     * 查看变量:show variables;
     * 
     * -------------------------------------------MySQL高级操作-----------------------------------------
     * 
     * 【distinct】查询不重复数据:select distinct country from website;
     *       //注意 distinct的用法,使重复元素只显示一次
     * 
     * 【where】子句:select * from website where id=1;
     *      //where子句查询特定条件的数据
     *      select name from website where country='CN';
     * 
     * 【and or】子句:select * from website where country='CN';
     *             +------+---------+-----------------------+-------+---------+
     *             | id   | name    | url                   | alexa | country |
     *             +------+---------+-----------------------+-------+---------+
     *             |    2 | taobao  | http://www.taobao.com |    13 | CN      |
     *             |    3 | cainiao | http://www.runoob.com |   673 | CN      |
     *             |    4 | weibo   | http://weibo.com      |    20 | CN      |
     *             +------+---------+-----------------------+-------+---------+
     * 
     *           select * from website where country='CN' or country='USA'; //or是或者关系 
     *             +------+----------+-------------------------+-------+---------+
     *             | id   | name     | url                     | alexa | country |
     *             +------+----------+-------------------------+-------+---------+
     *             |    1 | Google   | http://www.google.com   |     1 | USA     |
     *             |    2 | taobao   | http://www.taobao.com   |    13 | CN      |
     *             |    3 | cainiao  | http://www.runoob.com   |   673 | CN      |
     *             |    4 | weibo    | http://weibo.com        |    20 | CN      |
     *             |    5 | Facebook | http://www.facebook.com |    20 | USA     |
     *             +------+----------+-------------------------+-------+---------+
     *           select * from website where country='CN' and country='USA';//and并集关系
     *           Empty set (0.15 sec)
     * 
     *           select * from website where alexa>15 and (country='CN' or country='USA');
                   +------+----------+-------------------------+-------+---------+                   | id   | name     | url                     | alexa | country |
                   +------+----------+-------------------------+-------+---------+                   |    3 | cainiao  | http://www.runoob.com   |   673 | CN      |
                   |    4 | weibo    | http://weibo.com        |    20 | CN      |
                   |    5 | Facebook | http://www.facebook.com |    20 | USA     |
                   +------+----------+-------------------------+-------+---------+
     * 
     * 【order by】排序:desc逆序排列,asc正序排列
     *          select * from website order by name desc;//按姓名逆序排列
                    +------+----------+-------------------------+-------+---------+                    | id   | name     | url                     | alexa | country |
                    +------+----------+-------------------------+-------+---------+                    |    4 | weibo    | http://weibo.com        |    20 | CN      |
                    |    2 | taobao   | http://www.taobao.com   |    13 | CN      |
                    |    1 | Google   | http://www.google.com   |     1 | USA     |
                    |    5 | Facebook | http://www.facebook.com |    20 | USA     |
                    |    3 | cainiao  | http://www.runoob.com   |   673 | CN      |
                    +------+----------+-------------------------+-------+---------+                    5 rows in set (0.18 sec)

                select * from website order by name asc;//按姓名正序排列
                    +------+----------+-------------------------+-------+---------+                    | id   | name     | url                     | alexa | country |
                    +------+----------+-------------------------+-------+---------+                    |    3 | cainiao  | http://www.runoob.com   |   673 | CN      |
                    |    5 | Facebook | http://www.facebook.com |    20 | USA     |
                    |    1 | Google   | http://www.google.com   |     1 | USA     |
                    |    2 | taobao   | http://www.taobao.com   |    13 | CN      |
                    |    4 | weibo    | http://weibo.com        |    20 | CN      |
                    +------+----------+-------------------------+-------+---------+
     * 
     * 
     * 【update】更新表中的数据:mysql> update website
     *                          -> set alexa=32,country='CN'
     *                          -> where id=7;
     *       
     *          mysql> select * from website;
                +------+----------+-------------------------+-------+---------+                | id   | name     | url                     | alexa | country |
                +------+----------+-------------------------+-------+---------+                |    1 | Google   | http://www.google.com   |     1 | USA     |
                |    2 | taobao   | http://www.taobao.com   |    13 | CN      |
                |    3 | cainiao  | http://www.runoob.com   |   673 | CN      |
                |    4 | weibo    | http://weibo.com        |    20 | CN      |
                |    5 | Facebook | http://www.face
  


 
分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • 分享下mysql各个主要版本之间的差异
  • MySQL essential版本和普通版本有什么区别?
  • redhat 5.4下安装MYSQL全过程
  • 如何用SQL命令查看Mysql数据库大小
  • 解析mysql中如何获得数据库的大小
  • 解析mysql修改为utf8后仍然有乱码的问题
  • 5个常用的MySQL数据库管理工具详细介绍
  • 解析在MySQL里创建外键时ERROR 1005的解决办法
  • 解析远程连接管理其他机器上的MYSQL数据库
  • mysql 精简过程(删除一些文件)

相关文章

  • 2018-12-05MySQL基础教程15 — SQL语法之数据操作语句DML—DELETE语法
  • 2017-05-11MySql修改数据库编码为UTF8避免造成乱码问题
  • 2018-12-05关于视图更新注意要点汇总
  • 2018-12-05MySQL 数据类型 详解
  • 2018-12-05Oracle中查询本月星期5的所有日期列表的语句
  • 2018-12-05 mysql进阶(四)mysql中select
  • 2018-12-05详解Mysql数据库之主从分离实例代码
  • 2017-05-11mysql 存储过程中变量的定义与赋值操作
  • 2018-12-05MySQL优化-常用函数代码详解(图)
  • 2017-05-11什么是blob,mysql blob大小配置介绍

文章分类

  • MsSql
  • Mysql
  • oracle
  • MariaDB
  • DB2
  • SQLite
  • PostgreSQL
  • MongoDB
  • Redis
  • Access
  • 数据库其它
  • sybase
  • HBase

最近更新的内容

    • MySQL中不能创建自增字段的解决方法
    • 分享一个纯 Python 实现的 MySQL 客户端操作库
    • mysql merge union merge sort_union 的不同
    • MySQL基础教程1 — 数据类型之数值类型
    • MySQL在Linux系统中隐藏命令行中的密码的方法
    • mysql5.7.21解压版安装配置图文
    • 在C#和MySQL中存取中文字符时避免乱码的方法
    • CentOS下Oracle安装
    • Mysql远程访问的开启
    • MySQL基本命令

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有