[英]BigQuery INSERT SELECT results in random order of records?
I used standard SQL to insert data form one table to another in BigQuery using Jupyter Notebook.我使用标准 SQL 在 BigQuery 中使用 Jupyter Notebook 将数据从一个表插入到另一个表。
For example I have two tables:例如我有两个表:
table1表格1
ID Product
0 1 book1
1 2 book2
2 3 book3
table2表2
ID Product Price
0 5 book5 8.0
1 6 book6 9.0
2 4 book4 3.0
I used the following codes我使用了以下代码
INSERT test_data.table1
SELECT *
FROM test_data.table2
ORDER BY Price;
SELECT *
FROM test_data.table1
I got我有
ID Product
0 1 book1
1 3 book3
2 2 book2
3 5 book5
4 6 book6
5 4 book4
I expected it appears in the order of ID 1 2 3 4 5 6 which 4,5,6 are ordered by Price我希望它按 ID 1 2 3 4 5 6 的顺序出现,其中 4、5、6 按价格排序
It also seems that the data INSERT and/or SELECT FROM display records in a random order in different run.似乎数据 INSERT 和/或 SELECT FROM 在不同的运行中以随机顺序显示记录。
How do I control the SELECT FROM output without including the 'Price' column in the output table in order to sort them?如何控制 SELECT FROM 输出而不在输出表中包含“价格”列以便对它们进行排序?
And this happened when I import a csv file to create a new table, the record order is random when using SELECT FROM to display them.这发生在我导入 csv 文件以创建新表时,使用 SELECT FROM 显示它们时记录顺序是随机的。
The ORDER BY
clause specifies a column or expression as the sort criterion for the result set. ORDER BY
子句指定一个列或表达式作为结果集的排序标准。
If an ORDER BY clause is not present, the order of the results of a query is not defined .如果不存在 ORDER BY 子句,则查询结果的顺序未定义。
Column aliases from a FROM clause or SELECT list are allowed.来自 FROM 子句或 SELECT 列表的列别名是允许的。 If a query contains aliases in the SELECT clause, those aliases override names in the corresponding FROM clause.
如果查询在 SELECT 子句中包含别名,则这些别名会覆盖相应 FROM 子句中的名称。
So, you most likely wanted something like below所以,你很可能想要像下面这样的东西
SELECT *
FROM test_data.table1
ORDER BY Price DESC
LIMIT 100
Note the use of LIMIT
- it is important part - If you are sorting a very large number of values, use a LIMIT clause to avoid resource exceeded type of error注意
LIMIT
的使用 - 这是重要的部分 - 如果要对大量值进行排序,请使用 LIMIT 子句以避免资源超出类型的错误
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.