这是我的要求,值插入到表中。
CREATE TABLE provendor (
prcode varchar (10),
prvendor varchar (5),
prpricing decimal (9,2)
);
INSERT INTO provendor(prcode, prvendor, prpricing)
VALUES
('PW-1001', 'P10', '500.00'),
('PQ-4570', 'P88', '35.00'),
('MM-120E', 'P67', '245.00'),
('MM-F12WR', 'P10', '1210.00'),
('PW-QZR-09', 'P10', '79.00'),
('PQ-4570', 'P10', '32.50'),
('MM-120E', 'P88', '242.00'),
('PW-1001', 'P45', '550.00'),
('MM-F12WR', 'P73', '1200.00'),
('PQ-4570', 'P67', '33.00'),
('MM-F12WR', 'P35', '1189.00'),
('PW-1001', 'P23', '510.00'),
('PQ-4570', 'P35', '36.00'),
('MM-120E', 'P23', '250.00');
我需要执行查询以检索由多家供应商提供的product code
的{{1}},pricing
和vendor code
,并且您的记录必须按产品分类代码。
这是我用于自我加入的填充
product
运行它时,错误将表明SELECT A.prvendor AS provendor1, B.prvendor AS provendor2, A.prcode
FROM provendor A, provendor B
WHERE prvendor1 > A.prcode
ORDER BY A.prcode;
的值不明确。我不知道怎么解决
答案 0 :(得分:0)
您不能在where子句中使用表别名
SELECT A.prvendor AS provendor1, B.prvendor AS provendor2, A.prcode
FROM provendor A, provendor B
WHERE A.prvendor > A.prcode
ORDER BY A.prcode;
但是,您应该使用ANSI连接语法,以便更清楚地理解,这通常被视为最佳实践:
SELECT A.prvendor AS provendor1,
B.prvendor AS provendor2,
A.prcode
FROM provendor A
JOIN provendor B
ON A.prvendor > A.prcode
ORDER BY A.prcode;