问题描述
- 分类汇总问题、求大神帮忙解决。跪求
-
下边是我实现第一个图的代码,现在我想实现第二张图查询出来的模式,第二张图的错误次数是该用户的记录次数(一个名词出现的次数)。这个同事告诉我是分类汇总问题、public String getList() throws Exception { chengJiJiLuList = dao.getList(TrainingOrCompetitionID,startTime,endTime); ArrayList chengJiJiLuList = new ArrayList(); coreService.getRsToObjList(chengJiJiLuList, ChengJiJiLu.class, "select userID,count(userID) as userID from ChengJiJiLu where trainingOrCompetitionID=" + TrainingOrCompetitionID + " group by userID;"); coreService.getRsToObjList(chengJiJiLuList, ChengJiJiLu.class, "select xiangmu,userID,count(userID) as userID from ChengJiJiLu where trainingOrCompetitionID=" + TrainingOrCompetitionID + " group by xiangmu,userID;"); userList = this.getUserLisAll(); return SUCCESS; public ArrayList getUserLisAll() throws Exception { Users user = new Users(); ArrayList userList = new ArrayList<Users>(); service.getObjList(userList, user, " oid in (select id from organization)", " id"); return userList; } }
<%@page contentType="text/html; charset=UTF-8" import="java.util.*" %> <%@ page import="com.sysgrrj.core.valueobject.UsersSession" %> <%@ taglib prefix="s" uri="/struts-tags" %> <html> <head> <jsp:include page='/res/inc/inc.jsp' flush='true'/> </head> <body> <s:form action="Add" id="form1" theme="simple" > <jsp:include page='/res/inc/inc_form_List.jsp' flush='true'/> <script type="text/javascript"> function doAction(action) { if ("add" == action) { var url = '/Module/ChengJiJiLu/Add.action?iframeId=' +<s:property value="iframeId"/>+'&TrainingOrCompetitionID='+<s:property value="TrainingOrCompetitionID"/>; window.parent.openWinEdit(this, '成绩记录', url, 0, 0); } else { var selectIds = ""; var arryObj = document.getElementsByName("selId"); var count = 0; for (var i = 0; i < arryObj.length; i++) { if (typeof arryObj[i].type != "undefined" && arryObj[i].type == "checkbox") { if (arryObj[i].checked) { selectIds = selectIds + arryObj[i].value + ","; count = count + 1; } } } if ("update" == action) { if (count == 0 || 1 < count) { alert('请先选择一条记录'); return false; } selectIds = selectIds.substring(0, selectIds.length - 1); var url = '/Module/ChengJiJiLu/Edit.action?id=' + selectIds + '&iframeId=' +<s:property value="iframeId"/>+'&TrainingOrCompetitionID='+<s:property value="TrainingOrCompetitionID"/>; window.parent.openWinEdit(this, '成绩记录', url, 0, 0); } else if ("del" == action) { if (count == 0) { alert('请先选择一条记录'); return false; } if (confirm("是否确认删除?")) { selectIds = selectIds.substring(0, selectIds.length - 1); document.getElementById("ids").value = selectIds; document.getElementById("form1").action = "Delete"; document.getElementById("form1").submit(); return true; } else { return false; } } } } </script> <div class="buttonDiv"> 查询日期: <input type="text" name="startTime" size="10" value="<s:property value="startTime"/>" readonly="true" onclick="setday(this)"> 至 <input type="text" name="endTime" size="10" value="<s:property value="endTime"/>" readonly="true" onclick="setday(this)"> 用户名称:<s:textfield name="keRenMingCheng" size="8" value="%{keRenMingCheng}"/> <s:submit theme="simple" name="List" action="List" value="查询" cssClass="button_style" method="getList"/> <input type="button" class="button_style_add" onclick="return doAction('add')"/> <input type="button" class="button_style_edit" onclick="return doAction('update')"/> <input type="button" class="button_style_del" onclick="return doAction('del')"/> </div> <div class="validatemsg"> <s:actionerror/> <s:fielderror/> <s:actionmessage/> </div> <%--<%--%> <%--UsersSession usersSession = (UsersSession) request.getSession().getAttribute("usersession");--%> <%--String userNameInfo = usersSession.getUsersObj().getName();--%> <%--%>--%> <table width="100%" class="listext" id="table1"> <tr> <TH colspan="7" style="background: #EBEBEB;height: 35px"> 成绩记录</TH> </tr> <TR> <TH width="10"><s:checkbox id="doAllSele" value="" onclick="selectAll()" name="doAllSele"></s:checkbox></TH> <TH width="30"> 序号</TH> <TH>用户名称</TH> <%--<TH>TrainingOrCompetitionID</TH>--%> <TH>时间</TH> <TH>项目</TH> <TH>状态</TH> <TH>备注</TH> </TR> <s:iterator value="chengJiJiLuList" status="st" var="cil"> <TR> <TD><input type="checkbox" name="selId" id="selId" value="<s:property value="id"/>"/></TD> <TD align="center"><s:property value='#st.index+1'/></TD> <TD ><s:iterator value="userList" var="ulist"> <s:if test="#ulist.id==#cil.userID"><s:property value="#ulist.name"/></s:if> </s:iterator></TD> <%--<TD ><s:property value="trainingOrCompetitionID"/></TD>--%> <TD align="center"><s:date name="shiJian" format="yyyy-MM-dd" /></TD> <TD ><s:property value="xiangMu"/></TD> <TD ><s:property value="zhuangTai"/></TD> <TD ><s:property value="beiZhu"/></TD> </TR> </s:iterator> </TABLE> <s:hidden name="TrainingOrCompetitionID"/> </s:form> </body> </html>
解决方案
sql语句的order by汇总
解决方案二:
select count(*) from 表 where 1 group by 用户名
解决方案三:
select username as 用户名称,count(用户名称) as 错误次数 from 你的表(第一个图的查询结果) group by 用户名称
时间: 2024-10-06 03:07:46