来自同一个 select 语句的不同结果

时间:2021-06-14 19:34:18

标签: sql google-bigquery

我有这个查询

SELECT regexp_replace(pn, '([\\W]*)', '') as pn,
       min(date) as date, 
       count(date) as num_days, 
       if((month in (1,3,5,7,8,10,12) and count(date) < 31) 
           or (month in (4,6,9,11) and count(date) < 30)
           or (month = 2 and count(date) < 28), 
           "MISSING", 
           "COMPLETE") as missingORcomplete
FROM `playground-216119.ben.demand_count_daily` dcd
JOIN `playground-216119.ben.CALENDAR_DIMENSION` cd on dcd.date = cd.date_id
where pn = 'MPU6500'
group by year,month,pn
order by date

它的输出是

enter image description here

但是当我把 create or replace table `missing_days` as 放在那个查询前面时

create or replace table `playground-216119.ben.missing_days` as
SELECT regexp_replace(pn, '([\\W]*)', '') as pn,
       min(date) as date, 
       count(date) as num_days, 
       if((month in (1,3,5,7,8,10,12) and count(date) < 31) 
           or (month in (4,6,9,11) and count(date) < 30)
           or (month = 2 and count(date) < 28), 
           "MISSING", 
           "COMPLETE") as missingORcomplete
FROM `playground-216119.ben.demand_count_daily` dcd
JOIN `playground-216119.ben.CALENDAR_DIMENSION` cd on dcd.date = cd.date_id
group by year,month,pn
order by date, on

然后用

查询建表结果

SELECT * FROM `missing_days` where pn = 'MPU6500' order by date

输出是

enter image description here

我知道在第一个中我有 where 子句,但这只是为了向您展示它的外观,然后在第二个中我删除它以创建所有其他零件编号实例。我不知道为什么我的表中的信息与我在 select 语句中获得的信息不同。任何想法将不胜感激!

0 个答案:

没有答案
相关问题