今天在群里看到一朋友提问
问题是截图,截图如下
CREATE TABLE sales ( year integer,-- 年 month integer,-- 月 counts integer -- 日 ) WITH ( OIDS=FALSE ); ALTER TABLE sales OWNER TO postgres; COMMENT ON TABLE sales IS '销售报表'; COMMENT ON COLUMN sales.year IS '年'; COMMENT ON COLUMN sales.month IS '月'; COMMENT ON COLUMN sales.counts IS '日'; insert into sales values(1991,1,11),(1991,2,12),3,13),4,14),(1992,21),22),23),24); CREATE EXTENSION tablefunc; select * from sales; SELECT * FROM crosstab('select year,month,counts from sales order by 1','select distinct month from sales order by 1') AS t ("年" integer,"一月" integer,"二月" integer,"三月" integer,"四月" integer);
另外需要注意下crosstab这个EXTENSION需要create才可以用。
结果如下截图
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。