Questions about database query updates

Source: Internet
Author: User
About database query update problem table structure: idorder_idnameaddressqtyproduct_numberproductlogistics_id sample data id --- order_id ---- name ------ address ---- qty ---- product ---- l about database query update
Table structure:
Id
Order_id
Name
Address
Qty
Product_number
Product
Logistics_id

Sample data
Id --- order_id ---- name ------ address ---- qty ---- product ---- logistics_id
1-----000001 ---- wanggang ---- shenzhen ---- 10 ---- iphone -----?
2-----42602 ---- wanggang ---- shenzhen ---- 5 ----- ipod -------?
3-----000003 ---- lier -------- beijing ----- 5 ----- ipad -------?
4-----000004 ---- zhaosi ------ guangzhou --- 8 ----- ipad -------?
5-----000005 ---- lier -------- beijing ----- 4 ----- iphone -----?


We will Upload each downloaded next order file to my system. except for the logistics_id field, other content is the content of this uploaded file. The current requirement is that when we import these orders to the database, we need to encode each email (the express number, logistics_id field ), if the person name and address are the same, the same code (the same express delivery) is required. how can I compile the same code for the records with the same name and address during the import ?? If it cannot be encoded during import, what method is better?
Share:
------ Solution --------------------
Are you using MySQL? You can use GROUP_CONCAT (expr) to obtain the list of conditions, and then update these IDs into a courier number.


SELECT tb.name, tb.address, GROUP_CONCAT(tb.id SEPARATOR ' ') AS id_list
    FROM table tb
GROUP BY tb.name, tb.address


Output
name, address, id_list
------------------------
wanggang, shenzhen, 1 2
lier, beijing 3 5
zhaosi,guangzhou, 4





Document: http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_group-concat

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.