无法根据多个条件选择唯一记录

时间:2014-05-12 09:51:49

标签: sql excel vba adodb

我有一张Excel格式report格式如下:

+----------+--------+-------------+
|   file   | column | columnIndex |
+----------+--------+-------------+
| abc.xlsx | test   |          14 |
| def.xlsx | test   |          55 |
| abc.xlsx | xyz    |          19 |
| def.xlsx | xyz    |          19 |
+----------+--------+-------------+

我尝试使用ADODB进行查询,以便在column不为空的情况下获取columnIndexcolumn值的唯一对。

我尝试了各种查询,但每个查询都给了我一个错误。

SELECT [report$].column,[report$].columnIndex 
from [report$] group by [report$].column,[report$].columnIndex 
having [report$].column<>''
ORDER BY columnIndex

给出了这个错误:

No value given for one or more required parameters.

此查询:

select [report$].column,[report$].columnIndex 
from [report$] group by [report$].column,[report$].columnIndex 
where [report$].column<>'' 
order by columnIndex 

给出了这个错误:

Syntax error (missing operator) in query expression '[report$].columnIndex where [report$].column<>'''.

此查询:

select distinct [report$].column,[report$].columnIndex 
from [report$] 
where [report$].column<>'' 
order by columnIndex 

给出了这个错误:

ORDER BY clause (columnIndex) conflicts with DISTINCT.

如何编写此查询以获取唯一值?

1 个答案:

答案 0 :(得分:2)

  • WHEREGROUP BY

  • 之前
  • <>相当于!=,因此您应该传递值以将[report$].column与。{/ p>

  • 进行比较。
  • No value given for one or more required parameters.的原因可能是拼写错误的字段名称。

例如:

WHERE [report$].column <> '' 
GROUP BY [report$].column,[report$].columnIndex 
ORDER BY [report$].columnIndex 
相关问题