0

let's say I have a table called transaction and it looks like this

ID   Price
--- ----------- 
706         117.94       
707         151.60       
708         185.29       
719         117.94       
711         195.85      

If Price column's type were varchar, then I could select entries by part of Price values.

For example, if I did:

 select * from transaction where Price like '%51%'

and I would get

707 151.60

However the Price column's type is numeric. How can I select entries by part of a numeric value?

5
  • What? Commented Mar 20, 2014 at 19:17
  • @Szymon no one said anything about SQL Server Commented Mar 20, 2014 at 19:19
  • 2
    What DBMS are you using? As @Alexander has pointed out, your query is perfectly valid in MySQL even if the column type were numeric. Commented Mar 20, 2014 at 19:21
  • 1
    Right, that's actually valid in SQL Server as well... Commented Mar 20, 2014 at 19:24
  • I bet this wasn't actually tried :) Commented Mar 20, 2014 at 19:30

1 Answer 1

3

MySQL
SQL Server
Oracle
SQLite

Everyone of them supports LIKE on numbers.
It appears to be PostgreSQL you are using. With PostgreSQL we actually need to change datatype:

SELECT * FROM transaction1 WHERE CAST(Price AS text) LIKE '%51%';

PostgreSQL

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.