【问题标题】:SQL Query Column Names and JSP/JSTLSQL 查询列名和 JSP/JSTL
【发布时间】:2023-03-07 06:32:01
【问题描述】:

我有一个在 Netbeans 中使用 JSTL 和 JSP 运行的 SQL 查询..

<sql:query dataSource="${snapshot}" var="disc">
    select DISCHARGE_STATUS as status, (count(*)/(select count(*) from hw))*100 as result from hw where age=<%= age_group %> and sex=<%= gender %> and ADMITTING_DIAGNOSIS_CODE=<%= admission_code %>  group by DISCHARGE_STATUS;
</sql:query>

并尝试用这个输出它:

<table border="1" width="100%">
    <tr>
    <th>Discharge Status: </th>

    </tr>
    <c:forEach var="row" items="${disc.rows}">
    <tr>
        <td><c:out value="${row.status}"/></td>
    </tr>
    <tr>
        <td><c:out value="${row.result}"/></td>
    </tr>
    </c:forEach>
</table>

result 正确输出,但状态为空。

当我在我的 php 代码上运行此查询以进行测试时,我得到以下信息:

status result   
a      0.4062   
b      0.0677   

【问题讨论】:

  • 什么列名?它只是一个百分比,你还没有给它分配一个列名。
  • @davidwallace 我继续修改上面的代码
  • 嗯,尝试将其命名为 status 以外的其他名称。我认为这是 JSTL forEach 循环中的关键字。
  • @AndyP 尝试一些其他别名作为状态,因为状态是关键字

标签: java mysql sql jsp jstl


【解决方案1】:

以下链接有答案 这不是一个合适的解决方案,但它有效

jsp jstl sql strange behaviour with as in mysql

select concat(DISCHARGE_STATUS) 作为状态,(count()/(select count() from hw))*100 作为结果 from hw where age= and sex= and ADMITTING_DIAGNOSIS_CODE= 按 DISCHARGE_STATUS 分组;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-26
    • 1970-01-01
    相关资源
    最近更新 更多