MySQL之day2

时间:2019-07-04
本文章向大家介绍MySQL之day2,主要包括MySQL之day2使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

 1.建立数据给 product 表格table

 1 mysql> show databases;
 2 +--------------------+
 3 | Database           |
 4 +--------------------+
 5 | information_schema |
 6 | myshool            |
 7 | mysql              |
 8 | performance_schema |
 9 | shop               |
10 | sys                |
11 +--------------------+
12 6 rows in set (0.00 sec)
13 
14 mysql> show tables;
15 +----------------+
16 | Tables_in_shop |
17 +----------------+
18 | product        |
19 +----------------+
20 1 row in set (0.09 sec)
21 
22 mysql> describe product;
23 +----------------+--------------+------+-----+---------+-------+
24 | Field          | Type         | Null | Key | Default | Extra |
25 +----------------+--------------+------+-----+---------+-------+
26 | product_id     | char(4)      | NO   | PRI | NULL    |       |
27 | product_name   | varchar(100) | NO   |     | NULL    |       |
28 | product_type   | varchar(32)  | NO   |     | NULL    |       |
29 | sale_price     | int(11)      | YES  |     | NULL    |       |
30 | purchase_price | int(11)      | YES  |     | NULL    |       |
31 | regist_date    | date         | YES  |     | NULL    |       |
32 +----------------+--------------+------+-----+---------+-------+
View Code

 

1.1  查询所有

  mysql> select * 2 from product; 

 1 mysql> select * from product;
 2 +------------+--------------+--------------+------------+----------------+-------------+
 3 | product_id | product_name | product_type | sale_price | purchase_price | regist_date |
 4 +------------+--------------+--------------+------------+----------------+-------------+
 5 | 0001       | T恤          | 衣服         |       1000 |            500 | 2009-09-20  |
 6 | 0002       | 打孔器       | 办公用品     |        500 |            320 | 2009-09-11  |
 7 | 0003       | 运行T恤      | 衣服         |       4000 |           2800 | NULL        |
 8 | 0004       | 菜刀         | 厨房用品     |       3000 |           2800 | 2009-09-20  |
 9 | 0005       | 高压锅       | 厨房用品     |       6800 |           5000 | 2009-01-15  |
10 | 0006       | 叉子         | 厨房用品     |        500 |           NULL | 2009-09-20  |
11 | 0007       | 砧板         | 厨房用品     |        880 |            790 | 2008-04-28  |
12 | 0008       | 圆珠笔       | 办公用品     |        100 |           NULL | 2009-11-11  |
13 +------------+--------------+--------------+------------+----------------+-------------+
14 8 rows in set (0.00 sec)

 

 1.2 为列设置别名

 1 mysql> select 'product_type' as tpye , 39 as number ,sale_price from product;
 2 +--------------+--------+------------+
 3 | tpye         | number | sale_price |
 4 +--------------+--------+------------+
 5 | product_type |     39 |       1000 |
 6 | product_type |     39 |        500 |
 7 | product_type |     39 |       4000 |
 8 | product_type |     39 |       3000 |
 9 | product_type |     39 |       6800 |
10 | product_type |     39 |        500 |
11 | product_type |     39 |        880 |
12 | product_type |     39 |        100 |
13 +--------------+--------+------------+
14 8 rows in set (0.00 sec)
15 
16 mysql> select product_type as tpye , 39 as number ,sale_price from product;
17 +--------------+--------+------------+
18 | tpye         | number | sale_price |
19 +--------------+--------+------------+
20 | 衣服         |     39 |       1000 |
21 | 办公用品     |     39 |        500 |
22 | 衣服         |     39 |       4000 |
23 | 厨房用品     |     39 |       3000 |
24 | 厨房用品     |     39 |       6800 |
25 | 厨房用品     |     39 |        500 |
26 | 厨房用品     |     39 |        880 |
27 | 办公用品     |     39 |        100 |
28 +--------------+--------+------------+
29 8 rows in set (0.00 sec)

 

$flag 上一页 下一页