将两张表和一张链接表变成一张大表
我尝试寻找这个问题,但没有发现任何相关内容。所以这里...
我有三个表,其极其简化的版本是:
Practitioners:
practitioner_id :: int
name :: nvarchar
保险:
insurance_id :: int
name :: nvarchar
InsuranceLink:
practitioner_id :: int
>insurance_id :: int
因此,从业者表包含从业者列表,保险表包含保险列表,链接表代表哪个从业者支持哪种保险。
现在,我需要创建一个可以显示如下信息的视图:
ViewTable:
practitioner_id :: int
practitioner_name :: nvarchar
Insurance_1 :: 位
insurance_2 :: 位
.....insurance_100 :: bit
换句话说,视图中的列是从业者的 ID 和姓名,以及 Insurances 中存在的每项保险(带有保险名称作为列名称(强制条件是保险名称是唯一的))。保险栏中的单元格将指示该从业者是否支持该保险。
有什么办法可以做到这一点吗?
或者更好的是,是否可以在 VB.NET 形式的数据集上使用 Excel 样式的数据透视表?这也能解决我的很多问题。
I tried looking for this question, but found nothing relevant. So here goes...
I have three tables, the extremely simplified versions of which are:
Practitioners:
practitioner_id :: int
name :: nvarchar
Insurances:
insurance_id :: int
name :: nvarchar
InsuranceLink:
practitioner_id :: int
insurance_id :: int
So, the practitioner table contains a list of practitioners, the insurance table contains a list of insurances, and the link table represents which practitioner supports which insurance.
Now, I need to create a view which can display the information like this:
ViewTable:
practitioner_id :: int
practitioner_name :: nvarchar
insurance_1 :: bit
insurance_2 :: bit
.....insurance_100 :: bit
In other words, the columns in the view are the ID and name of the practitioner, and every insurance that exists in Insurances (with the insurance name as the column name (there is an enforced condition that insurance names are unique)). The cells in the insurance columns will indicate if that practitioner supports that insurance.
Is there any way of doing this?
Or better yet, is it possible to use an excel-style pivot table on a DataSet in a VB.NET form? That would also solve many of my problems.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
PIVOT 是您正在寻找的关键字。
我知道现在您想知道是否有任何方法可以避免列出所有保险名称/使其不是一个固定列表。答案是否定的,几乎没有。您可以以编程方式创建视图,但添加保险时仍需要更新视图。
PIVOT is the keyword you're looking for.
I know that now you're wondering if there's any way to avoid listing out all the insurance names/having it not be a constant list. The answer is no, pretty much. You can create the view programatically but the view is still going to need to be updated when an insurance is added.