一个查询语句:
select l.commodityCode,substring(commodityName, 3),r.price/100 price from storetotal s,NetBarStore b ,Commodity l,RetailPrice r where and l.commodityCode =r.commodityCode and s.remainQuantity > 0 and r.price is not null and b.storeId=s.storeId and b.storeName like '2号%' group by l.commodityCode,l.commodityName order by commodityName不使用别名系统提示错误[本地] ERROR 1052: Column: 'commodityCode' in field list is ambiguous
commodityCode,commodityName,price,storetotal,NetBarStore,Commodity,RetailPrice都是表名
这些表有些字段相同。
但是用到了别名就正常,有谁知道别名的写法和用法吗
l.commodityCode是用到别名了?storetotal s是不是定义了storetotal的别名为S呢?RetailPrice r定义RetailPrice 的别名为r,s.commodityCode=l.commodityCode则代表了storetotal.commodityCode=Commodity.commodityCode,这样理解是否对呢?
select l.commodityCode,substring(commodityName, 3),r.price/100 price from storetotal s,NetBarStore b ,Commodity l,RetailPrice r where and l.commodityCode =r.commodityCode and s.remainQuantity > 0 and r.price is not null and b.storeId=s.storeId and b.storeName like '2号%' group by l.commodityCode,l.commodityName order by commodityName不使用别名系统提示错误[本地] ERROR 1052: Column: 'commodityCode' in field list is ambiguous
commodityCode,commodityName,price,storetotal,NetBarStore,Commodity,RetailPrice都是表名
这些表有些字段相同。
但是用到了别名就正常,有谁知道别名的写法和用法吗
l.commodityCode是用到别名了?storetotal s是不是定义了storetotal的别名为S呢?RetailPrice r定义RetailPrice 的别名为r,s.commodityCode=l.commodityCode则代表了storetotal.commodityCode=Commodity.commodityCode,这样理解是否对呢?
storetotal s是定义了storetotal的别名为S
s.commodityCode=l.commodityCode则代表了storetotal.commodityCode=Commodity.commodityCode,这样理解是对的