MySQL之相关函数
1、char_length(str)
(1)计算单位:字符
(2)不管汉字还是数字或者是字母都算是一个字符
2、length(str)
(1)计算单位:字节
(2)utf8编码:一个汉字三个字节,一个数字或字母一个字节。
(3)gbk编码:一个汉字两个字节,一个数字或字母一个字节。
例题:

SQL:
select tweet_id from Tweets where char_length(content)>15;
四舍五入
round(number,digits)
number,要四舍五入的数,digits是要小数点后保留的位数
如果 digits 大于 0,则四舍五入到指定的小数位。
如果 digits 等于 0,则四舍五入到最接近的整数。
如果 digits 小于 0,则在小数点左侧进行四舍五入。
如果round函数只有参数number,等同于digits 等于 0。
行转列

SELECT product_id, 'store1' store, store1 price FROM products WHERE store1 IS NOT NULL
UNION
SELECT product_id, 'store2' store, store2 price FROM products WHERE store2 IS NOT NULL
UNION
SELECT product_id, 'store3' store, store3 price FROM products WHERE store3 IS NOT NULL;
列转行

SELECT
product_id,
SUM(IF(store = 'store1', price, NULL)) 'store1',
SUM(IF(store = 'store2', price, NULL)) 'store2',
SUM(IF(store = 'store3', price, NULL)) 'store3'
FROM
Products1
GROUP BY product_id ;

Year--Month--day(str)---获取字符串的年月日
浙公网安备 33010602011771号