【问题标题】:How can i insert 2 new rows extraction from a query in query如何在查询中插入从查询中提取的 2 个新行
【发布时间】:2023-04-03 16:10:02
【问题描述】:

我必须更改原始文件并将其拆分,但我不知道如何。

SELECT A.QADAte, A.ProcessorType, A.ASDType ,A.Threshold, A.Accuracy, A.Accept, A.ItemsQty, C.Accuracy Accuracy01, C.Accept Accept01, C.ItemsQty ItemsQty01, D.Accuracy Accuracy07,
D.Accept Accept07, D.ItemsQty ItemsQty07, E.Accuracy Accuracy30, E.Accept Accept30, E.ItemsQty ItemsQty30
from `serv.dbo.accuracies` A inner join
(SELECT ProcessorType, max(QADate) maxQADate FROM `serv.dbo.accuracies` group by ProcessorType)
B ON A.QADate = B.maxQADate and A.ProcessorType = B.ProcessorType and A.SkipNulls = true and A.ASDType = '%' and A.Days=6
left join `serv.dbo.accuracies` C ON C.QADate=DATE_ADD(A.QADate, INTERVAL -1 DAY) and C.ProcessorType = A.ProcessorType and C.ASDType = '%' and C.SkipNulls = true and C.Days=6
left join `serv.dbo.accuracies` D ON D.QADate=DATE_ADD(A.QADate, INTERVAL -7 DAY) and D.ProcessorType = A.ProcessorType and D.ASDType = '%' and D.SkipNulls = true and D.Days=6
left join `serv.dbo.accuracies` E ON E.QADate=DATE_ADD(A.QADate, INTERVAL -30 DAY) and E.ProcessorType = A.ProcessorType and E.ASDType = '%' and E.SkipNulls = true and E.Days=6 

结果是这样的

我必须提取 F06 原始数据并将他放入 2 个不同的原始数据,其中 ASDType 不是“%”。我必须保留表格中的其余数据。

拜托,你能帮帮我吗?

【问题讨论】:

    标签: sql google-bigquery tableau-api


    【解决方案1】:

    您也可以在 tableau 中执行此操作,但由于您直接使用查询,因此最好链接多个查询并获取结果集。

    据我了解,要获得单独的行,您需要再创建一个查询 并为这两个查询做一个联合。对于第二个查询,仅采用 F06ASDType <> '%'作为过滤器检查第二个查询,我已添加它

        SELECT A.QADAte, A.ProcessorType, A.ASDType ,A.Threshold, A.Accuracy, A.Accept, A.ItemsQty, C.Accuracy Accuracy01, C.Accept Accept01, C.ItemsQty ItemsQty01, D.Accuracy Accuracy07,
        D.Accept Accept07, D.ItemsQty ItemsQty07, E.Accuracy Accuracy30, E.Accept Accept30, E.ItemsQty ItemsQty30
        from `serv.dbo.accuracies` A inner join
        (SELECT ProcessorType, max(QADate) maxQADate FROM `serv.dbo.accuracies` group by ProcessorType)
        B ON A.QADate = B.maxQADate and A.ProcessorType = B.ProcessorType and A.SkipNulls = true and A.ASDType = '%' and A.Days=6
        left join `serv.dbo.accuracies` C ON C.QADate=DATE_ADD(A.QADate, INTERVAL -1 DAY) and C.ProcessorType = A.ProcessorType and C.ASDType = '%' and C.SkipNulls = true and C.Days=6
        left join `serv.dbo.accuracies` D ON D.QADate=DATE_ADD(A.QADate, INTERVAL -7 DAY) and D.ProcessorType = A.ProcessorType and D.ASDType = '%' and D.SkipNulls = true and D.Days=6
        left join `serv.dbo.accuracies` E ON E.QADate=DATE_ADD(A.QADate, INTERVAL -30 DAY) and E.ProcessorType = A.ProcessorType and E.ASDType = '%' and E.SkipNulls = true and E.Days=6
    
    UNION
    
        SELECT A.QADAte, A.ProcessorType, A.ASDType ,A.Threshold, A.Accuracy, A.Accept, A.ItemsQty, C.Accuracy Accuracy01, C.Accept Accept01, C.ItemsQty ItemsQty01, D.Accuracy Accuracy07,
        D.Accept Accept07, D.ItemsQty ItemsQty07, E.Accuracy Accuracy30, E.Accept Accept30, E.ItemsQty ItemsQty30
        from `serv.dbo.accuracies` A inner join
        (SELECT ProcessorType, max(QADate) maxQADate FROM `serv.dbo.accuracies` group by ProcessorType)
        B ON A.QADate = B.maxQADate and A.ProcessorType = B.ProcessorType and A.SkipNulls = true and A.ASDType = '%' and A.Days=6
        left join `serv.dbo.accuracies` C ON C.QADate=DATE_ADD(A.QADate, INTERVAL -1 DAY) and C.ProcessorType = A.ProcessorType and C.ASDType <> '%' and C.SkipNulls = true and C.Days=6 and B.ProcessorType = 'F06'
        left join `serv.dbo.accuracies` D ON D.QADate=DATE_ADD(A.QADate, INTERVAL -7 DAY) and D.ProcessorType = A.ProcessorType and D.ASDType = '%' and D.SkipNulls = true and D.Days=6
        left join `serv.dbo.accuracies` E ON E.QADate=DATE_ADD(A.QADate, INTERVAL -30 DAY) and E.ProcessorType = A.ProcessorType and E.ASDType = '%' and E.SkipNulls = true and E.Days=6
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-09-24
      • 1970-01-01
      • 1970-01-01
      • 2016-08-26
      • 1970-01-01
      • 2016-04-14
      相关资源
      最近更新 更多