我正在使用Amazon Quick Sight从MySQL数据库提取数据来为我的雇主生成可视数据。我是一名学生,有一点SQL经验,但是以前从未处理过这么大的数据库。
我需要抓住的表是001_leads至024_leads。这些表都以相同的方式设计。
这是我目前一直没有做的事情。 Quick Sight不会返回出色的错误警报,因此我一直在研究不同的解决方案。SELECT 001_leads.lead_received AS "City-A Leads Q1", 002_leads.lead_received AS "City-B Leads Q1"FROM 001_leads, 002_leadsWHERE lead_received BETWEEN '2017-01-01' AND '2017-04-01'
我很肯定我需要使用联接,但是我不知道如何联接24个不同的表。
理想情况下,运行此查询时,它将显示每个城市的每条线索。
感谢您的光临:)
编辑:
最佳答案
我认为联盟是您追求的目标...不确定,请问您所提问题的措辞。
例如。
SELECT 001_leads.lead_received AS Leads
FROM 001_leads
WHERE lead_received BETWEEN '2017-01-01' AND '2017-04-01'
UNION
SELECT 002_leads.lead_received
FROM 002_leads
WHERE lead_received BETWEEN '2017-01-01' AND '2017-04-01'
更新
以下内容应按照您的要求执行。
SELECT l1.lead_received AS LeadsCityA, l2.lead_received AS LeadsCityA, l3.lead_received AS LeadsCityA, l4.lead_received AS LeadsCityA
FROM 001_leads l1
LEFT JOIN 002_leads l2
ON lead_received BETWEEN '2017-01-01' AND '2017-04-01'
LEFT JOIN 003_leads l3
ON lead_received BETWEEN '2017-01-01' AND '2017-04-01'
LEFT JOIN 004_leads l4
ON lead_received BETWEEN '2017-01-01' AND '2017-04-01'
WHERE lead_received BETWEEN '2017-01-01' AND '2017-04-01'
关于mysql - 在Amazon Quick Sight上使用SQL从多个表中提取同一列,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44144051/