Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 将列和行连接在一起_Sql_Sql Server Express - Fatal编程技术网

Sql 将列和行连接在一起

Sql 将列和行连接在一起,sql,sql-server-express,Sql,Sql Server Express,我有一张桌子,上面有飞机和客户的选择 乙二醇 我用 SELECT Cust, opt1 + opt2 as options FROM myDB where Len(opt1) >1 or Len(opt2) >1 当然,在我的成绩表中,我两次得了cust A Cust | options | ------------------------ A | abcdef | A | ghi | B | m

我有一张桌子,上面有飞机和客户的选择

乙二醇

我用

SELECT
Cust,
opt1 + opt2 as options         
FROM myDB where Len(opt1) >1 or Len(opt2) >1 
当然,在我的成绩表中,我两次得了cust A

Cust  |  options  |
------------------------
A     |   abcdef  |    
A     |      ghi  |
B     |      mno  |
F     |      pqr  |
如何进一步压缩此查询,使结果变为:

 Cust |  options    |
------------------------
A     |   abcdefghi  |    
B     |      mno     |
F     |      pqr     |

谢谢!(使用SQL server Express)

如果您认为这应该更简单,我同意您的看法!请对这两个连接项进行投票和评论:谢谢,你有我可以在谷歌上搜索的主题标题吗?我想我理解你的要求。“组连接”或“分组连接”可能是您要搜索的内容?
 Cust |  options    |
------------------------
A     |   abcdefghi  |    
B     |      mno     |
F     |      pqr     |
SELECT DISTINCT c.Cust, options = ((SELECT c2.opt1 + c2.opt2 
  FROM dbo.myDB AS c2 WHERE c2.Cust = c.Cust 
  FOR XML PATH(''), TYPE).value('.[1]', 'nvarchar(max)'))
FROM dbo.myDB AS c;