本文介绍了我在编写查询时遇到问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我有桌子 srno uni_name director contyname uni_id org_id mou_sing pro_mous numberofstudent 101 IIT sanjay Norway 91 04是否5 101 IIT sanjay Finland 91 04否是3 现在我想要一个产生这个结果的查询 srno uni_name director挪威芬兰numberofstudent 101 IIT sanjay值mou_sign(是)值mou_sign(是)5,3 我的查询没有转动: - SELECT ROW_NUMBER() over ( order by reg_no) as srno,(svi.reg_no) as reg_no ,(university_info.university_name) as university_name,(svi.directors) as vc_dir_name,(svi.university_id) as uni_id,(svi.organization_id) as org_id,(country_info.country_name) as country_name,(svi.country_code) as conty_code,( case svi.mous_signed = ' 0' 然后 ' 是' 其他 ' No' end ) as mou_singed,(svi.number_student) as number_student,( case svi.prop_mous = ' 0' 然后 ' 是' else ' No' end ) as prop_mous,( case svi.if_prop_mous = ' 0' 然后 ' 是' 其他 ' No' end ) as if_prop_mous, (svi.number_mous) as number_mous,(organization.organization_type) as organization_type FROM state_visit_info svi INNER JOIN country_info ON svi.country_code = country_info.country_code INNER JOIN university_info ON svi.university_id = university_info.university_id INNER JOIN organization ON svi.organization_id = organization.organization_id 其中 svi.organization_id = ' 04' [edit]已添加代码块 - OriginalGriff [/ edit] 解决方案 你好Sanjay, 请看以下链接: 将行数据转换为SQL Server中的列 [ ^ ] 你在使用什么数据库? 如果是oracle,你可以使用 ListAgg [ ^ ],如果你正在使用SQL Server,你可以看看这个 [ ^ ] tip。 i have tablesrno uni_name director contyname uni_id org_id mou_sing pro_mous numberofstudent101 IIT sanjay Norway 91 04 yes No 5101 IIT sanjay Finland 91 04 No Yes 3now i want a query which produce this resultsrno uni_name director Norway Finland numberofstudent101 IIT sanjay value of mou_sign(yes) value of mou_sign(yes) 5 , 3and my query is without pivoting :-SELECT ROW_NUMBER() over(order by reg_no)as srno,(svi.reg_no)as reg_no,(university_info.university_name) as university_name,(svi.directors) as vc_dir_name,(svi.university_id) as uni_id, (svi.organization_id) as org_id, (country_info.country_name) as country_name,(svi.country_code) as conty_code,(case when svi.mous_signed = '0' then 'Yes' else 'No' end) as mou_singed,(svi.number_student) as number_student,(case when svi.prop_mous = '0' then 'Yes' else 'No' end) as prop_mous,(case when svi.if_prop_mous = '0' then 'Yes' else 'No' end) as if_prop_mous,(svi.number_mous) as number_mous ,(organization.organization_type) as organization_typeFROM state_visit_info svi INNER JOINcountry_info ON svi.country_code = country_info.country_code INNER JOINuniversity_info ON svi.university_id = university_info.university_id INNER JOINorganization ON svi.organization_id = organization.organization_idwhere svi.organization_id='04'[edit]Code block added - OriginalGriff[/edit] 解决方案 Hello Sanjay,Please see the following link:Convert row data to column in SQL Server[^]What database are you using?If it's oracle you can use ListAgg[^], if you're using SQL Server you can take a look at this[^] tip. 这篇关于我在编写查询时遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!