1
我正在使用codeigniter框架和mysql。我想要顯示記錄總和(amtreceived)> 50000。否則我想檢查與價值,這意味着總和(iman_sub_product_payment_details.amtreceived)作爲amount.Is有可能像這樣檢查。任何人都請幫助我。 以下是我的查詢使用mysql和codeigniter檢查總和(金額)的條件
$sql='SELECT pay_date,sub_ins_name as name, sum(iman_sub_product_payment_details.amtreceived) as amount, sum(iman_sub_product_payment_details.refundedamt) as refamount,iman_sub_product_payment_details.subscriber_id as subid FROM iman_subscriber_insitution_details LEFT JOIN `iman_sub_product_payment_details` ON `iman_sub_product_payment_details`.`subscriber_id`=`iman_subscriber_insitution_details`.`sub_institute_id`';
if(!empty($data['fromdate'])){
$sql.=' where iman_sub_product_payment_details.pay_date >= date("'.$fromdate.'")';
}if(!empty($data['todate'])){
$sql.=' and iman_sub_product_payment_details.pay_date <= date("'.$todate.'")';
}if($data['comboval']!=0){
$sql.=' and iman_sub_product_payment_details.combostatus ="1"';
}if($data['from_amount']!=""){
$sql.=' and amtreceived >="'.$data['from_amount'].'"';
}
if($data['to_amount']!=""){
$sql.=' and amtreceived <="'.$data['to_amount'].'"';
}
if($data['currency']!=0){
$sql.=' and iman_sub_product_payment_details.cur_id ="'.$data['currency'].'"';
}
$sql.=' group by iman_subscriber_insitution_details.sub_institute_id';
$sql.=' UNION
SELECT pay_date,agentname as name,sum(iman_sub_product_payment_details.amtreceived) as amount,sum(iman_sub_product_payment_details.refundedamt) as refamount,iman_sub_product_payment_details.subscriber_id as subid FROM iman_agent_details
LEFT JOIN `iman_sub_product_payment_details` ON `iman_sub_product_payment_details`.`dealer_id`=`iman_agent_details`.`agentid` ';
if(!empty($data['fromdate'])){
$sql.=' where iman_sub_product_payment_details.pay_date >= date("'.$fromdate.'")';
}if(!empty($data['todate'])){
$sql.=' and iman_sub_product_payment_details.pay_date <= date("'.$todate.'")';
}if($data['comboval']!=0){
$sql.=' and iman_sub_product_payment_details.combostatus ="1"';
}if($data['from_amount']!=""){
$sql.=' and amtreceived >="'.$data['from_amount'].'"';
}
if($data['to_amount']!=""){
$sql.=' and amtreceived <="'.$data['to_amount'].'"';
}
if($data['currency']!=0){
$sql.=' and iman_sub_product_payment_details.cur_id ="'.$data['currency'].'"';
}
$sql.=' group by iman_agent_details.agentid';
$sql.=' order by name asc';
$query=$this->db->query($sql);
我不知道我想在這種情況下使用。我總結了許多記錄工會等所以我的意思是作爲一個新的問題 – premi