id band (brand) num (sales quantity) price (unit price)
1 Samsung 7677 2300
2 Huawei 9877 1699
3 Apple 24552 6799
... More brands, unknown quantity, consider the large quantity in excel
Question:
If we want to count the top 3 brands with the largest total sales (the database cannot be used)
just tell me your idea, thank you
id band (brand) num (sales quantity) price (unit price)
1 Samsung 7677 2300
2 Huawei 9877 1699
3 Apple 24552 6799
... More brands, unknown quantity, consider the large quantity in excel
Question:
If we want to count the top 3 brands with the largest total sales (the database cannot be used)
just tell me your idea, thank you
php gets the execl content. Each cell will be a key in the array. Sales (quantity * price) are accumulated according to the brand key, and the top three are finally sorted.
Thank you for the invitation. You can use a program to read the excel file and organize it into an array, and then sort the array by price. Personal understanding
Excel problem?
Create a new column and calculate the total sales of each row;
Enable filtering
Sort
PHP implementation method:
<code class="php"><?php $data = []; // excel的数据 brand: 品牌; price: 价格; qty: 销量; $result = []; foreach ($data as $item) { $total = $item['price'] * $item['qty']; if (array_key_exists($item['brand'], $result)) { $result[$item['brand']] += $item['price'] * $item['qty']; } else { $result[$item['brand']] = $total; } } arsort($result); // 值降序排序 // 前三个值的key就是品牌了 ?> </code>