数据库日期

Posted gavin-yao

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了数据库日期相关的知识,希望对你有一定的参考价值。

<!--查按年询某个开发者下已上线的应用-->
<select id="selectAppByYearAndDevId" resultType="java.util.Map">
SELECT
app_name AS appName,
app_id As appId,
DATE_FORMAT(create_time, ‘%Y‘) AS date
FROM
aisv_g_app_info
WHERE
DATE_FORMAT(create_time, ‘%Y‘) = #{year}
AND is_del = 0
AND app_state = 5
AND developer_id = #{developerId}
</select>

<!--查按月询某个开发者下已上线的应用-->
<select id="selectAppByMonthAndDevId" resultType="java.util.Map">
SELECT
app_name AS appName,
app_id As appId,
DATE_FORMAT(create_time, ‘%Y-%m‘) AS date
FROM
aisv_g_app_info
WHERE
DATE_FORMAT(create_time, ‘%Y-%m‘) = #{month}
AND is_del = 0
AND app_state = 5
AND developer_id = #{developerId}
</select>

<!--查按周询某个开发者下已上线的应用-->
<select id="selectAppByWeekAndDevId" resultType="java.util.Map">
SELECT
app_name AS appName,
app_id As appId,
DATE_FORMAT(create_time, ‘%Y-%m-%d‘) AS date
FROM
aisv_g_app_info
WHERE
DATE_FORMAT(create_time,‘%Y-%m-%d‘) <![CDATA[ <= ]]>#{todayStr} AND
DATE_FORMAT(create_time,‘%Y-%m-%d‘)<![CDATA[ >= ]]>#{sevenDayBeforeStr}
AND is_del = 0
AND app_state = 5
AND developer_id = #{developerId}
</select>

<select id="selectListByUserOperationLogPage" resultMap="userOperationLogResult">

SELECT *
FROM
aisv_g_user_operation_log
<where>
1=1
<if test="param.userName!= null and param.userName !=‘‘">
and
user_name =#{param.userName}
</if>
<if test="param.userIp != null and param.userIp !=‘‘">
and
USER_IP =#{param.userIp }
</if>
<if test="param.operationType != null and param.operationType !=‘‘">
and
OPERATION_TYPE =#{param.operationType}
</if>
<if test="param.startdate != null and param.startdate !=‘‘">
and
OPERATION_TIME &gt;=#{param.startdate}
</if>
<if test="param.enddate != null and param.enddate !=‘‘">
and
OPERATION_TIME &lt;=#{param.enddate}
</if>
</where>
order by OPERATION_TIME DESC
limit #{page.begin},#{page.pageSize}
</select>

技术图片

@DateTimeFormat(pattern = "yyyy-MM-dd")
@JsonFormat(pattern = "yyyy-MM-dd")
private LocalDateTime transactionDate;

mysql中大于等于小于等于的写法

由于在mybatis框架的xml中<= , >=解析会出现问题,编译报错,所以需要转译
第一种写法:

原符号 < <= > >= & ’ "
替换符号 &lt; &lt;= &gt; &gt;= &amp; &apos; &quot;
例如:sql如下:

unix_timestamp(target.mc_end_date)&lt;= unix_timestamp(#{MonthEndTime});unix_timestamp(target.mc_start_date) &gt;= unix_timestamp(#{MonthBeginTime})
  • 1

第二种写法:
大于等于

<![CDATA[ >= ]]>

小于等于

<![CDATA[ <= ]]>

例如:sql如下:

mc_end_date <![CDATA[ >= ]]> #{endTime} and  mc_start_date <![CDATA[ <= ]]> #{startTime}

以上是关于数据库日期的主要内容,如果未能解决你的问题,请参考以下文章

sql 日期转换代码片段 - Dato,120,konvertere

Android studio 动态片段根据日期

日期选择器对话框在片段中不起作用[关闭]

如何从片段中调用 getSupportFragmentManager()?

vscode 用户代码片段 vue初始化模板 Snippet #新加入开头注释 自动生成文件名 开发日期时间等内容

如何从我的 DatePicker 片段中传输格式化的日期字符串?