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