韦德国际_韦德国际1946官方网站_韦德国际1946手机版
做最好的网站

mysql操作查询结果case,oracle时间操作比方

日期:2019-06-25编辑作者:韦德国际1946手机版

mysql oracle时间操作譬如

举例1:

mysql日期时间操作,mysql日期操作

select curdate();                       --获取当前日期
select last_day(curdate());                    --获取当月最后一天。
select DATE_ADD(curdate(),interval -day(curdate()) 1 day);   --获取本月第一天
select date_add(curdate()-day(curdate()) 1,interval 1 month); -- 获取下个月的第一天
select DATEDIFF(date_add(curdate()-day(curdate()) 1,interval 1 month ),DATE_ADD(curdate(),interval -day(curdate()) 1 day)) from dual; --获取当前月的天数

---获取招募倒计时时间

select time from app_web_setting_timecontrol where time>=now()
and time<date_add(curdate()-day(curdate()) 1,interval 1 month)
order by time asc limit 1;

 

#clients
[client]
#password    = your_password
port        = 3306
socket        = /var/run/mysql/mysql.sock
#default-character-set=utf8

 

动用该查询,得出iFavoriteID,iFavUserType ,cUser,iArticleID,dFavoriteTime八个字段的值:

MySQL日期时间函数大全

DAYOFWEEK(date) 
 重临日期date是星期几(1=周天,2=星期日,……7=周六,ODBC标准)
mysql> select DAYOFWEEK('1998-02-03'); 
  -> 3 
WEEKDAY(date) 
 再次来到日期date是星期几(0=星期日,1=星期天,……6= 星期一)。 
mysql> select WEEKDAY('1997-10-04 22:23:00'); 
  -> 5 
mysql> select WEEKDAY('1997-11-05'); 
  -> 2 
DAYOFMONTH(date) 
 重回date是初月底的第几日(在1到31范围内) 
mysql> select DAYOFMONTH('1998-02-03'); 
  -> 3 
DAYOFYEAR(date) 
 重返date是一年中的第几日(在1到366范围内) 
mysql> select DAYOFYEAR('1998-02-03'); 
  -> 34 
MONTH(date) 
 重回date中的月份数值 
mysql> select MONTH('1998-02-03'); 
  -> 2 
DAYNAME(date) 
 再次回到date是星期几(按英文名重返)
mysql> select DAYNAME("1998-02-05"); 
  -> 'Thursday' 
MONTHNAME(date) 
 再次回到date是几月(按英文名再次来到)
mysql> select MONTHNAME("1998-02-05"); 
  -> 'February' 
QUARTER(date) 
 重临date是一年的第多少个季度 
mysql> select QUARTER('98-04-01'); 
  -> 2 
WEEK(date,first)
 再次回到date是一年的第几周(first暗中同意值0,first取值1代表周二是周的起来,0从周日始于)
mysql> select WEEK('1998-02-20'); 
  -> 7 
mysql> select WEEK('1998-02-20',0); 
  -> 7 
mysql> select WEEK('1998-02-20',1); 
  -> 8 
YEAR(date) 
 返回date的年份(范围在1000到9999) 
mysql> select YEAR('98-02-03'); 
  -> 1998 
HOUR(time) 
 再次来到time的小时数(范围是0到23)
mysql> select HOUR('10:05:03'); 
  -> 10 
MINUTE(time) 
 重返time的分钟数(范围是0到59) 
mysql> select MINUTE('98-02-03 10:05:03'); 
  -> 5 
SECOND(time) 
 返回time的秒数(范围是0到59)
mysql> select SECOND('10:05:03'); 
  -> 3 
PERIOD_ADD(P,N) 
 扩大N个月到时期P并再次来到(P的格式YYMM或YYYYMM) 
mysql> select PERIOD_ADD(9801,2); 
  -> 199803 
