如何将这两个查询集成到一个查询中?

时间:2019-07-19 10:59:46

标签: sql google-bigquery

有人可以告诉我如何将这两个查询合并为一个查询吗?

我已经尝试过此代码,但是这里的问题是它不会更新Adserver表。

with first as (
    select *, c_date = Current_date() from FRIDAY.Adserver where C_date IS NULL
),

second as (
    select * from FRIDAY.Adserver JOIN FRIDAY.Matching_Table 
    ON Adserver.Placement_ExtID = Matching_Table.string_field_0

  ),
Tird As(
Select *, CONCAT(Cast(Date as String),"-",Second.string_field_0) AS New_IDS from Second 
) Select * from Tird

首先,我需要使用当前日期更新Adserver表:

查询1: UPDATE FRIDAY.Adserver SET C_date()= CURRENT_Date()其中C_date为NULL;

然后我只选择当前日期的数据:

查询2:

第一个为( 从FRIDAY.Adserver中选择*,其中C_date = Current_date() ), 第二个 从First JOIN FRIDAY.Matching_Table1中选择*     ON First.Placement_ExtID = Matching_Table1.string_field_1或First.Placement_ExtID = Matching_Table1.string_field_0 ), 奇数As( 选择*,CONCAT(Cast(日期作为字符串),“-”,Second.string_field_0)AS Second_IDS(从Second)选择*从Tird中选择


是否有将上述查询1和查询2组合在一起的方法?

1 个答案:

答案 0 :(得分:1)

那不可能。

查询可以更改数据(INSERT,UPDATE,DELETE)或返回数据(SELECT)。要同时执行两个代码。但这取决于使用的数据库服务器。

例如,您可以创建一个函数,该函数首先执行UPDATE语句,然后从SELECT语句返回数据。但是正如我所说,能否实现以及如何实现取决于数据库系统。

相关问题