1. ORDER BY 语句

	 ORDER BY 中字段必须是select 查询中的字段(示例在2中)

2. GROUP BY 语句

	  GROUP BY使用是必须加上你SELECT后面所查询的所有除聚合函数之外的所有字段

示例

SELECT
--   GROUP BY 示例
COUNT( resin.id ) recordNum,
resin.r_user_id,
resin.NAME userName,
resin.record_no,
resin.record_time,
MAX( resin.id ) maxid 
FROM
	(
		SELECT
		--   ORDER BY 示例
		ucr.id,
		ucr.dept_id,
		ucr.user_id,
		ucr.operator_id,
		ucr.vendor_id,
		ucr.r_user_id,
		ucr.contract_id,
		ucr.contract_no,
		ucr.file_name,
		ucr.file_path,
		ucr.created_by,
		ucr.created_at,
		ucr.changed_by,
		ucr.record_type,
		ucr.changed_at,
		ucr.record_time,
		ucr.available,
		ucr.start_time,
		ucr.end_time,
		ucr.version,
		u.NAME,
		u.record_no 
	FROM
		user_contract_record ucr
		LEFT JOIN r_user u ON ucr.r_user_id = u.id 
	WHERE
		u.id IS NOT NULL
	--  ORDER BY 示例	
	ORDER BY
		ucr.id DESC 
	) resin 
--   GROUP BY 示例	
GROUP BY
	resin.r_user_id,
	resin.NAME,
	resin.record_no,
	resin.record_time

或者更改达梦数据库配置,使之兼容mysql
aef2e565769bed7cbdbb76d45f52102

3. 如图mysql语句转达梦语句是 select中字段不能存在引号

image-1668671446490

4. 达梦数据库多表关联 select中尽量不要用table.* 进行查询,如果有字段冲突不会像mysql一样转义

image-1668672331803

5. 达梦数据库多表关联查询,表字段类型需要保持一致(例 int=int),如果不一致需要将数据类型强制转换成一致,比如转换为String(错误类型:-6111: 字符串转换出错)

```
 CAST(ID AS VARCHAR)
```
示例:

image-1668673993019

6.达梦数据库在使用时间戳时使用Date不要使用LocalDateTime,目前若依架构使用连接池不兼容

7.达梦数据库BLOB目前无法转换为VARCHAR,需要在库里将该字段删除保存之后重新创建text类型字段

上一篇 下一篇