PERIOD_DIFF(P1,P2) 
 重回在一代P1和P2之间月数(P1和P2的格式YYMM或YYYYMM)
mysql> select PERIOD_DIFF(9802,199703); 
  -> 11 
DATE_ADD(date,INTERVAL expr type)
DATE_SUB(date,INTERVAL expr type) 
ADDDATE(date,INTERVAL expr type) 
SUBDATE(date,INTERVAL expr type)
 对日期时间张开加减法运算
 (ADDDATE()和SUBDATE()是DATE_ADD()和DATE_SUB()的同义词,也得以用运算符 和-而不是函数
 date是一个DATETIME或DATE值,expr对date实行加减法的贰个表明式字符串type指明表明式expr应该怎样被分解
 [type值 含义 期望的expr格式]:
 SECOND 秒 SECONDS 
 MINUTE 分钟 MINUTES 
 HOUR 时间 HOURS 
 DAY 天 DAYS 
 MONTH 月 MONTHS 
 YEAR 年 YEARS 
 MINUTE_SECOND 分钟和秒 "MINUTES:SECONDS" 
 HOUR_MINUTE 小时和分钟 "HOUSportageS:MINUTES" 
 DAY_HOU君越 天和时辰 "DAYS HOU宝马X3S" 
 YEAR_MONTH 年和月 "YEARS-MONTHS" 
 HOUR_mysql操作查询结果case,oracle时间操作比方。SECOND 小时, 分钟, "HOURS:MINUTES:SECONDS" 
 DAY_MINUTE 天, 小时, 分钟 "DAYS HOURS:MINUTES" 
 DAY_SECOND 天, 小时, 分钟, 秒 "DAYS HOURS:MINUTES:SECONDS"
 expr中允许别的标点做分隔符,假若具有是DATE值时结果是三个DATE值,不然结果是二个DATETIME值)
 假使type关键词不完全,则MySQL从右端取值,DAY_SECOND因为远远不够时辰分钟等于MINUTE_SECOND)
 借使增添MONTH、YEA瑞虎_MONTH或YEA陆风X8,天数大于结果月份的最大天数则使用最小运气) 
mysql> SELECT "1997-12-31 23:59:59" INTERVAL 1 SECOND; 
  -> 1998-01-01 00:00:00 
mysql> SELECT INTERVAL 1 DAY "1997-12-31"; 
  -> 1998-01-01 
mysql> SELECT "1998-01-01" - INTERVAL 1 SECOND; 
  -> 1997-12-31 23:59:59 
mysql> SELECT DATE_ADD("1997-12-31 23:59:59",INTERVAL 1 SECOND); 
  -> 1998-01-01 00:00:00 
mysql> SELECT DATE_韦德国际1946手机版,ADD("1997-12-31 23:59:59",INTERVAL 1 DAY); 
  -> 1998-01-01 23:59:59 
mysql> SELECT DATE_ADD("1997-12-31 23:59:59",INTERVAL "1:1" MINUTE_SECOND); 
  -> 1998-01-01 00:01:00 
mysql> SELECT DATE_SUB("1998-01-01 00:00:00",INTERVAL "1 1:1:1" DAY_SECOND); 
  -> 1997-12-30 22:58:59 
mysql> SELECT DATE_ADD("1998-01-01 00:00:00", INTERVAL "-1 10" DAY_HOUR);
  -> 1997-12-30 14:00:00 
mysql> SELECT DATE_SUB("1998-01-02", INTERVAL 31 DAY); 
  -> 1997-12-02 
mysql> SELECT EXTRACT(YEAR FROM "1999-07-02"); 
  -> 1999 
mysql> SELECT EXTRACT(YEAR_MONTH FROM "1999-07-02 01:02:03"); 
  -> 199907 
mysql> SELECT EXTRACT(DAY_MINUTE FROM "1999-07-02 01:02:03"); 
  -> 20102 
TO_DAYS(date) 
 重临日期date是西元0年现今多少天(不划算1582年以前)
