2

How I can write query with Objection.js?

SELECT AVG(field), COUNT(*) FROM tab

Please help me

1 Answers1

2

Try this:

const result = await Tab.query().avg(`field`).count(`*`)
console.log(result[0].avg, result[0].count)
username_jj
  • 245
  • 1
  • 10
  • Hello, I see you are new to StackOverflow. Please provide some explanation when answering a question rather than just pasting the code without explanation :) – crodev Jul 01 '21 at 14:49
  • 1
    @crodev sorry for my ignorance, I thought the code itself is quite expressive, `avg()` and `count()` are built in methods provided by the library. Official doc: [https://knexjs.org/](https://knexjs.org/) – username_jj Jul 02 '21 at 06:14