How to use alias column name in where clause in SQL Server

后端 未结 5 1821
时光说笑
时光说笑 2020-11-27 06:49

When I tried to perform the below code in SQL Server 2005 I am getting the error

Invalid column name DistanceFromAddress

Code:<

5条回答
  •  北海茫月
    2020-11-27 07:08

    select 
        t1.*,
        t2.brand_name,
        t3.category_name,
        if(
            t3.parent_category_id=0,
            t3.cat_key,
            (
                select 
                  concat(t3b.cat_key,'/',t3.cat_key) 
                from master_category t3b 
                where t3b.category_id=t3.parent_category_id 
            )
        ) as cat_key,
        (
            select min(t4.product_MSP) 
            from trans_products t4  
            where t1.product_id=t4.product_id 
        ) as product_MSP,
        (
            select min(t4.product_MRP) 
            from trans_products t4 
            where t1.product_id=t4.product_id 
        ) as product_MRP 
    from master_products t1,
    master_brand t2,
    master_category t3 
    where t1.status=1 
    and t2.status=1 
    and t2.brand_id=t1.brand_id 
    and t3.category_id=t1.category_id 
    and t3.display_status=1 
    and t1.category_id=6 
    and product_MSP between '1000' and '500000' 
    

提交回复
热议问题