group_concat不适用于count

时间:2017-10-14 16:55:13

标签: mysql count group-concat

我使用

input()

我需要的是取回像

这样的结果
SELECT 
GROUP_CONCAT(DISTINCT `a`.`IDperson` SEPARATOR ', ') AS `person`,
COUNT(`a`.`IDjobs`) AS `total`
FROM
`a`
GROUP BY `a`.`ID_person`
ORDER BY `total` DESC

但它不起作用 得到的回报就像GROUP_CONCT一样无法正常工作

person        total
 2342           98
 1342           75
 3844           70
 1705           62
 3309           53
 5918, 1328     52
 1503, 1890     46
21004, 6536     45

3 个答案:

答案 0 :(得分:0)

似乎你需要根据计数进行连续灌浆,所以你应该

 class saveclick implements Button.OnClickListener {
        public void onClick(View v) {
        gif.setImageBitmap(bitmap);
        imgTakenPic.setImageBitmap(bm);
        gif.buildDrawingCache();
       bitmap = gif.getDrawingCache();
        imgTakenPic.buildDrawingCache();
        bm=imgTakenPic.getDrawingCache();
        File outputFile = new File("/sdcard/ssjos.gif");
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream(outputFile);
        } catch (IOException e) {
            e.printStackTrace();
        }
          if (fos != null) {
            AnimatedGifEncoder gifEncoder = new AnimatedGifEncoder();
           gifEncoder.start(fos); 
           gifEncoder.addFrame(bitmap);
           gifEncoder.addFrame(bm);
           gifEncoder.finish();

        }
                }
                   }

答案 1 :(得分:0)

我推测你想要:

SELECT numjobs, GROUP_CONAT(idperson SEPARATOR ', ' ORDER BY idperson) as persons
FROM (SELECT idperson, COUNT(*) as numjobs
      FROM a
      GROUP BY idperson
     ) ap
GROUP BY numjobs
ORDER BY numjobs DESC;

答案 2 :(得分:0)

GROUP_CONCAT()完美无缺。由于您GROUP BY `a`.`ID_person`,每个组只包含一个`a`.`ID_person`值,因此您获得了结果。您可能想要`GROUP BY `a`.`IDjobs`

SELECT 
    GROUP_CONCAT(DISTINCT `a`.`IDperson` SEPARATOR ', ') AS `person`,
    COUNT(`a`.`IDjobs`) AS `total`
FROM
   `a`
GROUP BY `a`.`IDjobs`
ORDER BY `total` DESC