mysql> select TO_DAYS(950501); 
  -> 728779 
mysql> select TO_DAYS('1997-10-07'); 
  -> 729669 
FROM_DAYS(N) 
 给出西元0年到现在多少天重临DATE值(不划算1582年在此以前)
mysql> select FROM_DAYS(729669); 
  -> '1997-10-07' 
DATE_FORMAT(date,format) 
 遵照format字符串格式化date值
 (在format字符串中可用标识符:
 %M 月名字(January……December) 
 %W 星期名字(Sunday……Saturday) 
 %D 有葡萄牙语前缀的月份的日子(1st, 2nd, 3rd, 等等。) 
 %Y 年, 数字, 4 位 
 %y 年, 数字, 2 位 
 %a 缩写的星期名字(Sun……Sat) 
 %d 月份中的天数, 数字(00……31) 
 %e 月份中的天数, 数字(0……31) 
 %m 月, 数字(01……12) 
 %c 月, 数字(1……12) 
 %b 缩写的月度名字(Jan……Dec) 
 %j 一年中的天数(001……366) 
 %H 小时(00……23) 
 %k 小时(0……23) 
 %h 小时(01……12) 
 %I 小时(01……12) 
 %l 小时(1……12) 
 %i 分钟, 数字(00……59) 
 %r 时间,12 小时(hh:mm:ss [AP]M) 
 %T 时间,24 小时(hh:mm:ss) 
 %S 秒(00……59) 
 %s 秒(00……59) 
 %p AM或PM 
 %w 三个星期中的天数(0=Sunday ……6=Saturday ) 
 %U 星期(0……52), 这里周六是星期的第一天 
 %u 星期(0……52), 这里周二是星期的首后天 
 %% 字符% )
mysql> select DATE_FORMAT('1997-10-04 22:23:00','%W %M %Y'); 
  -> 'Saturday October 1997' 
mysql> select DATE_FORMAT('1997-10-04 22:23:00','%H:%i:%s'); 
  -> '22:23:00' 
mysql> select DATE_FORMAT('1997-10-04 22:23:00','%D %y %a %d %m %b %j'); 
  -> '4th 97 Sat 04 10 Oct 277' 
mysql> select DATE_FORMAT('1997-10-04 22:23:00','%H %k %I %r %T %S %w'); 
  -> '22 22 10 10:23:00 PM 22:23:00 00 6' 
TIME_FORMAT(time,format)
 和DATE_FORMAT()类似,但TIME_FORMAT只管理小时、分钟和秒(其他符号发生二个NULL值或0)
CURDATE() 
CURRENT_DATE()
 以'YYYY-MM-DD'或YYYYMMDD格式重回领后天期值(依据重返值所处上下文是字符串或数字) 
mysql> select CURDATE(); 
  -> '1997-12-15' 
mysql> select CURDATE() 0; 
  -> 19971215 
CURTIME() 
CURRENT_TIME()
 以'HH:MM:SS'或HHMMSS格式再次来到当前光阴值(依据再次回到值所处上下文是字符串或数字) 
mysql> select CURTIME(); 
  -> '23:50:26' 
mysql> select CURTIME() 0; 
  -> 235026 
NOW() 
SYSDATE() 
CURRENT_TIMESTAMP()
 以'YYYY-MM-DD HH:MM:SS'或YYYYMMDDHHMMSS格式重回当前几日期时间(依据重回值所处上下文是字符串或数字) 
mysql> select NOW(); 
  -> '1997-12-15 23:50:26' 
mysql> select NOW() 0; 
  -> 19971215235026 
UNIX_TIMESTAMP() 
UNIX_TIMESTAMP(date) 
 重返三个Unix时间戳(从'一九六七-01-01 00:00:00'阿奇霉素T起始的秒数,date默许值为当前时光)
mysql> select UNIX_TIMESTAMP(); 
  -> 882226357 
