Oracle rows and columns convert column names if they are numbers, enclose the following in double quotation marks:
--Build a table
CREATE TABLE Workinfo
(
WID Integer PRIMARY key,
Sid Integer,
CONSTRAINT SID foreign Key (SID) references student (SID),
City Nvarchar2 (,--) Employment cities
Wage number (10,2),--monthly Salary
Workdate Date,--Employment time
Eid Integer,
CONSTRAINT Eid foreign Key (Eid) references Emp (Eid)--introducer
);
--False data
INSERT into workinfo values (1001,8001, ' Shanghai ', 5000,to_date (' 2009-3-5 ', ' yyyy-mm-dd '), 6005);
INSERT into workinfo values (1002,8002, ' Shanghai ', 4500,to_date (' 2010-3-5 ', ' yyyy-mm-dd '), 6005);
INSERT into workinfo values (1003,8005, ' Shanghai ', 5500,to_date (' 2009-3-5 ', ' yyyy-mm-dd '), 6005);
INSERT into workinfo values (1004,8003, ' Hangzhou ', 4000,to_date (' 2009-12-5 ', ' yyyy-mm-dd '), 6006);
INSERT into workinfo values (1005,8004, ' Hangzhou ', 4500,to_date (' 2007-12-5 ', ' yyyy-mm-dd '), 6006);
INSERT into workinfo values (1006,8006, ' Nanjing ', 4000,to_date (' 2009-12-5 ', ' yyyy-mm-dd '), 6006);
INSERT into workinfo values (1007,8008, ' Hangzhou ', 4000,to_date (' 2009-12-5 ', ' yyyy-mm-dd '), 6006);
INSERT into workinfo values (1008,8010, ' Shanghai ', 4000,to_date (' 2007-12-5 ', ' yyyy-mm-dd '), 6007);
INSERT into workinfo values (1009,8007, ' Hangzhou ', 4400,to_date (' 2008-12-5 ', ' yyyy-mm-dd '), 6007);
INSERT into workinfo values (1010,8009, ' Hangzhou ', 4000,to_date (' 2009-12-5 ', ' yyyy-mm-dd '), 6007);
-Statistics on the number of jobs per year in each region are shown below
Select A.city,
SUM (case is a.years= ' then a.rs else 0 end) "2007",
SUM (case is a.years= ' then a.rs else 0 end) "2008",
SUM (case if a.years= ' then a.rs else 0 end) "2008",
SUM (case is a.years= ' then a.rs else 0 end) "2009"
From
(
Select City,to_char (workdate, ' yyyy ') years,count (SID) RS
From Workinfo
Group BY City,to_char (workdate, ' yyyy ')
) A
GROUP BY A.city
Results
Oracle rows and columns convert column name numbers