Reference: Http://stackoverflow.com/questions/6898935/sql-update-query-with-group-by-clause
--Update DataUPDATEProduct_info asTINNER JOIN (SELECTPRODUCT_ID,Max(update_date) Update_date fromProduct_infoWHEREproduct_id= 830 GROUP byproduct_id) T1 ont.product_id=t1.product_id andT.update_date=t1.update_dateSETIsActive= 1, remark= 'Update operation directly on the shelves---3! ';
--Check the latest recordsSelect * fromProduct_info asTINNER JOIN (SELECTPRODUCT_ID,Max(update_date) Update_date fromProduct_infoGROUP byproduct_id) T1wheret.product_id=t1.product_id andT.update_date=T1.update_dateorder by t.product_id;
--The structure of the table usedCREATE TABLE' product_info ' (' product_id ' )INT(Ten) UNSIGNED not NULL, ' Product_Name 'VARCHAR( -) not NULL, ' Cost_price 'DECIMAL(Ten,2) UNSIGNED not NULL DEFAULT '0.00', ' Current_price 'DECIMAL(Ten,2) UNSIGNED not NULL DEFAULT '0.00', ' update_date 'DATETIME not NULL DEFAULT '2015-01-01 00:00:00', ' Remark 'VARCHAR(255) not NULL DEFAULT "', ' isActive 'TINYINT(1) not NULL DEFAULT '1', INDEX' idx_id ' (' product_id ')) COMMENT='Product Information Sheet (IsActive Indicates whether the existing product is being sold) \ r \ n This table adds a record to the stock table when new items are added'COLLATE='Utf8_general_ci'ENGINE=InnoDB;
mysql-How to query/modify the record of the maximum date