mysql相当于访问存储的查询

时间:2011-02-01 15:46:55

标签: mysql ms-access

我正在将一个使用访问权限的网站转换为MySQL的主数据库。我遇到了一个SQL语句的问题,我一直无法通过谷歌找到答案。

此SQL语句引用存储的查询(qryProgramMostRecentVersion):

strSQL1 = "SELECT q.Program_ID, q.ProgramName, q.MostRecentVersion, q.MostRecentVersionID " & _
"FROM qryProgramMostRecentVersion AS q WHERE NOT EXISTS(" & _
"SELECT OrderID FROM Orders " & _
"WHERE q.MostRecentVersionID = Orders.ProgramVersion_ID AND " & _
"Orders.Customer_ID = " & strCustomerID & " AND Orders.RegStatus_ID=1) " & _
"ORDER BY q.Program_ID"

MySQL中有没有相应的东西?

2 个答案:

答案 0 :(得分:4)

是的,它被称为View。只需使用CREATE VIEW <viewname> AS后跟您的查询:

CREATE VIEW qryProgramMostRecentVersion AS
SELECT col1, col2 FROM sometable
....

答案 1 :(得分:0)

您可以使用View。 尝试这样的事情: - 在数据库中创建一个VIew

CREATE OR REPLACE VIEW vwPrgRecentVersion AS
SELECT q.program_id, 
       q.programname, 
       q.mostrecentversion, 
       q.mostrecentversionid 
FROM   qryprogrammostrecentversion AS q 
WHERE  NOT EXISTS(SELECT orderid 
                  FROM   orders 
                  WHERE  q.mostrecentversionid = orders.programversion_id 
                         AND orders.regstatus_id = 1) ;

然后从你的代码中使用:

SELECT *
  FROM vwPrgRecentVersion
 WHERE Orders.Customer_ID =  " & strCustomerID & " ORDER BY Program_ID"