How to group By counting with TypeOrm Repository help me

QUERYBUILDERR:

const res = await this.jobViewsRepository.createQueryBuilder('jobViews')           
    .addSelect("COUNT(jobViews.user_id) AS jobViews_total_count" )
    .leftJoinAndSelect(Jobs, "jobs", "jobs.id = jobViews.job_id")
    .where("jobs.user_id != :id", { id: user_id })        
    .groupBy("jobViews.job_id")**
    .orderBy('jobViews_total_count', 'DESC')**
    .limit(limit)
    .offset(offset)           
    .getRawMany();

FINDOPTION:

 const result = await this.jobViewsRepository.find({
        relations: ["jobs"],
        loadEagerRelations: true,  
        order: { id: "DESC" },
        skip: offset,
        take: limit,
    }
    );

DATABSE: mysql same question with: Is there a way I can use Group By and Count with Type Orm Repository but it has no answer



Read more here: https://stackoverflow.com/questions/64891948/how-to-group-by-counting-with-typeorm-repository-help-me

Content Attribution

This content was originally published by MRCC at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: