/*登錄數據庫*/
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;
參考:MySQL5.1參考手冊官方簡體中文版
http://www.w3school.com.cn/sql/sql_functions.asp