如何在不输入长全名的情况下选择 p.Quota?现在我正在做
SELECT c.id,
c.UserName,
p.Quota,
cs.StatusName
FROM CUSTOMERS AS c,
PRODUCTS AS p
LEFT JOIN CUSTOMERSTATUSTYPES as cs ON c.StatusId=cs.CustomerStatusId
LIMIT 1 ;
我得到错误:
ERROR 1054 (42S22): Unknown column 'c.StatusId' in 'on clause'
但是该列确实退出并且此代码有效:
SELECT c.id,
c.UserName,
cs.StatusName
FROM CUSTOMERS AS c
JOIN CUSTOMERSTATUSTYPES as cs ON c.StatusId = cs.CustomerStatusId
LIMIT 1 ;
最佳答案
您正在混合使用 ANSI 和非 ANSI JOIN 语法:
SELECT c.id,
c.UserName,
p.Quota,
cs.StatusName
FROM CUSTOMERS AS c,
PRODUCTS AS p
LEFT JOIN CUSTOMERSTATUSTYPES as cs ON c.StatusId=cs.CustomerStatusId
LIMIT 1 ;
使用 ANSI 连接编写:
SELECT c.id,
c.UserName,
p.Quota,
cs.StatusName
FROM CUSTOMERS AS c
JOIN PRODUCTS AS p ON --JOIN criteria goes here
LEFT JOIN CUSTOMERSTATUSTYPES as cs ON c.StatusId = cs.CustomerStatusId
LIMIT 1;
...但我不知道您使用什么标准将 PRODUCTS
加入 CUSTOMERS
表。
关于mysql - 从 2 个表中选择。 MySql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1478080/