mysql> select UNIX_TIMESTAMP('1997-10-04 22:23:00'); 
  -> 875996580 
FROM_UNIXTIME(unix_timestamp) 
 以'YYYY-MM-DD HH:MM:SS'或YYYYMMDDHHMMSS格式再次来到时间戳的值(依据再次来到值所处上下文是字符串或数字) 
mysql> select FROM_UNIXTIME(875996580); 
  -> '1997-10-04 22:23:00' 
mysql> select FROM_UNIXTIME(875996580) 0; 
  -> 19971004222300 
FROM_UNIXTIME(unix_timestamp,format) 
 以format字符串格式重回时间戳的值
mysql> select FROM_UNIXTIME(UNIX_TIMESTAMP(),'%Y %D %M %h:%i:%s %x'); 
  -> '1997 23rd December 03:43:30 x' 
SEC_TO_TIME(seconds) 
 以'HH:MM:SS'或HHMMSS格式重返秒数转成的TIME值(依据再次回到值所处上下文是字符串或数字) 
mysql> select SEC_TO_TIME(2378); 
  -> '00:39:38' 
mysql> select SEC_TO_TIME(2378) 0; 
  -> 3938 
TIME_TO_SEC(time) 
 再次回到time值有稍许秒 
mysql> select TIME_TO_SEC('22:23:00'); 
  -> 80580 
mysql> select TIME_TO_SEC('00:39:38'); 
  -> 2378

