选择在VBA统计查询(Access 2010中) [英] Select and count Query in VBA (Access 2010)
问题描述
我有一个选择查询作为表单中的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 ]
)
这篇关于选择在VBA统计查询(Access 2010中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!