Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何修改表以使其具有SQL的正确权限_Sql_Dataset_Spotfire - Fatal编程技术网

如何修改表以使其具有SQL的正确权限

如何修改表以使其具有SQL的正确权限,sql,dataset,spotfire,Sql,Dataset,Spotfire,我正在尝试在数据集上进行可视化,这有点棘手 我的excel文件如下所示: col1 col2 col3 Production 2017 Production 2018 engine 1 4CV 1.8L 650 Units 800 units engine 1 6CV 1.9L 700 units 300 units Engine 2 4CV 1.8L

我正在尝试在数据集上进行可视化,这有点棘手

我的excel文件如下所示:

col1        col2      col3   Production 2017   Production 2018
engine 1    4CV       1.8L      650 Units         800 units
engine 1    6CV       1.9L      700 units         300 units
Engine 2    4CV       1.8L      450 units         450 units
如果我想以我需要的总量来处理年度工作,我将使用Spotfire作为可视化工具:

col1        col2      col3   Production    Year
engine 1    4CV       1.8L       650       2017 
engine 1    4CV       1.8L       800       2018 
engine 1    6CV       1.9L       700       2017
engine 1    6CV       1.9L       300       2018
Engine 2    4CV       1.8L       450       2017
Engine 2    4CV       1.8L       450       2018

你们知道如何将我的第一个表转换为第二个表吗?也许使用一个SQL查询

只需使用两个查询,在每个查询中只投影两年中的一个,然后将两个查询合并在一起。大概是这样的:

SELECT  col1, col2, col3, Prod2017 FROM [YourTable]
UNION ALL
SELECT  col1, col2, col3, Prod2018 FROM [YourTable] 
+----------+------+------+-----------------+-----------+
|   col1   | col2 | col3 |    Category     |   Value   |
+----------+------+------+-----------------+-----------+
| engine 1 | 4CV  | 1.8L | Production 2017 | 650 Units |
| engine 1 | 4CV  | 1.8L | Production 2018 | 800 units |
| engine 1 | 6CV  | 1.9L | Production 2017 | 700 units |
| engine 1 | 6CV  | 1.9L | Production 2018 | 300 units |
| Engine 2 | 4CV  | 1.8L | Production 2017 | 450 units |
| Engine 2 | 4CV  | 1.8L | Production 2018 | 450 units |
+----------+------+------+-----------------+-----------+

其余的都是简单的格式问题,可以通过使用
CONVERT
来实现。您需要的是
UNPIVOT
。我不确定当连接到嵌入式数据源(如excel)时,您将如何利用SQL查询。如果这是存储在RDBMS中的,那么可能。无论哪种方式,您都希望在SQL或Spotfire中使用
UNPIVOT

  • 插入>转换
  • 在“转换”下选择“取消分割”,然后单击“添加”
  • 选择col1、col2和col3并将它们添加到“要通过的列”中
  • 选择2017年生产、2018年生产以及您拥有的任何其他列年,并将其添加到“要转换的列”中
  • 单击“确定”
这将使您的数据如下所示:

SELECT  col1, col2, col3, Prod2017 FROM [YourTable]
UNION ALL
SELECT  col1, col2, col3, Prod2018 FROM [YourTable] 
+----------+------+------+-----------------+-----------+
|   col1   | col2 | col3 |    Category     |   Value   |
+----------+------+------+-----------------+-----------+
| engine 1 | 4CV  | 1.8L | Production 2017 | 650 Units |
| engine 1 | 4CV  | 1.8L | Production 2018 | 800 units |
| engine 1 | 6CV  | 1.9L | Production 2017 | 700 units |
| engine 1 | 6CV  | 1.9L | Production 2018 | 300 units |
| Engine 2 | 4CV  | 1.8L | Production 2017 | 450 units |
| Engine 2 | 4CV  | 1.8L | Production 2018 | 450 units |
+----------+------+------+-----------------+-----------+
  • 单击编辑>列属性
  • 将“类别”列和“值”列的名称更改为“生产和年份”
现在,您的数据将如下所示

+----------+------+------+-----------------+------------+
|   col1   | col2 | col3 |      Year       | Production |
+----------+------+------+-----------------+------------+
| engine 1 | 4CV  | 1.8L | Production 2017 | 650 Units  |
| engine 1 | 4CV  | 1.8L | Production 2018 | 800 units  |
| engine 1 | 6CV  | 1.9L | Production 2017 | 700 units  |
| engine 1 | 6CV  | 1.9L | Production 2018 | 300 units  |
| Engine 2 | 4CV  | 1.8L | Production 2017 | 450 units  |
| Engine 2 | 4CV  | 1.8L | Production 2018 | 450 units  |
+----------+------+------+-----------------+------------+
+----------+------+------+-----------------+------------+---------+
|   col1   | col2 | col3 |      Year       | Production | TheYear |
+----------+------+------+-----------------+------------+---------+
| engine 1 | 4CV  | 1.8L | Production 2017 | 650 Units  |    2017 |
| engine 1 | 4CV  | 1.8L | Production 2018 | 800 units  |    2018 |
| engine 1 | 6CV  | 1.9L | Production 2017 | 700 units  |    2017 |
| engine 1 | 6CV  | 1.9L | Production 2018 | 300 units  |    2018 |
| Engine 2 | 4CV  | 1.8L | Production 2017 | 450 units  |    2017 |
| Engine 2 | 4CV  | 1.8L | Production 2018 | 450 units  |    2018 |
+----------+------+------+-----------------+------------+---------+
如果你想一年一年,那么

  • 插入>计算列
  • 插入此表达式
    Right([Year],4)
您的数据现在将如下所示

+----------+------+------+-----------------+------------+
|   col1   | col2 | col3 |      Year       | Production |
+----------+------+------+-----------------+------------+
| engine 1 | 4CV  | 1.8L | Production 2017 | 650 Units  |
| engine 1 | 4CV  | 1.8L | Production 2018 | 800 units  |
| engine 1 | 6CV  | 1.9L | Production 2017 | 700 units  |
| engine 1 | 6CV  | 1.9L | Production 2018 | 300 units  |
| Engine 2 | 4CV  | 1.8L | Production 2017 | 450 units  |
| Engine 2 | 4CV  | 1.8L | Production 2018 | 450 units  |
+----------+------+------+-----------------+------------+
+----------+------+------+-----------------+------------+---------+
|   col1   | col2 | col3 |      Year       | Production | TheYear |
+----------+------+------+-----------------+------------+---------+
| engine 1 | 4CV  | 1.8L | Production 2017 | 650 Units  |    2017 |
| engine 1 | 4CV  | 1.8L | Production 2018 | 800 units  |    2018 |
| engine 1 | 6CV  | 1.9L | Production 2017 | 700 units  |    2017 |
| engine 1 | 6CV  | 1.9L | Production 2018 | 300 units  |    2018 |
| Engine 2 | 4CV  | 1.8L | Production 2017 | 450 units  |    2017 |
| Engine 2 | 4CV  | 1.8L | Production 2018 | 450 units  |    2018 |
+----------+------+------+-----------------+------------+---------+

注意,您可以在向dxp“添加数据”时执行此操作。每当数据被刷新时,这些转换都会发生

谢谢,这是一种肯定的方法。如果有人有办法直接更改表格,我很乐意。回答得很好,非常感谢。今天下午我正在尝试!谢谢,没问题@oilid.b!这是一个非常好的提示!再次感谢您的详细解释。无需担心@oilid.bHi,我想知道是否有办法保留数据集的两个版本。这样,我会将我的第一个数据集保存在一个视图中,每次我更新它时,它都会在另一个视图中进行所需的转换。