[英]Beginner at PHP syntax, mySQL_query error
I'm attempting to make a page that is just a CREATE VIEW using DreamWeaver CS5. 我正在尝试使用DreamWeaver CS5制作一个仅创建视图的页面。 How do I need to input my code to just receive a table with all data relevant to the logged in user.
我如何输入代码以仅接收包含与登录用户有关的所有数据的表。
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)
您必须将查询放在引号中以使其成为字符串。
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")
ORDER BY
. ORDER BY
。 WHERE
clause should not be in the middle of the SELECT
, you will need to use a CASE
. WHERE
子句不应位于SELECT
的中间,您将需要使用CASE
。 The R.RID
in the THEN
block of the CASE
statements may need to be a 1
, not entirely sure what you hoped to get from those COUNT
statements you originally had. CASE
语句的THEN
块中的R.RID
可能需要为1
,并不完全确定您希望从最初拥有的COUNT
语句中得到什么。
I tried to figure out what you were trying to do, and I think this is it: 我试图弄清楚您要做什么,我想就是这样:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.