MySQL 05 Chapter _ fuzzy queries and aggregate functions

In the previous query needs to be "accurate" to shut down the query, "complete" the full input in order to check the appropriate result,
But in the actual development process will usually require the user may not know the "exact", "complete" keyword,
Then you need to provide a less stringent forms of inquiry, namely fuzzy query, just type part can be done about the inquiry.

First, fuzzy query
    1 , using the keyword LIKE
        Syntax: the SELECT  < field list | *>  the FROM table [ the WHERE field names LIKE% keyword% ] ;
        Description: Wildcard _ (0-1 represents any character), % (0 represents any of a plurality of characters)
        举例:SELECT * FROM tb_student 
              WHERE student_name LIKE '%娘%' OR phone LIKE '%娘%' OR address LIKE '%娘%' OR email LIKE '%娘%';
    2、使用BETWEEN  END关键字
        Syntax: the SELECT  < field list | *>  the FROM table [ the WHERE field name AND BETWEEN start value end value ] ;
        Description: "start value" and "end value" are included
        举例:SELECT * FROM tb_score WHERE student_score >=80 AND student_score <= 90;
              SELECT * FROM tb_score WHERE student_score BETWEEN 80 AND 90;

    3 , using the IN keyword
         Syntax: the SELECT  < Field List | *>  the FROM table [ the WHERE <field name IN (a list of possible values)> ] ;
         Note: If the query contains the keyword IN at the back of the "possible values ​​list", considered to be legitimate
         Example: - Query "java" and "HTML" Course information 
              the SELECT  *  the FROM tb_subject the WHERE SUBJECT_NAME = "java" OR SUBJECT_NAME = "HTML";
               the SELECT  *  the FROM tb_subject the WHERE SUBJECT_NAME the IN ( "java", "HTML");
     . 4 , using regular expressions (REGEXP) clause
       Syntax ,: 1 the SELECT  < field list | *>  the FROM table [ the WHERE <field name REGEXP regular expression rules> ] ;
       Syntax ,: 2 the SELECT  < matched value > REGEXP, < regular expression rules > ;
       Explanation: The value is matched regular expression rules if the meet, which matches the success of the display 1, 0 otherwise
       举例:SELECT * FROM tb_student WHERE email REGEXP '^([a-zA-Z0-9]+)*@([a-zA-Z0-9]+)\.([a-zA-Z]{2,5})$';
             -- ^[\u2E80-\u9FFF]+$
             SELECT * FROM tb_student WHERE not student_name REGEXP "^([u0391-uFFE5]{2,4})$";
Second, aggregate functions
      . 1 , COUNT (): number of statistics records satisfying the condition
       2 , the SUM (): summation
       . 3 , the AVG (): calculating an average value
       . 4 , MAX (): selecting the maximum value
       . 5 , MIN (): for the minimum
      
      The SELECT  *  the FROM tb_score LIMIT 10 , 5 ;
       - for tb_score table, each page displays up to five records, please check the second page of 
      the SELECT  *  the FROM tb_score LIMIT 5 , 5 ;
       the SELECT  SUM (student_score) the FROM tb_score;
       the SELECT  AVG (student_score) the FROM tb_score;
       the SELECT  MAX (student_score) the FROM tb_score;
       the SELECT  MIN (student_score) the FROM tb_score;
      
      pageCount = (rowCount%pageSize == 0) ? rwoCount / pageSize : rowCount / pageSize + 1;
      
      
Three, mysql commonly used functions:
    1 , the character-related functions:
         the SELECT CONCAT (student_no, ' ---- ' , student_name) the FROM tb_student;
         the SELECT address, the LENGTH (address) the length of the FROM tb_student;
         the SELECT  the UPPER ( "afaag");
         the SELECT  the LOWER ( "asdKKJF" );
     2 , values related functions:
         - the ROUND (X-, D) rounding 
        the SELECT  the ROUND ( 85.65622 , 2 );
         - the ROUND (X-) rounded, d is 0 
        the SELECT  the ROUND ( 85.65622 );
         -`TRUNCATE` (X, D) function truncates 
        the SELECT  TRUNCATE ( 85.65622 , 2 );
         - ` MOD` (N, M) modulo 
        the SELECT the MOD ( 10 , . 3 );
     . 3 , the date-related functions:
        Date function calculates the time difference
        TIMESTAMPDIFF(unit,datetime_expr1,datetime_expr2);
        Description:
        unit: Pointing to calculate what type of difference
        datetime_expr1: subtrahend
        datetime_expr2: minuend
      

 

Guess you like

Origin www.cnblogs.com/zhangzimuzjq/p/11669716.html