我需要执行多个连接,我从多个表中获取数据并在id上连接。棘手的是一个表需要连接两次。代码如下:
(
SELECT
content.brand_identifier AS brand_name,
CAST(timestamp(furniture.date) AS DATE) AS order_date,
total_hearst_commission
FROM
`furniture_table` AS furniture
LEFT JOIN `content_table` AS content ON furniture.site_content_id = content.site_content_id
WHERE
(
timestamp(furniture.date) >= TIMESTAMP('2020-06-01 00:00:00')
)
)
UNION
(
SELECT
flowers.a_merchant_name AS merchant_name
FROM
`flowers_table` AS flowers
LEFT JOIN `content` AS content ON flowers.site_content_id = content.site_content_id
)
GROUP BY
1,
2,
3,
4
ORDER BY
4 DESC
LIMIT
500
我以为我可以用union,但它给了我一个错误 Syntax error: Expected keyword ALL or keyword DISTINCT but got "("
1条答案
按热度按时间yjghlzjz1#
我不能发表评论,但像ghb州一样,查询的列数不同;因此,工会不会在这里工作。
我认为首先知道为什么需要子查询会很有帮助。我猜这个查询不会产生您想要的结果,所以请详细说明原因。