If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Please assist with complex (to me) select conditions?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-10-06, 12:24
bobmct bobmct is offline
Registered User
 
Join Date: Jun 2006
Posts: 1
Please assist with complex (to me) select conditions?

Gentlemen;

Although I've been actually programming with MySQL for a number of years with good results I am far, far, far from a DB expert! I have a new requirement that I cannot figure out an acceptable way to achieve. I thought that some "seasoned" db person(s) would have a better idea of how I could accomplish this.

Here are some sample specs:

table column definition:

_serial varchar(60) default ' '

table row entry values for column _serial:
string value consists of 1 to n "sets" of 2-digit numbers.

1: 0002030405
2: 0102030405
3: 0103040607
4: 0203040506
5: 0004050708
6: 0400020106
7: 00060100
8: 0103050608
9: 0402101200

Search Arg:

020410

Criteria:

This argument would ONLY match row 9 even though
the number sets are not in sequence. Also note
that the number set "10" is requested and although
it appears on other rows it is NOT actually a SET
in the other rows (it is made up of one digit from
one set and another from the adjacent set.

Task:

Write a SELECT statement that will accomplish, if possible, the above criteria


I was planning on utilizing the INSTR() function either on the entire string or perhaps splitting up the argument string into 2-digit "sets" and AND'ing multiple INSTR() together but that wouldn't address the non-aligned set values (i.e.: the "set" 10).

Any help, ideas, recommendations, suggestions will be very much appreciated as I pond this problem.

Thank you,

Bob
Reply With Quote
  #2 (permalink)  
Old 06-15-06, 17:35
wanado wanado is offline
Registered User
 
Join Date: Dec 2004
Posts: 1
An idea,

U can use regex
SELECT id,_serial, if("10" REGEXP ('^([0-9][0-9])*'),"Yes","No") FROM strings
... jut some tests, not final solution (im a begginer)

or if u can build a string_format_function() that outputs the formated string
SELECT string_format_function(_serial) From table

Result "00,12,40,10,25,01,01"
then using same function to test the search string
WHERE string_format_function(_serial) LIKE string_format_function(_search_string)

something like this function
FORMAT(X,D)
Formats the number X to a format like '#,###,###.##', rounded to D decimal places, and returns the result as a string. If D is 0, the result has no decimal point or fractional part.

only put comma after 2 digits.

i'm curious about the final solution

Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On