当存在 WITH 语句时,WHERE IN (SELECT) 语句中断查询
WHERE IN (SELECT) statement breaks query, when there is a WITH statement present
这非常有效:
SELECT qaer_name,
AVG(Minutes(QA_Time)) AS avg_minutes,
COUNT(Zendesk_URL) AS num_tickets
FROM zendeskData
WHERE qaer_name IN (SELECT Name FROM qaers)
AND tags LIKE '%cosmetic%'
AND CAST(sub_to_qa_date AS DATE) >= CAST('${new Date('2021-11-10')}' AS DATE)
GROUP BY qaer_name
但这会因错误而中断:TypeError: Cannot read property '0' of undefined
WITH cosmetic AS (
SELECT qaer_name,
AVG(Minutes(QA_Time)) AS avg_minutes,
COUNT(Zendesk_URL) AS num_tickets
FROM zendeskData
WHERE qaer_name IN (SELECT Name FROM qaers)
AND tags LIKE '%cosmetic%'
AND CAST(sub_to_qa_date AS DATE) >= CAST('${new Date('2021-11-10')}' AS DATE)
GROUP BY qaer_name
)
SELECT * FROM cosmetic
这个没有报错(但没有做我想要的过滤):
WITH cosmetic AS (
SELECT qaer_name,
AVG(Minutes(QA_Time)) AS avg_minutes,
COUNT(Zendesk_URL) AS num_tickets
FROM zendeskData
--WHERE qaer_name IN (SELECT Name FROM qaers)
WHERE tags LIKE '%cosmetic%'
AND CAST(sub_to_qa_date AS DATE) >= CAST('${new Date('2021-11-10')}' AS DATE)
GROUP BY qaer_name
)
SELECT * FROM cosmetic
但是,这个确实给出了同样的错误:TypeError: Cannot read property '0' of undefined
WITH cosmetic AS (
SELECT qaer_name,
AVG(Minutes(QA_Time)) AS avg_minutes,
COUNT(Zendesk_URL) AS num_tickets
FROM zendeskData
WHERE tags LIKE '%cosmetic%'
AND CAST(sub_to_qa_date AS DATE) >= CAST('${new Date('2021-11-10')}' AS DATE)
GROUP BY qaer_name
)
SELECT *
FROM cosmetic
WHERE qaer_name IN (SELECT Name FROM qaers)
为什么 WHERE IN (SELECT)
语句仅在存在 WITH
语句时中断它?
编辑:
这也给出了同样的错误。
let data = Database.alasql(`
;WITH cosmetic AS (
SELECT qaer_name,
AVG(Minutes(QA_Time)) AS avg_minutes,
COUNT(Zendesk_URL) AS num_tickets
FROM zendeskData z
WHERE EXISTS (SELECT 1 FROM qaers q WHERE z.qaer_name = q.Name)
AND tags LIKE '%cosmetic%'
AND CAST(sub_to_qa_date AS DATE) >= CAST('${new Date('2021-11-10')}' AS DATE)
GROUP BY qaer_name
)
SELECT *
FROM cosmetic
`);
Logger.log(data);
我不知道为什么我原来的方法不起作用,但我想出了一个变通办法。
除了制作 qaers
table,然后在以后的查询中选择 table,我的替代方法是制作 table 一个 JS 数组,然后传递将其格式化为列表的查询。
这给出了我正在寻找的正确结果,因为它允许我使用名称列表和 WITH
语句,当我使查询变得更复杂时,这是必需的。
let qaers = Database.alasql(`
SELECT MATRIX Name
FROM annotatorData
WHERE Pod_Number = 'QA'
`);
let data = Database.alasql(`
WITH cosmetic AS (
SELECT qaer_name,
AVG(Minutes(QA_Time)) AS avg_minutes,
COUNT(Zendesk_URL) AS num_tickets
FROM zendeskData
WHERE qaer_name IN ('${qaers.join("','")}')
AND tags LIKE '%cosmetic%'
AND CAST(sub_to_qa_date AS DATE) >= CAST('${new Date('2021-11-10')}' AS DATE)
GROUP BY qaer_name
)
SELECT *
FROM cosmetic
`)
这非常有效:
SELECT qaer_name,
AVG(Minutes(QA_Time)) AS avg_minutes,
COUNT(Zendesk_URL) AS num_tickets
FROM zendeskData
WHERE qaer_name IN (SELECT Name FROM qaers)
AND tags LIKE '%cosmetic%'
AND CAST(sub_to_qa_date AS DATE) >= CAST('${new Date('2021-11-10')}' AS DATE)
GROUP BY qaer_name
但这会因错误而中断:TypeError: Cannot read property '0' of undefined
WITH cosmetic AS (
SELECT qaer_name,
AVG(Minutes(QA_Time)) AS avg_minutes,
COUNT(Zendesk_URL) AS num_tickets
FROM zendeskData
WHERE qaer_name IN (SELECT Name FROM qaers)
AND tags LIKE '%cosmetic%'
AND CAST(sub_to_qa_date AS DATE) >= CAST('${new Date('2021-11-10')}' AS DATE)
GROUP BY qaer_name
)
SELECT * FROM cosmetic
这个没有报错(但没有做我想要的过滤):
WITH cosmetic AS (
SELECT qaer_name,
AVG(Minutes(QA_Time)) AS avg_minutes,
COUNT(Zendesk_URL) AS num_tickets
FROM zendeskData
--WHERE qaer_name IN (SELECT Name FROM qaers)
WHERE tags LIKE '%cosmetic%'
AND CAST(sub_to_qa_date AS DATE) >= CAST('${new Date('2021-11-10')}' AS DATE)
GROUP BY qaer_name
)
SELECT * FROM cosmetic
但是,这个确实给出了同样的错误:TypeError: Cannot read property '0' of undefined
WITH cosmetic AS (
SELECT qaer_name,
AVG(Minutes(QA_Time)) AS avg_minutes,
COUNT(Zendesk_URL) AS num_tickets
FROM zendeskData
WHERE tags LIKE '%cosmetic%'
AND CAST(sub_to_qa_date AS DATE) >= CAST('${new Date('2021-11-10')}' AS DATE)
GROUP BY qaer_name
)
SELECT *
FROM cosmetic
WHERE qaer_name IN (SELECT Name FROM qaers)
为什么 WHERE IN (SELECT)
语句仅在存在 WITH
语句时中断它?
编辑: 这也给出了同样的错误。
let data = Database.alasql(`
;WITH cosmetic AS (
SELECT qaer_name,
AVG(Minutes(QA_Time)) AS avg_minutes,
COUNT(Zendesk_URL) AS num_tickets
FROM zendeskData z
WHERE EXISTS (SELECT 1 FROM qaers q WHERE z.qaer_name = q.Name)
AND tags LIKE '%cosmetic%'
AND CAST(sub_to_qa_date AS DATE) >= CAST('${new Date('2021-11-10')}' AS DATE)
GROUP BY qaer_name
)
SELECT *
FROM cosmetic
`);
Logger.log(data);
我不知道为什么我原来的方法不起作用,但我想出了一个变通办法。
除了制作 qaers
table,然后在以后的查询中选择 table,我的替代方法是制作 table 一个 JS 数组,然后传递将其格式化为列表的查询。
这给出了我正在寻找的正确结果,因为它允许我使用名称列表和 WITH
语句,当我使查询变得更复杂时,这是必需的。
let qaers = Database.alasql(`
SELECT MATRIX Name
FROM annotatorData
WHERE Pod_Number = 'QA'
`);
let data = Database.alasql(`
WITH cosmetic AS (
SELECT qaer_name,
AVG(Minutes(QA_Time)) AS avg_minutes,
COUNT(Zendesk_URL) AS num_tickets
FROM zendeskData
WHERE qaer_name IN ('${qaers.join("','")}')
AND tags LIKE '%cosmetic%'
AND CAST(sub_to_qa_date AS DATE) >= CAST('${new Date('2021-11-10')}' AS DATE)
GROUP BY qaer_name
)
SELECT *
FROM cosmetic
`)