CREATE VIEW 简单问题!解决马上结贴
CREATE VIEW vRULE_INFO AS
SELECT E.CARID, E.RULE_ID, E.Status, P.RULEID
FROM CAR_RULE E, RULE_INFO P
WHERE (P.RULEID = E.RULE_ID)
AND (E.Status=1)
OR (E.Status=3)
SELECT * FROM vRULE_INFO WHERE CarId = 4用这句执行上面的视图 得到下面子查询相同结果怎么改视图啊 谢谢 解决马上结贴
SELECT * FROM RULE_INFO AS P WHERE RULEID IN(SELECT RULE_ID FROM CAR_RULE WHERE CarId = 4 AND Status=1 or Status=3)
------解决方案--------------------修改视图用alter
ALTER VIEW vRULE_INFO AS
SELECT * FROM RULE_INFO AS P WHERE RULEID IN(SELECT RULE_ID FROM CAR_RULE WHERE CarId = 4 AND Status=1 or Status=3)
------解决方案--------------------alter
------解决方案--------------------你們沒有看懂樓主的意思
按他的意思,是要將視圖修改後,通過執行SELECT * FROM vRULE_INFO WHERE CarId = 4來得到與SELECT * FROM RULE_INFO AS P WHERE RULEID IN(SELECT RULE_ID FROM CAR_RULE WHERE CarId = 4 AND Status=1 or Status=3)一樣的結果
但是有一個問題
子查詢的結果中的列是RULE_INFO表的所有列,那麼如果要通過視圖也得到相同的結果,視圖的列中必須包含CarId,從子查詢中只能分析出CarId列屬於表CAR_RULE,但在不在RULE_INFO表中就不知道了