当前位置:网站首页>Database logic processing function

Database logic processing function

2022-07-05 19:51:00 My talented girlfriend

function

Numerical function

  • abs(x) The absolute value
  • ceil(x) Greater than or equal to x Minimum integer of
  • floor(x) Less than or equal to x Maximum integer for
  • mod(x,y) x Divide y The remainder of
  • round(x,n) take x Round to n Decimal place
  • rand() Returns a random number

 Insert picture description here

Character functions

  • char_length(s) Character length
  • concat(a,b) Character connection
  • instr(s,s1) Returns the first occurrence of a character , Case insensitive
  • lower(a) / upper(b) Case conversion
  • octet_length(s) The length of the returned character bytes ,utf-8 Character occupation 3 Characters
  • substring(s,n,m) Intercept characters from n At the beginning m Letters , The position is calculated from 1 Start
  • trim(s1 from s) Delete the beginning and end characters , Default is space

 Insert picture description here

Date function

  • current_date The current date
  • current_time current time
  • current_timestamp Current time and date
  • extract(p from date) Extract information from dates
  • datediff(d1, d2) Calculate the number of days between dates
  • d1 + interval Date plus time interval

select date ‘2011-11-12’ + interval ‘-1’ month t_goodss

 Insert picture description here

Conversion function

  • cast

Alias

Both column names and table names use keywords AS

Conditional expression

case

case expression
 when value1 then result1
 when value2 then result2
 else --
 end
case 
 when conditon1 then result1
 when conditon2 then result2
 else --
 end

if

if and java The trinocular expression in is similar

select if(1<2, '1<2','1>=2') as result;

 Insert picture description here

原网站

版权声明
本文为[My talented girlfriend]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/186/202207051844063276.html