Using COALESCE in SQL view(在 SQL 视图中使用 COALESCE)
问题描述
我需要从多个表创建一个视图.视图中的一列必须由表中的多行组成,作为带有逗号分隔值的字符串.
I need to create a view from several tables. One of the columns in the view will have to be composed out of a number of rows from one of the table as a string with comma-separated values.
这是我想做的事情的一个简化示例.
Here is a simplified example of what I want to do.
客户和订单之间存在一对多关系.所以给定这个数据
There is a one-to-many relationship between Customer and Orders. So given this data
我想要这样的视图:
这样每个人都会出现在表格中,无论他们是否有订单.
So that EVERYBODY shows up in the table, regardless of whether they have orders or not.
我有一个需要转换为该视图的存储过程,但您似乎无法在视图中声明参数和调用存储过程.关于如何将此查询放入视图中的任何建议?
I have a stored procedure that i need to translate to this view, but it seems that you cant declare params and call stored procs within a view. Any suggestions on how to get this query into a view?
推荐答案
EDIT:修改答案以包含视图的创建.
EDIT: Modified answer to include creation of view.
这篇关于在 SQL 视图中使用 COALESCE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!