zoukankan      html  css  js  c++  java
  • mysql数据库笔记

    /*登录数据库*/
    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                                                                                

  • 相关阅读:
    3.6
    2.26
    2.22
    出差记录(每日食谱)
    关于本博客的样式
    知乎搜索/(引擎)的故事
    【历史/对越自卫反击战】刘立华||我的战地笔记——陵园祭
    如何在Xpath路径中添加变量?如何将字符串传递给Xpath?
    阿里网盘搜索网站汇总
    经济学人下载
  • 原文地址:https://www.cnblogs.com/woxinfeixiang2015/p/5494645.html
Copyright © 2011-2022 走看看