/*登录数据库*/
mysql -u root -p
select curdate() as 日期; /*两个日期相加*/ select date_add(curdate(),interval 1 month); /*取月份,同理可取年、日*/ select month('2010-10-30'); /*取模运算*/ select mod(100,9);
/*去字符串右边的n个字符*/
select right('stinging',5);
1.模式匹配:
标准的sql模式匹配:
操作符:like 、not like
匹配符:_ 单个字符 、% 0或多个字符
扩展的sql模式匹配:
操作符:regexp 、 not regexp
count() 与 group by
select * , count(*) from tableName [where] order by columnName [, columnName]
select * , count(*) from SC order by Sno;
2.函数 SELECT function(列) [as someName]FROM 表
SELECT MAX(article) AS article FROM shop; SELECT MIN(article) AS article FROM shop; SELECT AVG(article) AS article FROM shop; SELECT SUM(article) AS article FROM shop; SELECT COUNT([DISTINCT ]article) AS article FROM shop; SELECT COUNT(*) AS article FROM shop;
3.限制LIMIT子句
SELECT article, dealer, price FROM shop ORDER BY price DESC LIMIT 1;
4.用户变量
SELECT @min_price:=MIN(price),@max_price:=MAX(price) FROM shop; SELECT * FROM shop WHERE price=@min_price OR price=@max_price;
5.主要聚集函数
count( [distinct|all] *) count( [distinct|all] <列名>) sum( [distinct|all] <列名>) avg( [distinct|all] <列名>) max ( [distinct|all] <列名>) min ( [distinct|all] <列名>)
参考:MySQL5.1参考手册官方简体中文版
http://www.w3school.com.cn/sql/sql_functions.asp