Mysql base notes three - rookie tutorial

Excerpt from rookie tutorial, part of the knowledge point record according to my own situation. In order to consolidate a knowledge learned, and secondly for future review.

Where clause

To conditionally select data from the table, can be added to the WHERE clause of a SELECT statement.
where passenger for select, delete, update command.
BINARY keyword may be used to set the where clause string is case-sensitive.

LIKE clause

Like clause any character identification unsolicited% sign, percent sign% if not used, and the = Like clauses same effect.

Statement:
SELECT Field 1, Field 2, ..., n from the field table where field m Like condition;

  • '% A': a data ending
  • 'A%': beginning a data
  • '% A%': contains a data
  • ' A ': is a three-bit and intermediate data
  • '_A': two and ending with a data
  • 'A_': two data and starts with a

Represents any of 0% or more characters, the character can match any type and length
_ represents any single character
[] represents a character listed in the brackets
[^] represents a single character is no longer in a plurality of rows of brackets
Note : when the query contains wildcards (more symbols), the special characters "[]" can be enclosed in

UNION operator

The results for the select statement is connected to two or more combinations of a set of results. Multiple select statement removes duplicate data.

grammar:

select a,b,c from tb1 [where condition] UNION [ALL/DISTINCT]  select a,b,c from tb2 [where condiction]

all: return all result sets that contain duplicate data
distinct: the result set delete duplicate data
tips: UNION default out duplicate data.

Sort Mysql

Sort order by using the
syntax:

select 字段1,字段2,...,字段n from table 
order by 字段m [ASC/DESC] ,字段p [ASC/DESC],...

ASC ascending order, DESC descending, descending default.

tips:
alphabetical order:

  1. If the character set gbk, directly order by ordering
  2. If the character set utf-8, the first character transcoding reorder
    select * from table order by convert (field n using gbk)

Group by statement

They are grouped according to one or more queue result sets.
Using COUNT, SUM, AVG, etc. functions on the packet column.
grammar:

SELECT column_name, function(column_name)
FROM table_name
WHERE column_name operator value
GROUP BY column_name;

WITH ROLLUP can be achieved then the same statistics (SUM, AVG, COUNT ...) on the basis of statistical data in the packet.

Tips:
the Where, Group by, the HAVING difference:

  1. where: Inst for screening query results and work before returning
  2. Group by: to select query result set out in accordance with a field or expression group
  3. For and where to check out the packet group by filtration, the isolated grouping result satisfaction condition, the query results filtering operation after the return result sets.
    Execution order:
    select-> where-> by-Group> having-> Order by

where 和 having:
①select s#,sage from Student where sage>15;
②select s#,sage fron Student having sage>15;
③select s# from Student having sage>15;

  1. where screening directly from the data field in a table
  2. re having screened out from the screening field, it will be given first sentence ③
  3. ①② statement, where and sage equivalent
Released four original articles · won praise 0 · Views 24

Guess you like

Origin blog.csdn.net/qq_41614773/article/details/105265074