question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Syntax for COUNT(), AVG() and SUM()

See original GitHub issue

I didn’t find any docs for operations like count(), avg(), sum(). Something like:

const productCount = await this.productRepository.count({ accountId });
const itemCount = await this.productRepository.find({accountId}).sum("items");

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:12
  • Comments:18 (2 by maintainers)

github_iconTop GitHub Comments

65reactions
ahmadalfycommented, Jun 30, 2020

The current version of typeorm now supports count. This will work

const productCount = await this.productRepository.count({ accountId });
60reactions
greg-murray-volusioncommented, Dec 5, 2018

use query builder to build any sql you need and get raw results. Something like:

let [sum] = await context.locations
            .createQueryBuilder("location")
            .select("SUM(location.something)", "sum")
            .getRawOne(); 

I think this one should be

let { sum } = await ...
Read more comments on GitHub >

github_iconTop Results From Across the Web

SQL COUNT(), AVG() and SUM() Functions - W3Schools
The COUNT() function returns the number of rows that matches a specified criterion. COUNT() Syntax. SELECT COUNT(column_name) FROM table_name. WHERE condition;.
Read more >
SQL COUNT(), AVG() and SUM() - GeeksforGeeks
SQL COUNT() Function : The COUNT() function provides the number of rows that matches a specified condition. COUNT() Syntax – ; SQL AVG()...
Read more >
SQL SELECT COUNT | SUM | AVG - Dofactory
COUNT, SUM, and AVG are aggregate functions. COUNT returns a count of the number of data values. SUM returns the sum of the...
Read more >
SQL Count – How to Select, Sum, and Average Rows in SQL
The AVG function finds the arithmetic mean for a group of records in a SQL table. An average, or arithmetic mean, is the...
Read more >
SQL Aggregate Functions: SUM(), COUNT(), AVG(), Functions
The AVG() function calculates the average of a set of values. Syntax: AVG(). or. AVG( [ALL|DISTINCT] expression ). Example: The following SQL ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found