Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

An example method of concatenating mysql strings and setting null values

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

# string concatenation concat (s1Powers2); concatenate the strings in last_name and first_name in the table

Select concat (last_name,first_name) as name from employees

# will only modify last_name, not first_name

SELECT first_name,last_name AS f FROM employees

# separate the two columns with commas and name them out_put

SELECT CONCAT (`last_ name`,',', `phone_ number`) AS out_put FROM employees

# ifnull determines whether it is empty, displays 0 instead of null if it is empty, and displays the column name as a result

SELECT IFNULL (commission_pct,0) AS result FROM employees

Content extension:

Concatenation of strings

1.1 CONCAT (S1 and S2...) Function

Returns the string generated by the connection parameter, one or more contents to be concatenated. If any one is NULL, the return value is NULL.

SELECT CONCAT ('now time:', NOW ());-- output result: current time: 2019-01-17 11:27:58

1.2 CONCAT_WS (xmens 1pr s2pr..) Function

Returns a string after multiple strings are concatenated, with an x between each string.

SELECT CONCAT_WS (';', 'pan_junbiao blog', 'KevinPan','pan_junbiao');-- output result: pan_junbiao blog; KevinPan;pan_junbiao

I hope the above arrangement can help you, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report