【发布时间】:2021-03-18 21:00:01
【问题描述】:
即使我在两个查询中都添加了 order by 子句,我也会得到不同的排序顺序。 以下是我在 Teradata 和雪花上执行的查询-
Teradata:
Select column1, column2, column3, column4,column5 From Teradata_Table Where column1 in (1027837724,1040965189,1046224751) and column2='2021-03-11'
order by column1 ;
结果 -->
| column1 | column2 | column3 | column4 | column5 |
|---|---|---|---|---|
| 1027837724 | 3/11/2021 | 0 | 42.66 | 5942 |
| 1027837724 | 3/11/2021 | 12052.34 | 2.99 | 5735 |
| 1040965189 | 3/11/2021 | 5336.72 | 10.87 | 5944 |
| 1040965189 | 3/11/2021 | 0 | 311.16 | 5942 |
| 1046224751 | 3/11/2021 | 0 | 14.99 | 5735 |
| 1046224751 | 3/11/2021 | 0 | 2.99 | 5735 |
雪花:
Select column1, column2, column3, column4,column5 From Snowflake_Tablename Where column1 in (1027837724,1040965189,1046224751) and column2='2021-03-11'
order by column 1
结果 -->
| column1 | column2 | column3 | column4 | column5 |
|---|---|---|---|---|
| 1027837724 | 3/11/2021 | 12052.34 | 2.99 | 5735 |
| 1027837724 | 3/11/2021 | 0 | 42.66 | 5942 |
| 1040965189 | 3/11/2021 | 5336.72 | 10.87 | 5944 |
| 1040965189 | 3/11/2021 | 0 | 311.16 | 5942 |
| 1046224751 | 3/11/2021 | 0 | 14.99 | 5735 |
| 1046224751 | 3/11/2021 | 0 | 2.99 | 5735 |
【问题讨论】:
-
您仅按列指定单个订单。您在该列中有多个具有相同值的行,因此其中的排序基本上是随机的。
-
是的。如果您在同一个 DBMS 上运行两次查询,甚至不能保证对具有相同 ORDER BY 列的一组行进行排序内。
标签: sorting sql-order-by teradata snowflake-cloud-data-platform resultset