[英]Convert SQL CTE expression to normal subquery
is there a way to convert the following sql query with CTE expression into a subquery version? 有没有办法将以下sql查询与CTE表达式转换为子查询版本? It works on SQL 8 but i need to run this on SQL 5
它适用于SQL 8,但我需要在SQL 5上运行它
WITH no_duplicate AS
( SELECT * , ROW_NUMBER() OVER (PARTITION BY lead_google_client_id ORDER BY lead_google_client_id DESC) AS single_googleClientID
FROM properties
)
SELECT lead_referral,
count(*) as total,
count(case when state = 'rejected' and priority != 3 then 1 end) as rejected
FROM no_duplicate
WHERE single_googleClientID=1
GROUP BY lead_referral
Disclaimer: I am not sure what you are trying to accomplish. 免责声明:我不确定您要完成的任务。 For that you will have to provide more information, like sample data from the
properties
table. 为此,您必须提供更多信息,例如
properties
表中的示例数据。
Try this: 尝试这个:
SELECT
ROW_NUMBER() OVER (PARTITION BY lead_google_client_id ORDER BY lead_google_client_id DESC) AS single_googleClientID, lead_referral,
count(*) as total,
count(case when state = 'rejected' and priority != 3 then 1 end) as rejected
FROM properties
WHERE single_googleClientID=1
GROUP BY lead_referral
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.