R
R
Ram19792019-08-25 16:01:37
MySQL
Ram1979, 2019-08-25 16:01:37

How to get below result?

My Laeavel 5.8 ->  query:

Table id int AUTO_INCREMENT
group_id int
coeff_id int
coeff VARCHAR(255)

$guery= DB::table('posts')
            ->select(DB::raw('count(*) as count, group_id'))
            ->groupBy('group_id')
             ->get()->toArray();




I get just below.
Array
    (
        [0] => stdClass Object
            (
                [count] => 5
                [group_id] => 1
            )

            [1] => stdClass Object
                (
                    [count] => 5
                    [group_id] => 2
                )

But i want get some thing like below

Array
    (
        [0] => stdClass Object
            (
                [count] => 5
                [group_id] => 1
                [coeff_id]=> 1
                [coef] => 0.005
            )

        [1] => stdClass Object
            (
                [count] => 5
                [group_id] => 2
                [coeff_id]=> 2
                [coef] => 0.005
                )

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
oleg_ods, 2019-08-25
@oleg_ods

Add the fields you need to the select.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question