Name Country
A EU
B US
C EU
D EU
我上面的表名为myset,我想在列中添加一列“国家代码”。国家/地区代码位于下面的代码集
的数据集中 Country Country Code
EU 001
US 002
我想要的输出是:
Name Country Country Code
A EU 001
B US 002
C EU 001
D EU 001
有人可以帮我写代码吗?
答案 0 :(得分:0)
搜索google以获取sql连接或数据合并。
首先:不要在列名中使用空格,这会让一切烦人:) 因此,将列重命名为country_code。
SET @count = (SELECT COUNT(IsPass) FROM Z);
SET @count1 = (SELECT COUNT(IsPass) FROM Z WHERE IsPass='true');
IF(@count = @count1)
THEN
SELECT SUM(Z.MaxMarks) AS MaxMarks, SUM(Z.MinMarks) AS MinMarks, SUM(Z.SecuredMarks) AS SecuredMarks, 'true' AS TempIsPass FROM Z
END
答案 1 :(得分:0)
PROC SQL
是这样做的有趣方式:
PROC SQL;
CREATE TABLE joined AS
SELECT coun.Name, coun.Country, cod.CountryCode
FROM Country coun
LEFT JOIN Codes cod
ON coun.Country = cod.Country;
QUIT;