如何获取查询以列而不是行显示结果?

时间:2018-10-24 10:02:34

标签: sql google-bigquery

我有以下BigQuery查询:

SELECT avg(order_total)  as currentVal FROM ...

UNION ALL

select AVG(order_total)  as lastVal FROM ...

这给了我

Row currentVal  
1    28.50161137440758
2    25.068

我怎么得到它:

Row currentVal          lastVal
1    28.50161137440758  25.068

3 个答案:

答案 0 :(得分:2)

您可以使用子查询并进行聚合:

 [Activity(Theme = "@style/MyTheme")]
public class MyEventsActivity : AppCompatActivity
{
    private SupportToolBar mToolBar;
    private DrawerLayout drawerLayout;
    private ListView mLeftDrawer;
    /// <summary>
    /// Set the layout My Evebts on view, display the events of the user
    /// </summary>
    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        SetContentView(Resource.Layout.MyEvents);
        mToolBar = FindViewById<SupportToolBar>(Resource.Id.toolBarMenu3);
        drawerLayout = FindViewById<DrawerLayout>(Resource.Id.drawerLayout3);
        mLeftDrawer = FindViewById<ListView>(Resource.Id.listviewleft3);
        new  Utils.ActionBar(mToolBar, drawerLayout, mLeftDrawer,this);
        // Create your application here
    }

}

答案 1 :(得分:0)

如下所示的用例

    select max(case when row=1 then currentVal end) as currentVal,
            max(case when row=2 then currentVal end) as lastVal  from 
   (
    SELECT 1 as row avg(order_total)  as currentVal FROM ...

    UNION ALL

    select 2 , AVG(order_total)  as lastVal FROM 
  ) t

答案 2 :(得分:0)

我认为使用子查询将是最简单的方法。

select 
(select AVG(order_total) from ...) as currentVal,
(select  AVG(order_total) from ...) as lastVal