用于读取特定表、列的 sql 命令

发布于 2024-07-29 07:14:19 字数 268 浏览 3 评论 0原文

对于 SQL 坚定拥护者来说,这可能是一个非常愚蠢的问题,但我只想要一个 SQL 命令。

详细信息,

我正在使用一个名为R的数据分析工具,该工具使用ODBC从XLS读取数据。 我现在正在尝试从 XLS 文件读取数据。 R 中的 ODBC 工具接受 SQL 命令。

问题,

有人能给我一个 SQL 命令来从 XLS 文件读取数据吗? - 指定板材 - 指定列[按名称] - 指定行[仅由行索引指定]

谢谢...

This is probably a very stupid question for SQL stalwarts, but I just want one SQL command.

Details,

I am using a data analysis tool called R, this tool uses ODBC to read data from XLS. I am now trying to read data from an XLS file. The ODBC tool in R accepts SQL commands.

Question,

Can someone give me an SQL command that will read data from an XLS file's
- Specified sheet
- Specified column [by name]
- Specified row [Specified just by Row Index]

Thanks ...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

皇甫轩 2024-08-05 07:14:19

通过下面的查询,您可以读取列 A、& 的第 61 行的数据。 G 应该读取 G 之前的所有列。

SELECT * FROM [Sheet1$a61:G]

With the query below you can read the data from row 61 of cloumn A, & G is supposed to read all columns till G.

SELECT * FROM [Sheet1$a61:G]
[浮城] 2024-08-05 07:14:19

设置与文件的连接后,您可以使用以下语句:

select [columnname] from [sheetname$] where [columnname] = 'somevalue'

不确定行索引。 但是,如果文件中的每一行都有序列号或任何此类唯一值,则可以使用 where 子句。

Once you have set the connection to the file, you can use following statement:

select [columnname] from [sheetname$] where [columnname] = 'somevalue'

Not sure about the row index thing. But you can make use of where clause if each row in the file has serial number or any such unique value.

中二柚 2024-08-05 07:14:19

下面是一个示例查询:

SELECT [sheet1$.col1], [sheet1$.col2], [sheet2$.col1] 
FROM   [sheet1$], [sheet2$] 
WHERE  [sheet1$.col1] = [sheet2$.col2]

假设 Excel 文档有 2 个工作表(sheet1sheet2)。 每个工作表有 2 列,第一行作为标题(每个工作表中的 col1col2)。

这是完整的代码:

> library(RODBC)
> conn <- odbcConnectExcel('c:/tmp/foo.xls')
> query <- "select [sheet1$.col1], [sheet1$.col2], [sheet2$.col1] 
            from [sheet1$], [sheet2$] 
            where [sheet1$.col1] = [sheet2$.col2];"
> result <- sqlQuery(conn, query)
> odbcClose(conn)
> result
  col1 col2 col1.1
1    1    3      5
2    2    4      6
3    3    5      7

我从未找到处理行号的方法。 我只是创建一个额外的列并按顺序填写。 不确定这是否适合你。

Here's a sample query:

SELECT [sheet1$.col1], [sheet1$.col2], [sheet2$.col1] 
FROM   [sheet1$], [sheet2$] 
WHERE  [sheet1$.col1] = [sheet2$.col2]

This assumes an excel document with 2 sheets (sheet1 and sheet2). Each sheet has 2 columns, with the first row as headers (col1 and col2 in each sheet).

Here's the complete code:

> library(RODBC)
> conn <- odbcConnectExcel('c:/tmp/foo.xls')
> query <- "select [sheet1$.col1], [sheet1$.col2], [sheet2$.col1] 
            from [sheet1$], [sheet2$] 
            where [sheet1$.col1] = [sheet2$.col2];"
> result <- sqlQuery(conn, query)
> odbcClose(conn)
> result
  col1 col2 col1.1
1    1    3      5
2    2    4      6
3    3    5      7

I've never found a way to deal with row numbers. I just create an extra column and fill down sequentially. Not sure if that works for you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文