Re: MySQL Regular expression

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Owen

You can actually do it in MySQL..using the SUBSTRING_INDEX function -

SUBSTRING_INDEX(str,delim,count)
If your count is positive, SUBSTRING_INDEX returns everything to the left of
the count occurence of the delimiter (counting from left)

If count is negative, SUBSTRING_INDEX returns everything to the right of the
count occurence of the delimiter (counting from right)

Therefore say your field name is price and you want week five's price, you
would do the select like so:

SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(price, ',', 5), ',', -1)

And this will return only week 5's price



HTH

Rory McKinley
Nebula Solutions
+27 82 857 2391
rorym@nebula.co.za
"There are 10 kinds of people in this world,
those who understand binary and those who don't" (Unknown)

----- Original Message ----- 
From: "O Franssen" <twisteddesign@eircom.net>
To: <php-db@lists.php.net>
Sent: Thursday, October 09, 2003 1:49 PM
Subject:  MySQL Regular expression


> I'm not a 100% sure if this is the correct list for the following
> question, so I shall apologise beforehand if I upset any one.
>
> Now, I have a field in my database table in the following format:
>
> 100,30,443, etc.
> Representing prices for 52(53) weeks of the year and comma delimited.
>
> Now I need to check the price for a given week within my query.
> The problem however is that the week number is variable.
>
> Is there a way to count the number of non-consecutive occurances of a
> character, in this case commas, in a regular expression?
>
> I know ,{#} will check for # occurances of consecutive occurances of
> #, but is there a similar way to check for non-consecutive?
>
> Thank you in advance.
>
> -- 
> Regards,
> Owen Franssen
> Twisted Design
>
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux