SQL文优化
select PROD_ID,
PROD_NAME,
DEPT_ID,
SAL_PRICE,
STOCK_AMOUNTS,
MINI_PO,
SPECIFICATION,
case '6942836701321'
when PROD_BARCODE1 then
PKG_SIZE1
when PROD_BARCODE2 then
PKG_SIZE2
when PROD_BARCODE3 then
PKG_SIZE3
when PROD_BARCODE4 then
PKG_SIZE4
when PROD_BARCODE5 then
PKG_SIZE5
when PROD_BARCODE6 then
PKG_SIZE6
end as PKG_SIZEE
from ST_Product_Master
where '6942836701321' in(PROD_BARCODE1,PROD_BARCODE2,PROD_BARCODE3,PROD_BARCODE4,PROD_BARCODE5,PROD_BARCODE6)
帮忙看看这段sql怎么能优化下,提高SQL的运行速度?
------解决方案-------------------- where '6942836701321' in(PROD_BARCODE1,PROD_BARCODE2,PROD_BARCODE3,PROD_BARCODE4,PROD_BARCODE5,PROD_BARCODE6)
'6942836701321' 这个是列名?????
------解决方案--------------------改成这样试试:
select PROD_ID,
PROD_NAME,
DEPT_ID,
SAL_PRICE,
STOCK_AMOUNTS,
MINI_PO,
SPECIFICATION,
case '6942836701321'
when PROD_BARCODE1 then
PKG_SIZE1
when PROD_BARCODE2 then
PKG_SIZE2
when PROD_BARCODE3 then
PKG_SIZE3
when PROD_BARCODE4 then
PKG_SIZE4
when PROD_BARCODE5 then
PKG_SIZE5
when PROD_BARCODE6 then
PKG_SIZE6
end as PKG_SIZEE
from ST_Product_Master
where PROD_BARCODE1 = '6942836701321' or
PROD_BARCODE2 = '6942836701321' or
PROD_BARCODE3 = '6