Some operations of SQL statements

 

1. Convert the data, sometimes it is necessary to convert the integer type to the floating point type.

 1) Use the decimal point directly:

    

select 10*1.0 / 3

  2) Use CAST for conversion (this is a little troublesome):

select   cast(cast(10 as float)/3 as decimal(10,2)) as print

  

2. Query the results according to different conditions in the same SQL sentence:

 1) Use CASE WHEN:

    

SELECT
	count(CASE WHEN cyqkbm ='2' THEN 1 ELSE NULL END)  / count(*)

 

     

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326400694&siteId=291194637