现有一语句如下:
select b.mar_en_name, a.rd_name, a.shipto_code, a.inventory, a.twomonthtotalcost,
round(((inventory/twomonthtotalcost)*61) , 1) as InventoryDays, smmonth
from gl_distributor a, gl_market b
where a.mar_code=b.mar_code and twomonthtotalcost<>0 and
twomonthtotalcost is not null and hub_type_id=1 and smmonth='200609' and inventorydays>100 order by inventorydays
但是执行时显示"INVENTORYDAYS 无效的标识符", 去掉最后一个条件就没有问题, 看来在where语句中无法使用字段别名, 有什么解决办法吗?
另外,我不想通过子查询来解决这个问题!
------解决方法--------------------------------------------------------
select b.mar_en_name, a.rd_name, a.shipto_code, a.inventory, a.twomonthtotalcost,
round(((inventory/twomonthtotalcost)*61) , 1) as InventoryDays, smmonth
from gl_distributor a, gl_market b
where a.mar_code=b.mar_code and twomonthtotalcost<>0 and
twomonthtotalcost is not null and hub_type_id=1 and smmonth='200609' order by inventorydays having inventorydays>100
------解决方法--------------------------------------------------------
同一个sql不可以马上使用别名。
不可以这样,
select a.x m
from tab
where m < 0
------解决方法--------------------------------------------------------
没有什么好的办法,用子查询不是很好的么,还可以用临时表啊。
------解决方法--------------------------------------------------------
select b.mar_en_name, a.rd_name, a.shipto_code, a.inventory, a.twomonthtotalcost,
round(((inventory/twomonthtotalcost)*61) , 1) as InventoryDays, smmonth
from gl_distributor a, gl_market b
where a.mar_code=b.mar_code and twomonthtotalcost<>0 and
twomonthtotalcost is not null and hub_type_id=1 and smmonth='200609' and inventorydays>100
order by round(((inventory/twomonthtotalcost)*61) , 1)