0

所以我有这个查询并想在其中实现一些 HTML,所以我可以在我的网站上打印而不使用循环。但我的问题是我的案件的字符串部分没有附加到testresults.TestCaseId?我怎样才能做到这一点?

SELECT 
    CASE WHEN testresults.StatusId = 1 THEN  '<li class="list-group-item list-group-item-success">'+testresults.TestCaseId+'</li>' ELSE '' END
FROM
    testresults
ORDER BY testresults.TestRunsId DESC;

此查询仅返回 testresults.TestCaseId 的值,而不是 'this'+...+'this' 部分。

4

1 回答 1

1

MariaDB/MySQL 不用+作字符串连接运算符。相反,请使用以下CONCAT()功能:

SELECT
    CASE WHEN testresults.StatusId = 1
         THEN CONCAT('<li class="list-group-item list-group-item-success">',
                     testresults.TestCaseId, '</li>')
         ELSE '' END
FROM testresults
ORDER BY TestRunsId DESC;

如果您想在这里使用实际的运算符,那么您可以使用 ANSI||连接运算符,具体取决于您的 MariaDB 服务器模式:

SELECT
    CASE WHEN testresults.StatusId = 1
         THEN '<li class="list-group-item list-group-item-success">' ||
              testresults.TestCaseId || '</li>'
         ELSE '' END
FROM testresults
ORDER BY TestRunsId DESC;
于 2021-09-09T07:18:38.830 回答