我的情况如下:
表用户
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
BackgroundWorker1.RunWorkerAsync()
End Sub
Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
MsgBox("test")
End Sub
Private Sub BackgroundWorker1_RunWorkerCompleted(sender As Object, e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
BackgroundWorker1.RunWorkerAsync()
End Sub
表格属性
ID User viewname Description
1 JamesId employeeview This is a employee
2 FredId employeeview This is a employee
3 NickId managerview This is a manager
我需要创建如下视图:
EmployeeView
ID key value user_ref
1 name james 1
2 phone 88888888888 1
3 email test@test.com 3
4 name fred 2
5 phone 555555555555 2
ManagerView
Id empId name phone Description
1 JamesId james 88888888888 This is a employee
2 FredId fred 555555555555 This is a employee
属性表是User表的扩展,其中所有内容都存储为键值对。需要使用上面的两个表动态创建视图。属性表是动态的。
是否可以生成此类视图。有人可以举个例子吗。
答案 0 :(得分:0)
我设法在postgres中使用交叉表功能。但是我必须修改属性表以容纳另一个colume作为标识。
修改后的属性表:
ID key value user_ref identifier
1 name james 1 viewemployee
2 phone 88888888888 1 viewemployee
3 email test@test.com 3 viewmanager
4 name fred 2 viewemployee
5 phone 555555555555 2 viewemployee
使用交叉表进行 employeeview 的SQL查询:
create MATERIALIZED VIEW EmployeeView as
select one.id, one.userid, two.name, two.phone, one.description from
user_table one,
(SELECT *
FROM crosstab(
'SELECT user_ref,key,value FROM user_properties where identifier=''viewemployee'' order by 1,2')
AS
ct_row (user_ref int, name varchar, phone varchar)) two
where
one.id=two.user_ref
使用交叉表进行 managerview 的SQL查询:
create MATERIALIZED VIEW ManagerView as
select one.id, one.userid, two.email, one.description from
user_table one,
(SELECT *
FROM crosstab(
'SELECT user_ref,key,value FROM user_properties where identifier=''viewmanager'' order by 1,2')
AS
ct_row (user_ref int, email varchar)) two
where
one.id=two.user_ref