親愛的朋友們,我有一個要求從一張表中獲得具有不同標準的計數(*)。我在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";
但它花費了相當多的時間。你能告訴我有什麼辦法可以用最少的時間和一個選擇條款來做到嗎?
在此先感謝。
有多少行,你必須在該表? – 2013-02-18 08:53:23