Need to Sort and Filter 2 Price files into one
We have 2 price files one from last year, and a new one from this year. there are about 25000 rows in each, but have slightly different prices, and none of the items in this years file have UPC codes.
I need to combine the two lists, keeping the higher prices, when the cost and description is the same. If the higher priced item does not have a UPC in that row, I need to pull the UPC from a matching lower priced item if it exists. Then delete any other m开发者_StackOverflow中文版atches, so we have one clean list.
I would like to do this with PHP/MySQL
Any Suggestions or assistance would be greatly appreciated.
Since your want to do this with MySQL, I suppose the data is already in the DB, then this is just a SQL query:
INSERT INTO NewPriceList (Price, Cost, Description, UPC)
SELECT L.Price, L.Cost, L.Description, L.UPC
FROM LastYear L, ThisYear T
WHERE
L.Cost = T.Cost AND
L.Description = T.Description AND
L.Price > T.Price
UNION
SELECT T.Price, L.Cost, L.Description, L.UPC
FROM LastYear L, ThisYearT
WHERE
L.Cost = T.Cost AND
L.Description = T.Description AND
L.Price <= T.Price;
Otherwise you'd have to do this manually in PHP (for each item of one list, search the corresponding item in the second list, take the columns you want and insert into your database) or insert the data into your database before executing the query.
精彩评论