Where method Alias fields

Where method Alias ​​fields


Usually we often this command at the next sql


SELECT od.* ,
CASE 
	WHEN od.UnitPrice> 20 THEN 3
	WHEN od.UnitPrice> 10 THEN 2
ELSE 1
END 'Level'
   FROM [Order Details] od 

The results displayed like this

image

But if this time we need another one at a time as long as the Level> 1 it?

In general it should be very intuitive to where you want to add filters become Level


SELECT od.* ,
CASE 
	WHEN od.UnitPrice> 20 THEN 3
	WHEN od.UnitPrice> 10 THEN 2
ELSE 1
END 'Level'
   FROM [Order Details] od 
WHERE Level > 2

The results will become Level can not find the data row

image

At this time no need to get the whole Case Select to filter

As long as the original results as objects to be queried to select doing just fine

like this


SELECT * FROM(
SELECT od.* ,
CASE 
	WHEN od.UnitPrice> 20 THEN 3
	WHEN od.UnitPrice> 10 THEN 2
ELSE 1
END 'Level'
   FROM [Order Details] od 
) t
WHERE Level > 2

Original: Big Box  Where method Alias field


Guess you like

Origin www.cnblogs.com/chinatrump/p/11490829.html