forked from wangqiccc/WUIF1707-2-11-27
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sql.html
111 lines (102 loc) · 3.54 KB
/
sql.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
</body>
<script>
// mysql> create table shopping(
// -> id int(11) not null auto_increment primary key,
// -> name varchar(100) not null,
// -> price int(11) not null,
// -> cid int(11) not null,
// -> num int(11) not null)
// -> engine=innodb default charset=utf8;
// Query OK, 0 rows affected (0.04 sec)
//
//
// mysql> create table type(
// -> id int(11) not null auto_increment primary key,
// -> type varchar(100) not null,
// -> sort int(11) not null)
// -> engine=innodb default charset=utf8;
// Query OK, 0 rows affected (0.04 sec)
// 一.平均价
// mysql> create table dingdan(
// -> id int(11) not null auto_increment primary key,
// -> sid int(11) not null,
// -> count int(11) not null)
// -> engine=innodb default charset=utf8;
// Query OK, 0 rows affected (0.04 sec)
//
// mysql> select * from shopping
// -> ;
// +----+-----------+-------+-----+-----+
// | id | name | price | cid | num |
// +----+-----------+-------+-----+-----+
// | 1 | iphone8 | 5600 | 1 | 10 |
// | 2 | 小米MIX2 | 3200 | 1 | 150 |
// | 3 | OPPO R11S | 3200 | 1 | 100 |
// | 4 | OPPO R11S | 3200 | 1 | 100 |
// | 5 | OPPO R11S | 3200 | 1 | 100 |
// | 6 | 联想电脑 | 4800 | 21 | 30 |
// | 7 | 戴尔电脑 | 3200 | 21 | 48 |
// | 8 | 苹果电脑 | 8200 | 21 | 15 |
// +----+-----------+-------+-----+-----+
// mysql> select avg(price) as "平均价" from shopping;
// +-----------+
// | 平均价 |
// +-----------+
// | 4325.0000 |
// +-----------+
//mysql> select avg(price) as "电脑平均价" from shopping where cid=21;
//+------------+
//| 电脑平均价 |
//+------------+
//| 5400.0000 |
//+------------+
// 1 row in set (0.01 sec)
//三、查询某个商品的存货价值
//mysql> select price*num as value from shopping where name="iphone8";
//+-------+
//| value |
//+-------+
//| 56000 |
//+-------+
//某个订单的总金额
//mysql> select price*count as "订单金额" from shopping,dingdan where shopping.id=dingdan.id;
//+----------+
//| 订单金额 |
//+----------+
//| 9600 |
//+----------+
//查询价格最低的三个商品
//mysql> select * from shopping order by price limit 0,3;
//+----+-----------+-------+-----+-----+
//| id | name | price | cid | num |
//+----+-----------+-------+-----+-----+
//| 2 | 小米MIX2 | 3200 | 1 | 150 |
//| 3 | OPPO R11S | 3200 | 1 | 100 |
//| 4 | OPPO R11S | 3200 | 1 | 100 |
//+----+-----------+-------+-----+-----+
//查询最新添加的一个商品
//mysql> select * from shopping order by id desc limit 0,1;
//+----+----------+-------+-----+-----+
//| id | name | price | cid | num |
//+----+----------+-------+-----+-----+
//| 8 | 苹果电脑 | 8200 | 21 | 15 |
//+----+----------+-------+-----+-----+
//mysql> select * from shopping,type where shopping.cid=type.id;
//+----+-----------+-------+-----+-----+----+------+------+
//| id | name | price | cid | num | id | type | sort |
//+----+-----------+-------+-----+-----+----+------+------+
//| 1 | iphone8 | 5600 | 1 | 10 | 1 | 手机 | 1 |
//| 2 | 小米MIX2 | 3200 | 1 | 150 | 1 | 手机 | 1 |
//| 3 | OPPO R11S | 3200 | 1 | 100 | 1 | 手机 | 1 |
//| 4 | OPPO R11S | 3200 | 1 | 100 | 1 | 手机 | 1 |
//| 5 | OPPO R11S | 3200 | 1 | 100 | 1 | 手机 | 1 |
//+----+-----------+-------+-----+-----+----+------+------+
</script>
</html>