How Propel Get Sum of a column

871 Views Asked by At

I want to get query Result from a table day wise sum. In propel How get two columns date and sum(rate)

I get all the table columns instead of selected columns,

$results = VoiceQuery::create()         
    ->select(array('call_date', 'rated_units'))
    ->withColumn('call_date', 'call_date')
    ->withColumn('SUM(rated_units)', 'rated_units')
    ->filterByOriginatingCli('1300690045')
    ->filterByCallDate($week_ago_date, Criteria::GREATER_EQUAL)
    ->groupBy("call_date")
    ->limit(10);

I want only selected two columns but according to above query I get all the table columns data.

1

There are 1 best solutions below

0
Qiniso On BEST ANSWER

Try this:

VoiceQuery::create()
    ->withColumn('SUM(rated_units)', 'sum_rated_units')
    ->filterByOriginatingCli('1300690045')
    ->filterByCallDate($week_ago_date, Criteria::GREATER_EQUAL)
    ->groupBy("call_date")
    ->select(['call_date', 'sum_rated_units'])
    ->limit(10)
    ->find();