I currently have a SQL query that produces a table with around 10M rows. I would like to append this table with another column that has the same entry for all 10M rows.
我目前有一个SQL查询,它生成一个包含大约10M行的表。我想用另一列附加这个表,该列对所有10M行都有相同的条目。
As an example consider the following toy query
作为一个示例,请考虑下面的toy查询
SELECT PRODUCT_ID, ORDER_QUANTITY
FROM PRODUCT_TABLE
GROUP BY SALES_DAY
And say that is produces the following table
假设它产生了下面的表格
PRODUCT_ID ORDER_QUANTITY`
1 10
2 12
3 14
How can I change this query so that it produces the following table, where every entry in USER_VALUE is 999.
如何更改此查询,以便生成以下表,其中USER_VALUE中的每个条目都是999。
PRODUCT_ID ORDER_QUANTITY USER_VALUE
1 10 999
2 12 999
3 14 999
I realize that there may be several answers here... but I suppose that it would help to know the method that would be produce the table with the smallest file size (I assume this would require specifying the type of data beforehand).
我意识到这里可能有几个答案……但是我想知道生成文件大小最小的表的方法会有所帮助(我假设这需要事先指定数据的类型)。
3 个解决方案
#1
22
Like this:
是这样的:
SELECT PRODUCT_ID, ORDER_QUANTITY, 999 as USER_VALUE
FROM PRODUCT_TABLE
GROUP BY SALES_DAY
#2
4
You can pass it in the SELECT
, for example:
您可以在SELECT中传递它,例如:
SELECT PRODUCT_ID, ORDER_QUANTITY, 999 AS USER_VALUE
FROM PRODUCT_TABLE
GROUP BY SALES_DAY
#3
0
you can use
您可以使用
SELECT PRODUCT_ID, ORDER_QUANTITY, user_value=999
FROM PRODUCT_TABLE
GROUP BY SALES_DAY
#1
22
Like this:
是这样的:
SELECT PRODUCT_ID, ORDER_QUANTITY, 999 as USER_VALUE
FROM PRODUCT_TABLE
GROUP BY SALES_DAY
#2
4
You can pass it in the SELECT
, for example:
您可以在SELECT中传递它,例如:
SELECT PRODUCT_ID, ORDER_QUANTITY, 999 AS USER_VALUE
FROM PRODUCT_TABLE
GROUP BY SALES_DAY
#3
0
you can use
您可以使用
SELECT PRODUCT_ID, ORDER_QUANTITY, user_value=999
FROM PRODUCT_TABLE
GROUP BY SALES_DAY