sql多行合并成一行(sql多行合并成一行的函数)
本篇文章给大家谈谈sql多行合并成一行,以及sql多行合并成一行的函数对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
SQL 多行数据合并成一行
group by 前面相同的字段,后面不同的,用max取。
SELECT m.member_id,
prefix_desc 'Prefix:',
UPPER(first_name) 'First Name:',
UPPER(last_name) 'Last Name:',
UPPER(email) 'Email:',
LOWER(user_id) 'User ID:',
REPLICATE('*',LEN(password)) 'Password:',
('****'+SUBSTRING(license_no,5,4)) 'Drivers Licese Number:',
REPLACE(email_ind,'Y','Accept') 'Email notification:',
REPLACE(return_ind,'Y','Accept') 'HERIZ E-RETURN',
max(CASE WHEN tel_type= 'B' THEN tel_number END + ' '+REPLACE(pref_phone_ind,'P','PREF')) 'Business Phone',
max('('+ p.country_code + ')'喊顷+ CASE WHEN tel_type= 'M' THEN tel_number END) 'Mobile Number',
max(CASE WHEN tel_type= 'F' THEN tel_number END) '闷凳Fax'
FROM MEMBER m, license l, phone_fax p
WHERE m.member_id = l.member_id
AND m.member_id = p.member_id
AND m.member_id = 'A000001'
group by
m.member_id,
prefix_desc 'Prefix:',
UPPER(first_name) 'First Name:',
UPPER(last_name) 'Last Name:'蚂渗旅,
UPPER(email) 'Email:',
LOWER(user_id) 'User ID:',
REPLICATE('*',LEN(password)) 'Password:',
('****'+SUBSTRING(license_no,5,4)) 'Drivers Licese Number:',
REPLACE(email_ind,'Y','Accept') 'Email notification:',
REPLACE(return_ind,'Y','Accept') 'HERIZ E-RETURN'
sql server怎么把多行数据合并成一行
group by 前面相同的字段,后面不同的,用max取。
SELECT m.member_id,
prefix_desc 'Prefix:',
UPPER(first_name) 'First Name:',
UPPER(last_name) 'Last Name:',
UPPER(email) 'Email:',
LOWER(user_id) 'User ID:',
REPLICATE('*',LEN(password)) 'Password:',
('****'+SUBSTRING(license_no,5,4)) 'Drivers Licese Number:',
REPLACE(email_ind,'Y','Accept') 'Email notification:',
REPLACE(return_ind,'Y','Accept') 'HERIZ E-RETURN',
max(CASE WHEN tel_type= 'B' THEN tel_number END + ' '+REPLACE(pref_phone_ind,'P','PREF')) 'Business Phone',
max('('+ p.country_code + ')'喊顷+ CASE WHEN tel_type= 'M' THEN tel_number END) 'Mobile Number',
max(CASE WHEN tel_type= 'F' THEN tel_number END) '闷凳Fax'
FROM MEMBER m, license l, phone_fax p
WHERE m.member_id = l.member_id
AND m.member_id = p.member_id
AND m.member_id = 'A000001'
group by
m.member_id,
prefix_desc 'Prefix:',
UPPER(first_name) 'First Name:',
UPPER(last_name) 'Last Name:'蚂渗旅,
UPPER(email) 'Email:',
LOWER(user_id) 'User ID:',
REPLICATE('*',LEN(password)) 'Password:',
('****'+SUBSTRING(license_no,5,4)) 'Drivers Licese Number:',
REPLACE(email_ind,'Y','Accept') 'Email notification:',
REPLACE(return_ind,'Y','Accept') 'HERIZ E-RETURN'
SQL 多行多列数据清洗合并为一行
SELECT
A,
GROUP_CONCAT( B SEPARATOR ',' ),
GROUP_CONCAT( C SEPARATOR ',' )
FROM
table_name
GROUP BY
A
1.GROUP_CONCAT()中的值为你要合并的数据的字段名;
2.SEPARATOR 函数是用来分隔这些要合并的数据的 ,' ' 中是你要用链胡哪个带哗符号来分隔,可以直接不填符号默认为空值;
2.必须要用GROUP BY 语句来进行分组管理,不然所有棚行拦的数据都会被合并成一条记录
参考链接
[img]关于sql多行合并成一行和sql多行合并成一行的函数的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。