【发布时间】:2013-02-02 15:21:35
【问题描述】:
亲爱的朋友们,我需要从具有不同标准的一张表中获取计数(*)。我正在使用带有 spring 的 hibernate。我正在使用下面的查询。
"select " +
"(select count(*) from enquiry where business_id="+busid+") AS allEnqCount,"+
"(select count(*) from enquiry where status='"+Constants.ENQ_FALLOWUP+"' and us.business_id="+busid+") AS followupCount," +
"(select count(*) from enquiry where status='"+Constants.ENQ_SITE_VISIT+"'and us.business_id="+busid+") AS siteVisitCount ," +
"(select count(*) from enquiry where status='"+Constants.ENQ_CUST_VISIT+"'and us.business_id="+busid+") AS customerVisitCount," +
"(select count(*) from enquiry where status='"+Constants.ENQ_OFFICE_VISIT+"'and us.business_id="+busid+") AS officevisitCount,"+
"(select count(*) from enquiry where status='"+Constants.ENQ_PENDING+"'and us.business_id="+busid+") AS pending";
但这需要相当长的时间。你能告诉我有没有什么方法可以用最少的时间和一个选择子句来完成。
提前致谢。
【问题讨论】:
-
那张表有多少行?