SFAH
SFAH

Reputation: 644

JPA Repository : How to multiply column value by parameter value

I Want to multiply the value of moving from database by 'km' value from parameter and the return the result , When I am using the following query it gives me an error that parameter[1] with that point didnot exist

Please help how can I calculate calue ?

public interface FareRateRepository  extends JpaRepository<FareRate, Long>{

    @Query("select f.moving* :km from FareRate f where f.id=1" )
    float  calculateFare(@Param("km") Long km);

}

Upvotes: 1

Views: 2292

Answers (2)

Try this

@Query(value = "select ( f.moving * ?1 ) as fare from FareRate f where f.id=1", nativeQuery = true )
float  calculateFare(Long km);

NOTE : You have to specify the actual table name instead of FareRate in the query. And this will run a native query.

Upvotes: 0

Zeromus
Zeromus

Reputation: 4542

you missed the ":"

select f.moving* :km from FareRate f where f.id=1

Upvotes: 2

Related Questions