Mysql- multi-table query data record

Multi-table query data records

A relationship between the operation data

  • And (UNION)

And consolidating table is to have the same number of fields and field types together

  • Cartesian product (CARTESIAN PRODUCT)

Cartesian product is the result of the condition does not return to the table relation connection.

  • The connector (INNER JOIN)

The so-called inner join in the table is the relationship between the Cartesian product data records in the table, reserved table relationships, all matching data record, discarding data record does not match.

  • External link (OUTER JOIN)

The so-called external connection: that is the Cartesian product data recording table relations, not only in relation to retain data recording table matched, but also the remaining portion of the data record does not match. In accordance with reservations do not match the data source can be divided recording left outer, right outer join, full outer join.

Left outer join

The so-called left outer connection: the Cartesian product is a relationship between an addition to selecting the data records match, further comprising association data record does not match the table on the left,

Right outer join

Right outer join operation is the Cartesian product of a relationship between an addition to selecting the data records match, further comprising association data record does not match the right table.

Full outer join

Full outer join operation is the Cartesian product table relationships, in addition to selecting a data record match, further comprising a data record associated with the role of the two lists do not match.

Second, inline query

SELECT field1 field2 field3
    FROM join_tablename1 INNER JOIN join_table_name2 [INNER JOIN join_tablename]
    ON join_condition

Third, the external link inquiry

SELECT field1 field2 field3 
    FROM join_tablename1 LEFT|RIGHT|FULL [OUTER] JOIN join_tablename2
    ON join_condition

The use of commonly used functions MySql

String Functions: The main functions for processing the string class

Numerical functions: such function is mainly for processing digital

Date Functions: These functions are mainly used with dates and events

System Information Functions: These functions used to acquire MySQL software system information

  • The combined string function CONCAT () and CONCAT_WS ()
#合并字符串函数一
CONCAT(S1,S2,S3)
select ('my','sq','l')
mysql
#合并字符串函数二
CONCAT_WS(SEP,S1,S2,...SN)
SELECT CONCAT_WS('-','029','88461234')
029-88461234
  • Comparative STRCMP string size function ()

In the MySQL software can STRCMP (comparing the incoming string object).

#比较字符串大小
STRCMP(str1,str2)
如果参数str1大于Str2,则返回结果1,如果参数str1小于str2,则返回结果-1,如果str1等于str2则返回结果0
  • Get the LENGTH function () function and the CHAR_LENGTH String () String length
#获取传入参数str的长度
LENGTH(str)
#获取传入的参数str的字符数
CHAR_LENGTH(str)
  • Implement the letter case conversion functions UPPER () and character illusion LOWER ()

In MySQL function can be implemented all the letters uppercase character string converted by the UPPER () and UCASE ().

#转换为大写
UPPER(S)
#转换为大写
UCASE(S)

Implemented to convert all lowercase letters in a string by the LOWER () and LCASE () function.

#转换为小写字母
LCASE(S)
#转换为小写字母
LOWER(S)
  • Find string
#返回字符串位置的FIND_IN_SET()函数
FIND_IN_SET(str1,str2)
上述函数,将会返回在字符串str2中与str1相匹配的字符串的位置,参数str2中将包含若干个用逗号隔开的字符串。

#返回指定字符串位置的FIELD()函数
FIELD(str,str1,str2....)
上述函数将会返回第一个与字符串str匹配的字符串的位置

#返回指定位置的字符串的ELT()函数
ELT(n,str1,str2)
上述函数将会返回第n个字符串
  • Taken from the prior string substring
#从左边或右边截取字符串
LEFT(str,num)
RIGHT(str,num)

#截取指定位置和长度的字符串
SUBSTRING(str,num,len)
MID(str,num,len)
  • The removal of the first string of spaces
#去除字符串开始处空格
LTRIM(str)
#去除字符串结束处空格
RTRIM(str)
#去除字符串首尾的空格
TRIM(str)
  • Replacement string
#使用INSERT函数
INSERT(str,pos,len,newstr)
上述函数会将字符串str中的pos位置开始长度为len的字符串newstr来替换,如果参数pos的值超过字符串的长度,则返回值为原始字符串str。如果len的长度大于原来字符串中所剩的长度,则从位置POS开始进行全部替换,若任何一个参数NULL,则返回至为NULL

#使用REPLACE()函数
REPLACE(str,substr,newstr)
上述函数会将字符串,str中的字符串substr用字符串newstr来替换。

Fifth, the use of numerical functions

  • Gets a random number
#通过RAND()和RAND(X)函数来获取随机数
SELECT RAND(),RAND(),RAND(3),RAND(3)
  • Get integer function
CEIL(X)
上述函数返回大于或等于数值X的最小整数

FLOOR(X)
上述函数返回小于或等于数值X的最大整数
  • Numerical interception function
RRUNCAT(X,Y)
上述函数返回值X保留到小数点后y位的值
  • Rounding function
ROUND(x)

Reproduced in: https: //www.cnblogs.com/XtsLife/p/11057486.html

Guess you like

Origin blog.csdn.net/weixin_34127717/article/details/93761153