Now there are millions of records, can be divided into hundreds of thousands of sets of data, according to the ID each ID exist under different combination, consult everybody how to sort out these combinations? Such as ID product prices 111 A 10 111 B 111 C 9 222 A 10 222 B
Contains A B C I want how many? Include how many AB? As long as give a hint, I slowly thinking!
CodePudding user response:
One of two ways. 1, SQL the direct analysis with decode (), is similar to the following list Product id number, number of product B, product C
ORACLE is decode, MYSQL as the when case
2, python
Iterate through all the data, set up the dictionary list of the product value is set, that's good operation, and can be set directly, [{' id ':' 111 ', 'product' : (' A ', 'B', 'C')}, {' id ':' 222 ', 'product' : (' A ', 'B')}]
Finally, traversing the dictionary list to get the target list