[postgresql]高分求一个sql
问题如下:
表A
CREATE TABLE student_new
(
pkey1 int4 NOT NULL,
pkey2 varchar(20) NOT NULL,
attend_year int4,
attend_grade int4,
attend_class text,
attend_no int4,
former_year int4,
former_grade int4,
former_class text,
former_no int4,
CONSTRAINT student_new_pkey PRIMARY KEY (pkey1, pkey2)
)
例: 表A1:pkey1 pkey2 attend_year attend_grade attend_class attend_no attend_year attend_grade attend_class attend_no
1 BMW 2008 3 班级3 3 2007 2 班级2 2
要求查询结果如下:
pkey1 pkey2 year grade class no
1 BMW 2008 3 班级3 3
1 BMW 2007 2 班级2 2
谢谢!