1

我有以下有效的查询:

SELECT
    SoftwareList,
    Count (SoftwareList) as Count
FROM [assigned]
GROUP BY SoftwareList

这将返回以下结果集:

*SoftwareList*  | *Count*
--------------------------
Office XP       | 3
Adobe Reader    | 3
Dreamewaver     | 2

我还可以运行以下查询:

SELECT
    GROUP_CONCAT(LastSeen) as LastSeen
FROM [assigned]
WHERE SoftwareList = 'Dreamweaver';

这将返回以下结果集:

*LastSeen*
----------
2007-9-23,2012-3-12

我希望将这两个查询合并为一个,以便返回以下结果:

*SoftwareList* | *Count* | *LastSeen*
--------------------------------------------------------
Office XP      | 3       | 2001-2-12,2008-3-19,2002-2-17
Adobe Reader   | 3       | 2008-2-12,2009-3-20,2007-3-16
Dreamewaver    | 2       | 2007-9-23,2012-3-12

我正在尝试这个,但不知道如何SoftwareList在嵌套语句中引用初始变量:

SELECT
    SoftwareList,
    Count (SoftwareList) as Count,
    (SELECT
        GROUP_CONCAT(LastSeen) FROM [assigned]
        WHERE SoftwareList = SoftwareList
    ) as LastSeen
FROM [assigned]
GROUP BY SoftwareList;

如何将SoftwareList每行返回的内容传递给嵌套语句?

4

1 回答 1

0

我认为这就是你想要的:

SELECT SoftwareList, COUNT(SoftwareList) AS Count, GROUP_CONCAT(LastSeen) 
FROM assigned GROUP BY SoftwareList
于 2013-09-19T12:09:41.860 回答