码迷,mamicode.com
首页 > 数据库 > 详细

MySQL-SQL基础-查询2

时间:2019-01-11 18:03:26      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:desc   primary   font   tom   extra   prim   customer   key   row   


mysql> create table customer(mid char(5) primary key,th date,sex char(1) default 0); Query OK, 0 rows affected (0.01 sec) mysql> desc customer; +-------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+-------+ | mid | char(5) | NO | PRI | NULL | | | name | varchar(20) | YES | | NULL | | | birth | date | YES | | NULL | | | sex | char(1) | YES | | 0 | | +-------+-------------+------+-----+---------+-------+ 4 rows in set (0.01 sec) mysql> insert into customer values(N0001,xiaoxiao,1980-11-23,1); Query OK, 1 row affected (0.00 sec) mysql> insert into customer values(N0002,bobo,1981-12-21,0); Query OK, 1 row affected (0.00 sec) mysql> create table goods(id int auto_increment primary key,name varchar(30)); Query OK, 0 rows affected (0.01 sec) mysql> insert into goods values(1,taotao); Query OK, 1 row affected (0.01 sec) mysql> insert into goods values(2,meimei); Query OK, 1 row affected (0.00 sec) mysql> select * from goods; +----+--------+ | id | name | +----+--------+ | 1 | taotao | | 2 | meimei | +----+--------+ 2 rows in set (0.00 sec) mysql> select * from customer; +-------+----------+------------+------+ | mid | name | birth | sex | +-------+----------+------------+------+ | N0001 | xiaoxiao | 1980-11-23 | 1 | | N0002 | bobo | 1981-12-21 | 0 | +-------+----------+------------+------+ 2 rows in set (0.00 sec) mysql> insert into customer values(G0001,dudu,1975-04-18,0); Query OK, 1 row affected (0.00 sec) mysql> insert into customer values(G0002,yuyu,1985-04-20,1); Query OK, 1 row affected (0.00 sec) mysql> select * from customer; +-------+----------+------------+------+ | mid | name | birth | sex | +-------+----------+------------+------+ | G0001 | dudu | 1975-04-18 | 0 | | G0002 | yuyu | 1985-04-20 | 1 | | N0001 | xiaoxiao | 1980-11-23 | 1 | | N0002 | bobo | 1981-12-21 | 0 | +-------+----------+------------+------+ 4 rows in set (0.00 sec) mysql> select * from goods; +----+--------+ | id | name | +----+--------+ | 1 | taotao | | 2 | meimei | +----+--------+ 2 rows in set (0.00 sec) mysql> select * from customer where birth=NULL; Empty set (0.00 sec) mysql> select name,birth,sex from customer where sex=1 and birth is not null; +----------+------------+------+ | name | birth | sex | +----------+------------+------+ | yuyu | 1985-04-20 | 1 | | xiaoxiao | 1980-11-23 | 1 | +----------+------------+------+ 2 rows in set (0.00 sec) mysql> select name,birth,sex from customer where birth<=1976-01-01 or birth>=1980-01-01 and sex=1; +----------+------------+------+ | name | birth | sex | +----------+------------+------+ | dudu | 1975-04-18 | 0 | | yuyu | 1985-04-20 | 1 | | xiaoxiao | 1980-11-23 | 1 | +----------+------------+------+ 3 rows in set (0.00 sec) mysql> select name,birth,sex from customer where (birth<=1976-01-01 or birth>=1980-01-01) and sex=1; +----------+------------+------+ | name | birth | sex | +----------+------------+------+ | yuyu | 1985-04-20 | 1 | | xiaoxiao | 1980-11-23 | 1 | +----------+------------+------+ 2 rows in set (0.01 sec) mysql> select name,birth,sex from customer order by sex asc,birth desc; +----------+------------+------+ | name | birth | sex | +----------+------------+------+ | bobo | 1981-12-21 | 0 | | dudu | 1975-04-18 | 0 | | yuyu | 1985-04-20 | 1 | | xiaoxiao | 1980-11-23 | 1 | +----------+------------+------+ 4 rows in set (0.00 sec)


 

MySQL-SQL基础-查询2

标签:desc   primary   font   tom   extra   prim   customer   key   row   

原文地址:https://www.cnblogs.com/drizzle-xu/p/10256364.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!