Coder Social home page Coder Social logo

Comments (6)

vincentlauvlwj avatar vincentlauvlwj commented on August 22, 2024

Try this:

val score = match(Articles.body).against("mysql tutorial", SearchModifier.IN_BOOLEAN_MODE).cast(FloatSqlType)

val query = Articles
    .select(Articles.id, Articles.body, score)
    .having { score greater 0F }
    .orderBy(score.desc())

from ktorm.

schmeic avatar schmeic commented on August 22, 2024

That doesn't work, the match against sql is used in both the having and order by clauses. Like this:

having (match (articles.body) against (? in boolean mode)) > ? order by match (articles.body) against (? in boolean mode)

and there is no AS score in the SELECT part of the sql.

from ktorm.

schmeic avatar schmeic commented on August 22, 2024

Also, what would be the best way to include all of the columns from one table, plus something like this score calculation without having to explicitly list each column? I'd like to be able to do something like this:

select(Articles.columns, score)

from ktorm.

vincentlauvlwj avatar vincentlauvlwj commented on August 22, 2024

Also, what would be the best way to include all of the columns from one table, plus something like this score calculation without having to explicitly list each column? I'd like to be able to do something like this:

select(Articles.columns, score)

You can use the plus operator for collections:

select(Articles.columns + score)

from ktorm.

vincentlauvlwj avatar vincentlauvlwj commented on August 22, 2024

That doesn't work, the match against sql is used in both the having and order by clauses. Like this:

having (match (articles.body) against (? in boolean mode)) > ? order by match (articles.body) against (? in boolean mode)

and there is no AS score in the SELECT part of the sql.

Actually, the AS operator is currently not supported.

Thanks for your feedback. I'm working on it.

from ktorm.

vincentlauvlwj avatar vincentlauvlwj commented on August 22, 2024

Ktorm 2.6 released. Now, we can assign aliases to the selected columns of a query and use them in subsequent clauses such as group by and having, just like the as keyword in SQL. Here is an example. This query selects departments whose average salary is greater than 100, then returns the average salaries along with their department’s IDs.

val deptId = Employees.departmentId.aliased("dept_id")
val salaryAvg = avg(Employees.salary).aliased("salary_avg")

Employees
    .select(deptId, salaryAvg)
    .groupBy(deptId)
    .having { salaryAvg greater 100.0 }
    .forEach { row ->
        println("${row[deptId]}:${row[salaryAvg]}")
    }

Generated SQL:

select t_employee.department_id as dept_id, avg(t_employee.salary) as salary_avg 
from t_employee 
group by dept_id 
having salary_avg > ?

from ktorm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.