如何在Laravel下获取具有相同id的元素的最大值

时间:2018-02-12 14:05:02

标签: laravel eloquent

使用Laravel/Eloquent,我想检索下表中每个week_id的最大值。

 +---------+-----------+
 | week_id |     value |
 +---------+-----------+
 |    5    |           |
 |    6    |         1 |
 |    6    |           |
 |    6    |           |
 |    7    |         3 |
 |    7    |         4 |
 |    7    |           |
 +---------+-----------+

使用MySql我会这样做:

SELECT week_id, max(value) as max_value FROM foo_table GROUP BY week_id

=>

+---------+-----------+
| week_id | max_value |
+---------+-----------+
|       5 |           |
|       6 |         1 |
|       7 |         4 |
+---------+-----------+

我怎样才能在Laravel下实现同样的目标?

1 个答案:

答案 0 :(得分:2)

试试这个:

for chunk in pd.read_csv(f, sep = ' ', header = None, chunksize = 512):
         # process your chunk here