LEFT & RIGHT (for column)
# choose the col string you want to separate
SELECT LEFT(col, number) AS new_col # col=> string column, number=> separate index position
FROM TABLE;
SELECT RIGHT(col, number) AS new_col
FROM TABLE;
# Sample:
# if we want to count the `name` start with 'a' character
SELECT SUM(new_name) AS n_name
FROM (SELECT name, CASE WHEN LEFT(name, 1)='a'
THEN 1 ELSE 0 END AS new_name
FROM TABLE) AS t1;
POSITION, STRPOS & SUBSTR
# POSITION, STRPOS: provides the position of a string counting from the left
# ATTENTION: both them are case sensitive
POSITION('target_string' IN col)
STRPOS(col, 'target_string')
# If you want separate the string, use LEFT or RIGHT and POSITION or STRPOS
...
LEFT(col, POSITION('target_string' IN col) -1 ) AS new_col # -1 is to substracting the target_string
...
LOWER, UPPER
# force every character in a string to become lowercase(uppercase)
LOWER(col)
UPPER(col)
CONCAT & ||
# CONCAT & ||: combines values from several columns into one column
...
CONCAT(a, 'space mark(or nothing)', b) AS new_col
a || 'space mark(or nothing)' || b AS new_col
...
CAST
# Allows us to change columns from one data type to another
# change float to int:
CAST(25.6 AS int) => 25
# change string to date:
CAST(year || '-' || month || '-' || day AS date) => 2018-08-21
COALESCE
# Returns the first non-null value passed for each row
COALESCE(col, 'Nothing here') AS show_non-null_col => if col is null, then will show 'Nothing here'
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。