select curdate (); --获取当前几天期 select last_day ( curdate ()); --获取前些时间最后一天。 select DATE_ADD ( curdate (), inter...

# Here follows entries for some specific programs

mysql oracle 时间操作比方 

SELECT iFavoriteID,
CASE WHEN iFavUserType = 0 THEN '消息管理员'
WHEN iFavUserType = 1 THEN '商家'
WHEN iFavUserType = 2 THEN '会员'
END AS iFavUserType, cUser, iArticleID,CONVERT(nvarchar(100), dFavoriteTime, 111) AS dFavoriteTime

# The MySQL server
[mysqld]
max_connections=500
default-character-set=utf8
#skip-character-set-client-handshake
port        = 3306
socket        = /var/run/mysql/mysql.sock
skip-locking
key_buffer = 16M
max_allowed_packet = 20M
table_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
log-slow-queries=/var/log/slowquery.log
long_query_time=1
wait_timeout = 120
max_connections = 200
max_user_connections = 100

select alarmid,alarmtype,dttimestamp from hdralarmbase20130320  where dttimestamp >  to_date('2013-3-20 10:12:28','yyyy-mm-dd hh24:mi:ss') 

FROM dig_favorite;

# Don’t listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (via the “enable-named-pipe” option) will render mysqld useless!
#
#skip-networking

 

 

# Replication Master Server (default)
# binary logging is required for replication
log-bin
expire_logs_days=7
log-error
binlog-ignore-db=mysql
binlog-ignore-db=test

mysql类似用法 

举例2:

# required unique id between 1 and 2^32 – 1
# defaults to 1 if master-host is not set
# but will not function as a master if omitted
server-id    = 1

 

SELECT a.UNIT,a.NUM_PRICE,a.WEIGHT_PRICE,(case WHEN a.UNIT='1' then a.NUM_PRICE else a.WEIGHT_PRICE end) price
from i_gift_inventory a;

# Replication Slave (comment out master section to use this)
#
# To configure this host as a replication slave, you can choose between
# two methods :
#

SELECT alarmid,alarmtype,dttimestamp FROM hdralarmbase20130129 WHERE dttimestamp < STR_TO_DATE('2013-01-29 13:33:19','%Y-%m-%d %T') 

举例3:

# 1) Use the CHANGE MASTER TO command (fully described in our manual)

#    the syntax is:
#
#    CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>,
#    MASTER_USER=<user>, MASTER_PASSWORD=<password> ;
#
#    where you replace <host>, <user>, <password> by quoted strings and
#    <port> by the master’s port number (3306 by default).
#
#    Example:
#
#    CHANGE MASTER TO MASTER_HOST=’125.564.12.1′, MASTER_PORT=3306,
#    MASTER_USER=’joe’, MASTER_PASSWORD=’secret’;
#
# OR
#
# 2) Set the variables below. However, in case you choose this method, then
#    start replication for the first time (even unsuccessfully, for example
#    if you mistyped the password in master-password and the slave fails to
#    connect), the slave will create a master.info file, and any later
#    change in this file to the variables’ values below will be ignored and
#    overridden by the content of the master.info file, unless you shutdown
#    the slave server, delete master.info and restart the slaver server.
#    For that reason, you may want to leave the lines below untouched
#    (commented) and instead use CHANGE MASTER TO (see above)
#
# required unique id between 2 and 2^32 – 1
# (and different from the master)
# defaults to 2 if master-host is set
# but will not function as a slave if omitted
#server-id       = 2
#
# The replication master for this slave – required
#master-host     =   <hostname>
#
# The username the slave will use for authentication when connecting
# to the master – required
#master-user     =   <username>
#
# The password the slave will authenticate with when connecting to
# the master – required
#master-password =   <password>
#
# The port the master is listening on.
# optional – defaults to 3306
#master-port     =  <port>
#
# binary logging – not required for slaves, but recommended
#log-bin

# Point the following paths to different dedicated disks
#tmpdir        = /tmp/
#log-update     = /path-to-dedicated-directory/hostname

# Uncomment the following if you are using BDB tables
#bdb_cache_size = 4M
#bdb_max_lock = 10000

# Uncomment the following if you are using InnoDB tables
#innodb_data_home_dir = /var/lib/mysql/
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = /var/lib/mysql/
#innodb_log_arch_dir = /var/lib/mysql/
# You can set .._buffer_pool_size up to 50 – 80 %
# of RAM but beware of setting memory usage too high
#innodb_buffer_pool_size = 16M
#innodb_additional_mem_pool_size = 2M
# Set .._log_file_size to 25 % of buffer pool size
#innodb_log_file_size = 5M
#innodb_log_buffer_size = 8M
#innodb_flush_log_at_trx_commit = 1
#innodb_lock_wait_timeout = 50

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates

[isamchk]
key_buffer = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M

[myisamchk]
key_buffer = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

 

select name,birthday,
 case 
     when birthday>'1983' then 'yong'
        when name='lee' then 'handsome'
        else 'just so so ' end
from lee;

date_format(date,'%Y-%m-%d')    -------------->oracle中的to_char(); 

 

本文由韦德国际发布于韦德国际1946手机版,转载请注明出处:mysql操作查询结果case,oracle时间操作比方

关键词: 数据库

Mysql创建用户与授权,Mysql创造新用户方法

1.CREATE USER CREATE USER user [IDENTIFIED BY [PASSWORD] 'password']     [, user [IDENTIFIED BY [PASSWORD] 'password']] ... CREATE USE奥迪Q3用于创...

详细>>

韦德国际1946手机版:mysql访问数据库的步子详解

php访问mysql数据库的步调,phpmysql数据库 官方说五.5从头就吐弃mysql_韦德国际1946手机版:mysql访问数据库的步子详解,...

详细>>

听他们说经纬度算最中距离的厂家,依据经纬度

基于经纬度算近日相差的店堂,经纬度算距离商铺 听他们说经纬度算最中距离的厂家,依据经纬度算距离。当下出于...

详细>>

【韦德国际1946手机版】MySQL数据库基本操作,M

MySQL学习笔记0二_数据库和表的基本操作,mysql学习笔记 02_1 操作数据库 (1)创立数据库 CREATE DATABASE [IF NOT EXISTS] db...

详细>>