TMD咯MySQL 2020-04-22
mysql> select gdcode,gdname,gdprice -> from goods -> where tid=1 -> order by gdprice; 结果 +--------+-----------+---------+ | gdcode | gdname | gdprice | +--------+-----------+---------+ | 001 | 迷彩帽 | 63 | | 008 | A字裙 | 128 | | 005 | 运动鞋 | 400 | +--------+-----------+---------+ 3 rows in set (0.02 sec)
mysql> select gdcode,gdname,gdsaleqty,gdprice -> from goods -> where tid=1 -> order by gdsaleqty desc,gdprice;
结果
+--------+-----------+-----------+---------+ | gdcode | gdname | gdsaleqty | gdprice | +--------+-----------+-----------+---------+ | 008 | A字裙 | 200 | 128 | | 005 | 运动鞋 | 200 | 400 | | 001 | 迷彩帽 | 29 | 63 | +--------+-----------+-----------+---------+ 3 rows in set (0.00 sec)
mysql> select gdcode,gdname,gdprice -> from goods -> limit 3; 结果 +--------+--------------+---------+ | gdcode | gdname | gdprice | +--------+--------------+---------+ | 001 | 迷彩帽 | 63 | | 003 | 牛肉干 | 94 | | 004 | 零食礼包 | 145 | +--------+--------------+---------+ 3 rows in set (0.00 sec)
mysql> select gdcode,gdname,gdprice from goods; +--------+---------------+---------+ | gdcode | gdname | gdprice | +--------+---------------+---------+ | 001 | 迷彩帽 | 63 | | 003 | 牛肉干 | 94 | | 004 | 零食礼包 | 145 | | 005 | 运动鞋 | 400 | | 006 | 咖啡壶 | 50 | | 008 | A字裙 | 128 | | 009 | LED小台灯 | 29 | | 010 | 华为P9_PLUS | 3980 | +--------+---------------+---------+ 8 rows in set (0.00 sec)
0
1
2
3
...
mysql> select gdcode,gdname,gdprice -> from goods -> limit 4,3; +--------+--------------+---------+ | gdcode | gdname | gdprice | +--------+--------------+---------+ | 006 | 咖啡壶 | 50 | | 008 | A字裙 | 128 | | 009 | LED小台灯 | 29 | +--------+--------------+---------+ 3 rows in set (0.00 sec)
mysql> select sum(gdsaleqty) from goods; +----------------+ | sum(gdsaleqty) | +----------------+ | 807 | +----------------+ 1 row in set (0.00 sec) mysql> select max(gdsaleqty) from goods; +----------------+ | max(gdsaleqty) | +----------------+ | 234 | +----------------+ 1 row in set (0.00 sec)
use onlinedb; SET FOREIGN_KEY_CHECKS=0; -- ---------------------------- -- Table structure for orders -- ---------------------------- DROP TABLE IF EXISTS `orders`; CREATE TABLE `orders` ( `oID` int(11) NOT NULL AUTO_INCREMENT, `uID` int(11) DEFAULT NULL, `oTime` datetime NOT NULL, `oTotal` float DEFAULT NULL, PRIMARY KEY (`oID`) ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8; -- ---------------------------- -- Records of orders -- ---------------------------- INSERT INTO `orders` VALUES (‘1‘, ‘1‘, ‘2017-12-04 08:45:07‘, ‘83‘); INSERT INTO `orders` VALUES (‘2‘, ‘3‘, ‘2017-12-04 08:45:07‘, ‘144‘); INSERT INTO `orders` VALUES (‘3‘, ‘9‘, ‘2017-12-04 08:45:07‘, ‘29‘); INSERT INTO `orders` VALUES (‘4‘, ‘8‘, ‘2017-12-04 08:45:07‘, ‘1049‘); INSERT INTO `orders` VALUES (‘5‘, ‘4‘, ‘2017-12-04 08:45:07‘, ‘557‘); INSERT INTO `orders` VALUES (‘6‘, ‘3‘, ‘2017-12-04 08:45:07‘, ‘1049‘);
mysql> select count(uID) from orders; +------------+ | count(uID) | +------------+ | 6 | +------------+ 1 row in set (0.00 sec)
mysql> select count(distinct uID) from orders; +---------------------+ | count(distinct uID) | +---------------------+ | 5 | +---------------------+ 1 row in set (0.00 sec)
mysql>select uID,uName,uSex,uCity from users group by uCity;
mysql> select uCity,count(*) from users -> group by uCity;
mysql> select uCity,GROUP_CONCAT(uID)as uIDs -> from users -> GROUP BY uCity;
mysql> select uCity,GROUP_CONCAT(uID ORDER BY uID SEPARATOR‘_‘)as ‘编号‘ -> from users -> GROUP BY uCity;
mysql> select uCity,count(*) from users -> where uCity in(‘长沙‘,‘上海‘) -> GROUP BY uCity -> WITH ROLLUP;
mysql> select uCity,count(*) from users -> GROUP BY uCity -> HAVING COUNT(*)>=3;