excel - 雪花 ODBC 到 Excel,包含空格的字段名称错误
问题描述
我们有一组高度复杂的表,其中包含最终为 Tableau 服务器上的一系列仪表板提供数据的嵌套视图。基本视图在某些数据字段上使用“as”子句来创建字段名称中带有空格的字段(iesomefieldname as “Some Field Name”)。以后的视图使用 * 通配符来检索所有值。Tableau 能够处理它。
现在的问题是用户想要在 Excel 中访问这些最终视图。
我们在他们的工作站上建立了一个 ODBC 连接,当他们从最终视图之一中提取数据时。但是,字段名称中包含空白的字段显示为错误,并且在生成的工作表中为空白。我正在尝试在该最终视图上构建一个视图并使用“as”子句删除字段名称中的空格,但无法为源字段找到正确的 SQL 语法。我试过括号,但没有奏效。
尝试 Power BI 会更好吗?我们的数据管理人员才刚刚开始使用它;我还没有看到它,但将是明天。
提前感谢您提供的任何提示!娄
解决方案
在具有重命名列的最终视图之上创建一个视图可能是您最简单的解决方案。从使用空格创建的列中进行选择的 SQL 语法(更一般地说:在其字段名称周围创建的列)是在您从中选择时"
将该列放在双引号 ( ) 中。"
这是一个例子:
-- Create a sample table. The first column contains spaces and capitals
create or replace table test_table
(
"Column with Spaces" varchar, -- A column created with quotes around it means that you can put anything into the field name. Including spaces & funky characters
col_without_spaces varchar
);
-- Insert some sample data
insert overwrite into test_table
values ('row1 col1', 'row1 col2'),
('row2 col1', 'row2 col2');
-- Create a view that renames columns
create or replace view test_view as
(
select
"Column with Spaces" as col_1, -- But now you have to select it like this since the spaces and capital letters have been treated literally in the create table statement
col_without_spaces as col_2
from test_table
);
-- Select from the view
select * from test_view;
产生:
+---------+---------+
|COL_1 |COL2 |
+---------+---------+
|row1 col1|row1 col2|
|row2 col1|row2 col2|
+---------+---------+
推荐阅读
- python - python中KNN的数据预处理
- optimization - 根据多次转化计算转化“权重”
- javascript - 按钮事件仅选择第一类。(jQuery)
- reactjs - 在 React 中使用通用组件
- python - 用于修改新文件并将修改后的文件添加到另一个目录的 AWS Lambda 函数
- python - 使用 cx_freeze 创建 .msi 时包括 Ghostscript
- python - 数据库表未填充数据(MySQL 连接器/Python)
- python - 是否有没有递归的快速排序的 Python 实现?
- discord - 如何创建公告频道
- python - 使用两个数据框中的两列查找并创建新列 pandas