我正在尝试使用DreamWeaver CS5创建一个只是CREATE VIEW的页面。如何输入我的代码以仅接收包含与登录用户相关的所有数据的表。
mysql_query(
CREATE VIEW UserResults
AS
SELECT E.No, E. Description
, Count(R.RID WHERE $Username= R.Owner)
, Count(R.RID WHERE $Username= R.Owner AND Status==’Active’ )
FROM ETable AS E, RTABLE as R
ORDER BY E.No)
答案 0 :(得分:3)
您必须将查询放在引号中以使其成为字符串。
mysql_query("CREATE VIEW UserResults AS SELECT E.No, E. Description, Count(R.RID WHERE $Username= R.Owner), Count(R.RID WHERE $Username= R.Owner AND Status==’Active’ ) FROM ETable AS E, RTABLE as R ORDER BY E.No")
答案 1 :(得分:1)
答案 2 :(得分:1)
ORDER BY
。WHERE
子句不应位于SELECT
的中间,您需要使用CASE
。 R.RID
语句的THEN
块中的CASE
可能需要1
,并不完全确定您希望从那些COUNT
获得的内容你最初的陈述。
我试图找出你想要做的事情,我认为就是这样:
CREATE VIEW UserResults AS
SELECT E.No, E.Description
, SUM(CASE
WHEN $Username = R.Owner THEN R.RID
ELSE 0
END) AS SumOfOwner
, SUM(CASE
WHEN $Username = R.Owner AND Status = 'Active' THEN R.RID
ELSE 0
END) AS SumOfOwnerAndActive
FROM ETable AS E
INNER JOIN RTABLE as R ON E.No = R.ENo
GROUP BY E.No, E.Description