Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php数组的Postgres_Php_Postgresql - Fatal编程技术网

php数组的Postgres

php数组的Postgres,php,postgresql,Php,Postgresql,我有一个包含值的表: CREATE TABLE grade (id int, name varchar(2), no int); INSERT INTO grade (id, name, no) VALUES (1, 'A', 7), (2, 'B', 6), (3, 'C', 10), (4, 'D', 12), (5, 'E', 15), (6, 'F', 21), (8, 'B', 16), (7, 'F', 18), (9, 'F', 25); 我需要数组中的输出来使用。。i、 e:

我有一个包含值的表:

CREATE TABLE grade
(id int, name varchar(2), no int);

INSERT INTO grade
(id, name, no)
VALUES
(1, 'A', 7),
(2, 'B', 6),
(3, 'C', 10),
(4, 'D', 12),
(5, 'E', 15),
(6, 'F', 21),
(8, 'B', 16),
(7, 'F', 18),
(9, 'F', 25);
我需要数组中的输出来使用。。i、 e:

[
  ['range','A','B','F'],
  ['0.00 - 4.41', 1, 1, 0],
  ['4.41 - 8.24', 0 , 1, 1]
  ...
  ...
  ['others', 0, 0, 1]
]
这就是我想要的():


是否可以仅从db查询中获得所需的输出?或者我已经使用php迭代了?

找到了一种归档结果()的方法:


你从哪里得到的直方图桶大小?它们都是参差不齐的。我打算建议使用
width\u bucket
功能,但它仅适用于常规直方图。我使用elester滑块,用户可以在其中创建范围,并基于此范围创建堆叠条形图。我正在使用谷歌可视化工具。
    select range, array_agg(name) as name, array_agg(count) as count
    from (
        select case
          when no between 0.00 and 4.41 then '0.00 - 4.41'
            when no between 4.41 and 8.24 then '4.41 - 8.24'
            when no between 8.24 and 14.77 then '8.24 - 14.77' 
            when no between 14.77 and 19.35 then '14.77 - 19.35' 
            when no between 19.35 and 23.00 then '19.35 - 23.00'
        else 'Others' end as range, name,  count (*) as count
        from grade
        WHERE name IN ('A','B','F') 
        group by range, name
        order by name
    ) t
    group by range
    select range, sum(a) as a_name, 
                  sum(b) as b_name, 
                  sum(f) as f_name, 
                  sum(count) as total
    from (
        select case
          when no between 0.00 and 4.41 then '0.00 - 4.41'
            when no between 4.41 and 8.24 then '4.41 - 8.24'
            when no between 8.24 and 14.77 then '8.24 - 14.77' 
            when no between 14.77 and 19.35 then '14.77 - 19.35' 
            when no between 19.35 and 23.00 then '19.35 - 23.00'
        else 'Others' end as range, 
                count(name = 'A' OR NULL) as A,
                count(name = 'B' OR NULL) as B,
                count(name = 'F' OR NULL) as F,  
                count (*) as count
        from grade
        WHERE name IN ('A','B','F') 
        group by range, name
        order by name
    ) t
    group by range