S
S
StimulJet2022-03-30 01:03:02
MySQL
StimulJet, 2022-03-30 01:03:02

How to get the difference of two fields of a Laravel table?

Hello. I have a task of such a plan. There is a number (for example, 5000) and there is a table with data, in the rows there are balance and revers fields in each of these number fields, for example, in the balance field the value is 10000, and in the revers field the value is 20000 and I need to get exactly those rows with one query to the table where the difference between balance and revers is greater than or equal to 5000. Thank you in advance for your answer. Laravel 4.2 framework

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
StimulJet, 2022-03-30
@StimulJet

Guys, help at least with a raw request. I can't figure out how to implement it at all.
Did

SELECT *, reverse - balance AS result FROM purses order by result where result > 5000

gives an error
Error in query (1064): Syntax error near 'where > 10000' at line 1
The same if instead of where I put having

T
ThunderCat, 2022-03-30
@ThunderCat

$result = Dok::selectRaw('(balance - revers) as results')->where('results', '>',  5000)->orderBy('results', 'desc')->get();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question