【发布时间】:2011-04-03 19:53:30
【问题描述】:
我必须编写一个语句,用综合生成的值填充表 (customers)。还有一个额外的约束,我应该只用特殊属性填充那些属性(列)(即正式对它们进行投影,然后专门对它们进行操作)。这些属性存储在第二个表中,attributes。
我的初稿包含以下两个陈述:
-- Get the attributes (columns) we are interested in only
SELECT attributeID from attributes
WHERE tableID = 'customers'
-- Iterate over each row of customers, filling only those attributes (columns)
-- obtained by the above SELECT statement
UPDATE customers
SET (use the records from above select statement...)
现在我的问题是如何将它们组合在一起。我知道有可能将 WHERE 子句附加到 SET 子句,但这会根据我的需要选择行,而不是列。我还阅读了有关PIVOT 的信息,但到目前为止只在一张桌子内,而不是两张,就像这里的情况一样。我会非常感谢任何提示,因为我不知道该怎么做。
【问题讨论】:
标签: sql sql-update projection