Like command in SQL

I want to conduct a search in SQL table using like command.
With the content is 250.xx, it is easy, like:
select count(number) from table1 where value1 like '250%'

With (410.xx-414.xx), I can use:
select count(number) from table1 where value1 like '41[0-4]%'

But I have problem conduct it on these below range:
range1 (491,491.0-491.9,492,492.0,492.8, or 496);
range2 ( 398.91,402.01,401.11,402.91,428.xx);
range3 (401.00, 401.1, or 401.9 and without range2)

Could you please help me in these ones.

Thank you very much!

YANKAUSKASAsked:
Who is Participating?
 
cyberkiwiConnect With a Mentor Commented:
For range3, there is no overlap with range2, so why even include range 2? Unless range2:401.11 is included in range3:401.1.  Again, since you have removed % from most of your conditions, I don't think range3:401.1 is supposed to mean like '401.1%' so there is no overlap.

So range3 should just be
where diag1 in ('401.00', '401.1', '401.9')

You can use IN when using exact values and don't need LIKE.
0
 
BuggyCoderCommented:
kindly elaborate, can't really get your question.
Are these ranges in table columns, if yes then what are you trying to search for???
0
 
YANKAUSKASAuthor Commented:
No, this range is the value inside each cell of table. Please read the like here:
http://www.sql-tutorial.net/SQL-LIKE.asp
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
YANKAUSKASAuthor Commented:
I want to count all the cell (according the id) which has value range inside these value: 491,491.0-491.9,492,492.0,492.8, or 496, for example.
0
 
BuggyCoderCommented:
could you please share some of your data with the specified ranges.
0
 
YANKAUSKASAuthor Commented:
If it is in a consecutive range from 491 to 497 I can use  49[1-7], but its value is omitted at some point. So how can I change the like command.
Do you get my question?
0
 
BuggyCoderCommented:
see if it is integer or numeric data why are you not going for between clause.
like should be applied if the data is varchar. if you can do comparisons by coverting the data in numeric(signed/unsigned), one should use between and other arithmetic operators
0
 
YANKAUSKASAuthor Commented:
Whenever is Ok, whenever the value inside these range, I will count it.
 491
491.0-491.9,
492
492.0
492.8
496

Outside, do not count, for example 492.0 and 492.8 count but 492.6 492.7 does not count.

I think that I explain my question enough to understand.
0
 
YANKAUSKASAuthor Commented:
Yes, I have done with consecutive value, but with discrete value, I don't know how to deal with. And because the value may have some form like 492.8. AFAIK, between is only for integer, right?
0
 
BuggyCoderCommented:
select * from sometable where cast(float,value)=491 or cast(float,value) between 491.0 and 491.9

and so on
0
 
YANKAUSKASAuthor Commented:
Sorry but your query didn't work. I do not want to risk y count all the value inside a range while some value may different. I still need some solution using "like" or specify the exact value instead.
Thanks
0
 
cyberkiwiCommented:
first range:
select count(number) from table1
where value1 like '491' or value1 like '418.[0-9]%'
   or value1 like '492' or value1 like '492.[0-8]%'
   or value1 like '496'
0
 
cyberkiwiCommented:
Is that what you are after?

> range1 (491,491.0-491.9,492,492.0,492.8, or 496);

It is not immediately obvious whether you wanted to include
491.02,
491.0 (exactly)
491 (exactly)
491.xx (will there be alpha?)
491.93 (491.93 is outside of 491.0 and 491.9 as a numeric range, but does 491.9 mean 491.9-anything?)
etc

You need to be very clear with your question
0
 
YANKAUSKASAuthor Commented:
Yes, cyberwiki, you seem correct. I have done with this so far, just a little:
I just need to specify the value and connect it using or, that's all I need, it's not so complicate I think.

range1 (491,491.0-491.9,492,492.0,492.8, or 496);
select sum(something) as sumtot from table1 where diag1 = '491' or diag1 like '491.[0-9]' or diag1 = '492' or diag1 = '492.0' or diag1 = '492.8' or diag1 = '496'

range2 ( 398.91,402.01,401.11,402.91,428.xx);
select sum(something) as sumtot from table1 where diag1 = '398.91' or diag1 = '402.01' or diag1 = '401.11' or diag1 = '402.91' or diag1 like '428%'



range3 (401.00, 401.1, or 401.9 and without range2) with range2 is ( 398.91,402.01,401.11,402.91,428.xx);

This query below does not works, please help me fix it cyberwiki:


select count(distinct something) from table1 where diag1 = '401.00' or diag1 = '401.1' or diag1 = '401.9' and diag1 <> '398.91' and diag1 <> '402.01' and diag1 <> '401.11' and diag1 <> '402.91' and diag1 not like '428%'

Open in new window

0
 
YANKAUSKASAuthor Commented:
Thank you, I have done it.
0
All Courses

From novice to tech pro — start learning today.