简体   繁体   English

选择并插入多个记录

[英]select and insert multiple records

------------------------------------------------
ID  |   Member Name |   Zone    | Created_Date |
------------------------------------------------
1   |   foo         |   Zone1   |  2015-02-23  |
2   |   bar         |   Zone1   |  2015-02-23  |
3   |   foo1        |   Zone2   |  2015-02-23  |
4   |   baar1       |   Zone2   |  2015-02-23  |
5   |   foo3        |   Zone1   |  2015-02-23  |
------------------------------------------------

------------------------------------------------------------
ID  |   Member ID   |    Car    |   Zone    | Created_Date |
------------------------------------------------------------
1   |   1           |   Civic   |   Zone1   |  2015-02-23  |
2   |   1           |   BMW     |   Zone2   |  2015-02-23  |
3   |   2           |   Vitz    |   Zone1   |  2015-02-23  |
4   |   2           |   BMW     |   Zone1   |  2015-02-23  |
5   |   3           |Honda City |   Zone2   |  2015-02-23  |
------------------------------------------------------------

I want to enter some entries in ledger against registration of cars in a zone 我想在分类帐中输入一些条目,以防止区域中的汽车注册

like 喜欢

in zone 1 how many cards registered today? 在1区今天注册了多少张卡?

i can handle with single zone, but how to manage multiple items 我可以处理单个区域,但如何管理多个项目

i am using codeigniter and trying like this 我正在使用codeigniter并尝试这样做

public function distribute_commision()
{
    $this->db->where('Is_Active', 0);
    //$this->db->where('Sort_Order', 4);
    $this->db->select('ID');                
    $this->db->select('Zone');
    $this->db->where('Created_Date', '2015-02-23');
    $query = $this->db->get('tbl_clients');

    if($query->num_rows() > 0)
    {
        $data = $query->result_array();

        foreach($data as $da)
        {
            $array = "'". $da['Zone'] ."'";
            $zone[] = $array;
        }

        $record = implode(",", $zone);
        //echo $record;
        $zm_query = $this->db->query("SELECT `ID`, `Name`, `Zone` FROM `tbl_members` WHERE `Zone` IN (".$record.") AND `Sort_Order` = '4' AND `Created_Date` = '".date('Y-m-d', time())."'");
        echo "<pre>";
        print_r($zm_query->result_array());
        echo "</pre>";          
    }   

}

Try this query 试试这个查询

select *,count(aa.id) as count tbl_client as aa
join tbl_members as bb on bb.id=aa.member_id
where aa.created_date=date('Y-m-d', time())
group by aa.created_date

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM