选择 DISTINCT 结果后的字符串连接
String concatenation after DISTINCT result selected
我有以下查询:
SELECT xmlagg(xmlparse(content RESULTS || '|' wellformed) ORDER BY RESULTS).getclobval() AS RESULTS
FROM
(
SELECT distinct ' ' || result|| ' - ' || result_final || ' xxx' as RESULTS from myTable where ID = '123456'
);
目前“xxx”会附加在每个result_final的末尾,如何通过将其连接到查询的最终字符串的开头来实现?
' xxx'|| RESULTS
有条件,只有当result=x时才会发生上述连接,否则只打印RESULTS。
将该字符串移到“结果”前面而不是后面。
不过,由于应该满足附加条件,请使用您当前的查询(没有 'xxx')作为子查询并通过 CASE
.
应用条件
使用虚拟样本数据:
SQL> DESC mytable
Name Null? Type
----------------------------------------- -------- ----------------------------
RESULT CHAR(1)
RESULT_FINAL CHAR(1)
ID CHAR(6)
SQL> SELECT * FROM mytable;
R R ID
- - ------
x y 123456
SQL> SELECT CASE
2 WHEN TO_CHAR (results) = 'x' THEN ' xxx' || results
3 ELSE results
4 END AS results
5 FROM (SELECT XMLAGG (XMLPARSE (CONTENT RESULTS || '|' WELLFORMED)
6 ORDER BY RESULTS).getclobval () AS RESULTS
7 FROM (SELECT DISTINCT
8 ' ' || result || ' - ' || result_final AS RESULTS
9 FROM myTable
10 WHERE ID = '123456'));
RESULTS
--------------------------------------------------------------------------------
x - y|
SQL>
我有以下查询:
SELECT xmlagg(xmlparse(content RESULTS || '|' wellformed) ORDER BY RESULTS).getclobval() AS RESULTS
FROM
(
SELECT distinct ' ' || result|| ' - ' || result_final || ' xxx' as RESULTS from myTable where ID = '123456'
);
目前“xxx”会附加在每个result_final的末尾,如何通过将其连接到查询的最终字符串的开头来实现?
' xxx'|| RESULTS
有条件,只有当result=x时才会发生上述连接,否则只打印RESULTS。
将该字符串移到“结果”前面而不是后面。
不过,由于应该满足附加条件,请使用您当前的查询(没有 'xxx')作为子查询并通过 CASE
.
使用虚拟样本数据:
SQL> DESC mytable
Name Null? Type
----------------------------------------- -------- ----------------------------
RESULT CHAR(1)
RESULT_FINAL CHAR(1)
ID CHAR(6)
SQL> SELECT * FROM mytable;
R R ID
- - ------
x y 123456
SQL> SELECT CASE
2 WHEN TO_CHAR (results) = 'x' THEN ' xxx' || results
3 ELSE results
4 END AS results
5 FROM (SELECT XMLAGG (XMLPARSE (CONTENT RESULTS || '|' WELLFORMED)
6 ORDER BY RESULTS).getclobval () AS RESULTS
7 FROM (SELECT DISTINCT
8 ' ' || result || ' - ' || result_final AS RESULTS
9 FROM myTable
10 WHERE ID = '123456'));
RESULTS
--------------------------------------------------------------------------------
x - y|
SQL>