将结果变量传递给Sqlite中的嵌套SELECT语句

时间:2013-09-19 12:00:22

标签: sqlite nested

我有以下查询有效:

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传递给嵌套语句?

1 个答案:

答案 0 :(得分:0)

我认为这就是你想要的:

SELECT SoftwareList, COUNT(SoftwareList) AS Count, GROUP_CONCAT(LastSeen) 
FROM assigned GROUP BY SoftwareList