Some use mysql summary

1. The value of the field all together into a string: group_concat

Usage: group_concat ([DISTINCT] fields to be connected [Order BY ASC / DESC sort field] [Separator 'delimiter'])

2. The transfer date time stamp: from_unixtime

用法:FROM_UNIXTIME(unix_timestamp,format),

Wherein fomat formats such as: '% Y-% m-% d% H:% i:% S'

3. The transfer date time stamp: date_format

用法:DATE_FORMAT(date, format)

4.if

Usage: IF (condition, v1, v2),

Wherein when return v1 condition is true, whether the return v2

5.case...when

Usage: case field When the comparison value 1 then returns the value 1 when the comparison value 2 then returns the value 2 else return value 3 end,

Wherein the value field comparison value = 1, for the return value of 1, if the comparison value does not equal the comparison value 1 or 2, for the return value 3

6. User variables @

Usage: @tmp: = fields or values

Personal summary:

1. If you want to get all the value of a field, and the amount of data and do not want to use cycle, we can use to help us deal with group_concat function.

2. We usually use the time function to format the date or time stamp by day / month / week / year statistics and other data packet, if the time field where conditions, and already know the scope of time, then we try not to use function mysql, because if the data is too large, may query speed will slow down.

3. Sometimes we use case ... when ... then ... else ... end and will group by the same time.

4. Use @ user variable and sometimes simultaneously or if we can sort the data (data volume is not small impact on query speed).

Reference https://www.cnblogs.com/wenxinphp/p/5841430.html

       https://www.cnblogs.com/haorenergou/p/7927591.html

       https://www.cnblogs.com/yangchunze/p/6669523.html

       https://www.cnblogs.com/raobenjun/p/7998467.html

       https://blog.csdn.net/u011649691/article/details/79059990

Guess you like

Origin blog.csdn.net/janthinasnail/article/details/90713995