我正在尝试使用SQL创建查询表,并在其上的仪表板中构建数据透视表,并且有以下查询:
SELECT
"Owner",
"Meetings",
"No Meeting Reason",
FROM Investors
所有者是全名,会议?是是/否条目,没有会议原因是值列表:“ 尚未开始”,“ 本月没有会议”,“ 正在等待详细信息发布”和空值。>
基本上,我想做的是使用IF查询,因此我可以创建以下列:
如何在查询中执行此操作?我知道第一个可能是
IF("Meetings?" = 'Yes',1,0) 'Confirmed Meeting'
预先感谢您的支持。
****编辑****
因此,我根据建议使用了CASE WHEN来更改此设置,但是,当每次确认会议和不开会时,我应该得到未完成 = 1时。 em> are = 0
(因为它是:如果 Meetings?是'No'并且 No Meeting Reason 是除本月没有会议之外的任何其他东西 >)
我没有得到,所以我将如何为以下内容构造一个嵌套的CASE WHEN语句: 如果“已确认会议”和“未开会”都不都是0,那么“未完成”是1?
答案 0 :(得分:0)
请尝试这样的操作。
SELECT
"Owner",
"Meetings",
"No Meeting Reason",
case when "Meetings"='Yes' then 1
else 0
end as "Confirmed Meeting",
case when "Meetings"='No' and "No Meeting Reason" ='No Meeting(s) This Month' then 1
else 0
end as "No Meeting",
case when "Meetings"='No' and nvl("No Meeting Reason",'x') in ('Not Yet Started','Awaiting Details Publish','x') then 1
else 0
end as "Not Complete"
FROM Investors;
答案 1 :(得分:0)
您可以使用CASE
进行此类请求。尽管我不了解"No Meeting Reason"
的数据类型是字符串还是带有列表的嵌套列以及您当前使用的数据库。
SELECT
"Owner",
"Meetings",
"No Meeting Reason",
CASE
WHEN "Meetings" = 'Yes' THEN 1
ELSE 0
END AS "Confirmed Meeting",
CASE
WHEN "Meetings" = 'No' AND "No Meeting Reason" = 'No Meeting(s) This Month' THEN 1
ELSE 0
END AS "No Meeting",
CASE
WHEN "Meetings" = 'No' AND "No Meeting Reason" IN ('Not Yet Started, Awaiting Details Publish', NULL) THEN 1
ELSE 0
END AS "Not Complete"
FROM Investors
对于您编辑的部分,这意味着已确认的会议和没有会议的会议都不都是0;会议可以是“是”或“否”,没有会议原因必须是“本月没有会议”。只需在"Not Complete"
列中添加这样的条件即可。
SELECT
"Owner",
"Meetings",
"No Meeting Reason",
CASE
WHEN "Meetings" = 'Yes' THEN 1
ELSE 0
END AS "Confirmed Meeting",
CASE
WHEN "Meetings" = 'No' AND "No Meeting Reason" = 'No Meeting(s) This Month' THEN 1
ELSE 0
END AS "No Meeting",
CASE
WHEN "Meetings" IN ('Yes', 'No') AND "No Meeting Reason" = 'No Meeting(s) This Month' THEN 1
WHEN "Meetings" = 'No' AND "No Meeting Reason" IN ('Not Yet Started, Awaiting Details Publish', NULL) THEN 1
ELSE 0
END AS "Not Complete"
FROM Investors
答案 2 :(得分:0)
在SQL Server
中,您可以像这样使用IIF
:
SELECT IIF(500<1000, 'YES', 'NO');
我不确定zoho
是否也支持此功能。我找不到任何资源,因此无法测试。