选择在VBA统计查询(Access 2010中)VBA、Access

由网友(冰封天堂)分享简介:我有一个选择查询作为表单中的on_click事件的一部分。I have a select query as part of an on_click event within a form.varSQL2 = "SELECT DISTINCT(*), count(*) AS Count1" & _" FROM Inv...

我有一个选择查询作为表单中的on_click事件的一部分。

I have a select query as part of an on_click event within a form.

varSQL2 = "SELECT DISTINCT(*), count(*) AS Count1" & _
          " FROM Inventory WHERE Part_ID='" & rs!Part_ID & "';"

我想知道什么是正确的语法,此查询会。我想匹配的ID,然后多少也有计数的所有记录。这是语法正确吗?

I am wondering what the correct syntax for this query would be. I would like all records that match the ID and then a count of how many there are. Is this syntax correct?

有可能会发现,这是正确的语法,但是,我没有得到一个错误,也没有回应。

It may be found that this is the correct syntax, however, I am neither getting an error nor response.

任何人都可以提出一个更好的选择。我看到那里的子查询已使用的情况下,但我真的不明白这一点,我都习惯了。之间的差异

Can anyone suggest a better alternative. I have seen cases where a subquery has been used, but I don't really understand the difference between that and what I have used.

推荐答案

随着塞尔吉奥写道,你需要这样的子查询:

As Sergio wrote, you need a subquery like this:

SELECT Count(*) AS Count1
FROM (
    SELECT DISTINCT * 
    FROM Inventory 
    WHERE Part_ID = [ rs!Part_ID ] 
)
阅读全文

相关推荐

最新文章