我正在尝试在Access数据库中管理我的应用程序的依赖项,我可以使用SQL查询的帮助将每个组件的列表作为单个结果返回。
例如,假设我有以下三个表,其中包含未在此处显示的其他列:
CurrentBuild Versions Dependencies
============== ============== =======================================
Item Version Item Version Item Version Dependency DepVersion
------ ------- ------ ------- ------ ------- ---------- ----------
MyExe 1.3 MyExe 1.0 MyExe 1.0 N/A N/A
MyDll1 1.0 MyExe 1.1 MyExe 1.1 N/A N/A
MyDll2 1.0 MyExe 1.2 MyExe 1.2 N/A N/A
MyDll3 1.1 MyExe 1.3 MyExe 1.3 N/A N/A
MyExe 1.4 MyDll1 1.0 MyDll4 1.0
MyDll1 1.0 MyDll2 1.0 SomeMsDll 1.0
MyDll2 1.0 MyDll3 1.0 MyDll4 1.0
MyDll2 1.1 MyDll3 1.0 MyDll5 1.0
MyDll3 1.0 MyDll3 1.1 MyDll4 1.0
MyDll3 1.1 MyDll4 1.0 MyDll6 1.0
MyDll4 1.0 MyDll5 1.0 MyDll6 1.0
MyDll5 1.0 MyDll6 1.0 MyDll7 1.0
MyDll6 1.0 MyDll7 1.0 MyDll8 1.0
MyDll7 1.0
我可以使用什么查询从CurrentBuild表中获取以下结果?我更喜欢对VBA宏进行简单查询;但是,如果无法通过查询完成,我不反对VBA宏。
Item Version
----------- -------
MyExe 1.3
MyDll1 1.0
MyDll2 1.0
MyDll3 1.1
MyDll4 1.0
MyDll6 1.0
MyDll7 1.0
MyDll8 1.0
SomeMsDll 1.0
到目前为止,我有以下内容,但这并没有给我预期的结果;它只是让我回到CurrentBuild表的内容:
SELECT W.Item, W.Version
FROM (SELECT DISTINCT V.[Item], V.[Version]
FROM ([Versions] AS V
INNER JOIN [Dependencies] AS D ON V.[Item] = D.[Dependency] AND V.[Version] = D.[DepVersion])
INNER JOIN [CurrentBuild] AS S ON D.[Item] = S.[Item] AND D.[Version] = S.[Version]
UNION
SELECT DISTINCT V.[Item], V.[Item]
FROM [Versions] AS V
INNER JOIN [CurrentBuild] AS S ON V.[Item] = S.[Item] AND V.[Version] = S.[Version]) AS W;
如果你很好奇为什么MyExe没有对MyDlls的依赖,那么简单的答案就是不需要回答关于我的查询的问题;但是,仅供参考,DLL是动态加载的,因此MyExe对MyDlls没有构建时依赖。
感谢。
答案 0 :(得分:0)
将该sucker打包到UNION查询中,并获取每个项目的最大版本值:
SELECT Max(Item) as Item, Max(Version) as Version
FROM
(SELECT Item, Version
FROM CurrentBuild
UNION
SELECT Item, Version
FROM Versions
UNION
SELECT Item, Version
FROM Dependencies
UNION
SELECT Dependency as Item, DepVersion as Version
FROM Dependencies) AllItem
GROUP BY Item, Version