如何从BigQuery表中选择特定记录?

时间:2016-07-28 20:58:23

标签: google-bigquery

我必须执行以下逻辑。我有一个包含多个字段的表,从该表中我必须选择具有组作为c而不是d的prod。一些刺激将有c组和d组。从选定的产品中,我必须选择其他字段,如纬度,经度等。

从下表中,使用SQL,如何检索突出显示的行?

enter image description here

2 个答案:

答案 0 :(得分:1)

我的理解是,“c”表示“我”,而“d”表示“f” 下面是这样的。
它标识那些在“i”组中但不在“f”组中的产品

SELECT Prod
FROM (
  SELECT Prod, 
    CONCAT('|', GROUP_CONCAT_UNQUOTED(group, '|'), '|') AS list 
  FROM YourTable
  GROUP BY Prod
)
WHERE list CONTAINS '|i|' 
AND NOT list CONTAINS '|f|'

您可以使用以下

进行测试
SELECT Prod
FROM (
  SELECT 
    Prod, 
    CONCAT('|', GROUP_CONCAT_UNQUOTED(group, '|'), '|') AS list 
  FROM 
    (SELECT 'prod1' AS Prod, 'i' AS group),
    (SELECT 'prod1' AS Prod, 'f' AS group),
    (SELECT 'prod1' AS Prod, 'f' AS group),
    (SELECT 'prod2' AS Prod, 'i' AS group),
    (SELECT 'prod3' AS Prod, 'i' AS group),
    (SELECT 'prod4' AS Prod, 'i' AS group),
    (SELECT 'prod4' AS Prod, 'f' AS group),
    (SELECT 'prod4' AS Prod, 'f' AS group),
    (SELECT 'prod4' AS Prod, 'f' AS group),
  GROUP BY Prod
)
WHERE list CONTAINS '|i|' 
AND NOT list CONTAINS '|f|'

所以你最后的查询可能看起来像

SELECT <list of needed fields>
FROM YourTable
WHERE Prod IN (
  SELECT Prod
  FROM (
    SELECT Prod, 
      CONCAT('|', GROUP_CONCAT_UNQUOTED(group, '|'), '|') AS list 
    FROM YourTable
    GROUP BY Prod
  )
  WHERE list CONTAINS '|i|' 
  AND NOT list CONTAINS '|f|'
)

答案 1 :(得分:0)

使用最基本的SQL,即使用ServiceConfiguration.configurations.upsert({ service: "facebook" }, { $set: { appId: '11111', clientId: '11111', // <-- Same as appId loginStyle: "popup", secret: '22222' } });

 var modal = function(Exturl) {
var ImageModalWin = new Ext.Window(
        {
            modal : true,
            border : false,
            plain : true,
            maximizable : true,
            scrollable : true,
            monitorResize : true,
            items : {
                xtype : 'button',   
                iconCls : 'fa fa-print',
                iconMask : true,
                listeners : {
                    click : function() {
                        var divToPrint = document.getElementById('imgId');
                        var newWin = window.open('', 'Print-Window');

                        newWin.document.open();

                        newWin.document
                                .write('<html><body onload="window.print()">'
                                        + divToPrint.innerHTML
                                        + '</body></html>');
                        newWin.document.close();

                        setTimeout(function() {
                            newWin.close();
                        }, 10);

                    }
                }

            },
            html : '<div id="imgId" class="to-print" style="width:100%;height:100%;"><center><img src="'
                    + url + '"></center></div>',
            resizable : {
                preserveAspectRatio : true
            }
        });
ImageModalWin.show();