当前位置:   article > 正文

dm(达梦)_达梦groupconcat

达梦groupconcat

1分组

后拼接字段(GROUP_CONCAT)

分组的字段需要加

 

  1. SELECT
  2. /*+ GROUP_OPT_FLAG(1)*/ r.role_id as id,
  3. r.role_name as name,
  4. r.role_code as code,
  5. WM_CONCAT(u.user_id) as userIds ,
  6. WM_CONCAT(u.user_name) as userNames
  7. from
  8. role r
  9. left join user_role ur on r.id = ur.role_id and ur.IS_DEL=0
  10. left join user u on ur.user_id =u.id and u.IS_DEL=0
  11. WHERE
  12. r.IS_DEL = 0
  13. group by r.role_id

多条数据 分组 展示字段用逗号隔开

LISTAGG(bus.ORG_NAME, ';')  可以自定义分隔符

wm_concat()  默认逗号隔开

注意:以上俩个函数,分组后 字段太长会报 字符串截断异常。

  1. select
  2. study.ID ,
  3. study.PROJECT_NAME ,
  4. LISTAGG(bus.ORG_NAME, ';') ,
  5. wm_concat(bus.BUSINESS_SUPERVISOR_NAME)
  6. from
  7. "ITMS_PROJECT"."STUDY" study
  8. LEFT JOIN "ITMS_PROJECT"."ORG" bus
  9. ON
  10. bus.BUSINESS_ID=study.ID
  11. group by
  12. study.ID
  13. ORDER by
  14. study.ID

2 时间格式化String

  1. to_char(PLANNED_TIME,'yyyy-mm-dd') as PLANNED_TIME

3 字段拼接||

 SELECT * ,VALID_START_TIME||'-'||VALID_END_TIME as validStartEndTime,。。。。。

4 时间范围查询

方式一

startTime /endTime 都是date类型  

字符串类型必须符合时间格式

  1. select *
  2. FROM
  3. user u
  4. WHERE 1=1
  5. <if test="startTime != null and endTime != null">
  6. AND u.start_time BETWEEN #{startTime } AND #{endTime }
  7. </if>

方式二(注意时间标度)

为什么我的时间后面加了['2023-03-30 23:59:59.999999' ]  因为数据库的标度是6,['2023-03-30 23:59:59' ] 这样的写法等于['2023-03-30 23:59:59.000000' ],会查询不到 某些数据

  1. select
  2. *
  3. from
  4. "aa"."aa" where
  5. CREATE_TIME >='2023-03-29' and CREATE_TIME <= '2023-03-30 23:59:59.999999'
  6. ORDER by CREATE_TIME DESC;

xml拼接

  1. AND TIME &gt;= CONCAT(#{timeStart},' 00:00:00')
  2. AND TIME &lt;= CONCAT(#{timeEnd},' 23:59:59')

5 展示序号 排序要跟整个sql保持一致才是你想要的递增序号

row_number() over (order by a.update_time desc) as number,

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/880927
推荐阅读
相关标签
  

闽ICP备14008679号