Reputation: 3
I have a problem formulating a sql query. The code is used in a php script accessing a sqlite database.
What I want to do: I only want to select datasets which are over an individual offset:
select * from tab1 t, tab2 z where t.id = z.ref and (t.value - z.offset > '50')
Why doesn't this work?
I tried another way but this fails too.
select *, t.value - z.offset as diff from tab1 t, tab2 z where t.id = z.ref and ( diff > '50')
The colum diff contains the correct value, but I cannot use it in the where clause.
Any idea how to formulate this? Thanks for your help! Galeo
Upvotes: 0
Views: 34
Reputation: 13334
If t.value
and z.offset
are both of some numeric type, then re-write your last condition as (t.value - z.offset > 50)
(no apostrophes).
Your 2nd
query uses column alias in WHERE
clause which is not allowed.
Upvotes: 1