SELECT b.station_name AS stationName, c.standard_name AS standardName, IFNULL( b.address, '' ) AS address, b.longitude AS longitude, b.latitude AS latitude, h.dict_label AS type, e.water_name AS waterName, DATE_FORMAT( a.sample_time, '%Y-%m-%d %H:%i:%S' ) AS sampleTime, IFNULL( g.dict_label, '无' ) AS LEVEL, CONCAT( IFNULL( AVG( CASE i.NAME WHEN 'COD' THEN 0+CONVERT ( a.param_value, CHAR ) END ), "" ), "(", IFNULL( ( SELECT dict_label FROM sys_dict_data WHERE dict_type = "sys_param_status" AND dict_value = AVG( CASE i.NAME WHEN 'COD' THEN CONVERT ( a.param_flag, UNSIGNED ) END ) ), "-" ), ")", "/", IFNULL( AVG( CASE i.NAME WHEN 'COD' THEN 0+CONVERT ( a.tag_status, CHAR ) END ), "" ), "/", IFNULL( AVG( CASE i.NAME WHEN 'COD' THEN 0+CONVERT ( a.mark, CHAR ) END ), "" ) ) AS 'COD' FROM water_data_real AS a LEFT JOIN water_station AS b ON a.station_code = b.station_code LEFT JOIN water_standard AS c ON b.standard_id = c.id LEFT JOIN rl_water_body AS e ON b.water_id = e.id LEFT JOIN ( SELECT dict_label, dict_value FROM sys_dict_data WHERE dict_type = "sys_station_type" ) AS h ON b.type = h.dict_value LEFT JOIN ( SELECT dict_label, dict_value FROM sys_dict_data WHERE dict_type = "water_level" ) AS g ON a.LEVEL = g.dict_value LEFT JOIN water_param_lib AS i ON a.param_code = i.CODE WHERE i.type = '2' AND b.station_code ='0000000002' AND a.sample_time >= '2023-05-23 23:34:44' AND a.sample_time <='2023-05-23 23:36:44' GROUP BY a.qn ORDER BY a.sample_time; Mark值应该是中文,但是通过拼接后的结果是显示0
时间: 2024-03-05 13:53:55 浏览: 49
根据您提供的 SQL 语句,我发现在拼接的语句中,对 `a.mark` 字段使用了 `CONVERT` 函数将其转换为了字符类型,这可能导致中文字符被转义或截断。您可以将该部分拼接语句修改为以下形式,使用 `IFNULL` 函数将中文字符转换为字符串类型:
```
CONCAT(
IFNULL(AVG(CASE i.NAME WHEN 'COD' THEN CONVERT(a.param_value, CHAR) END), ""),
"(",
IFNULL(
(
SELECT dict_label
FROM sys_dict_data
WHERE dict_type = 'sys_param_status'
AND dict_value = AVG(CASE i.NAME WHEN 'COD' THEN CONVERT(a.param_flag, UNSIGNED) END)
),
"-"
),
")",
"/",
IFNULL(AVG(CASE i.NAME WHEN 'COD' THEN CONVERT(a.tag_status, CHAR) END), ""),
"/",
IFNULL(
(
SELECT dict_label
FROM sys_dict_data
WHERE dict_type = 'sys_param_status'
AND dict_value = AVG(CASE i.NAME WHEN 'COD' THEN a.mark END)
),
""
)
) AS 'COD'
```
修改后,如果 `a.mark` 字段的值为中文,则会被正确地转换为字符串类型并显示在拼接结果中。
阅读全文