PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.databases.mysql > A thorny SQL question...
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
A thorny SQL question...

Réponse
 
LinkBack Outils de la discussion
Vieux 12/02/2008, 00h32   #1
Deane
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut A thorny SQL question...

(Sorry about the vague title, but I couldn't think of a title that
even remotely fit this situation.)

Consider a table with single column, consisting of URL paths in a
VARCHAR field, like this:

/animals/domesticated/cats
/animals/domesticated/dogs

However, say a directory can be "wildcarded" with a star, like this:

/animals/*/cats
/animals/*/dogs

If we select all four of the above URLs in a single statement, I want
to order them **as if the directories were in different cells and I
ordered ascending from the first cell, down to the last.**

So I want those URLs back like this --

/animals/*/cats
/animals/domesticated/cats
/animals/*/dogs
/animals/domesticated/dogs

-- since "*" (star) comes before the "d" in "domesticated." Put
another way, I want SQL to evaluate the second directory in the string
as a single value bound by the slashes ("*" or "domesticated") rather
than a collection of characters.

Effectively, I want to replicate the result that would occur if I had
the data organized into different cells like this --

field1 | field2 | field 3
----------------------------------
animals | * | cats
animals | * | dogs
animals | domesticated | cats
animals | domesticated | dogs

-- then had this on my SQL: "ORDER BY field1, field2, field3".

Possible?
  Réponse avec citation
Vieux 12/02/2008, 01h22   #2
Michael Austin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: A thorny SQL question...

Deane wrote:
> (Sorry about the vague title, but I couldn't think of a title that
> even remotely fit this situation.)
>
> Consider a table with single column, consisting of URL paths in a
> VARCHAR field, like this:
>
> /animals/domesticated/cats
> /animals/domesticated/dogs
>
> However, say a directory can be "wildcarded" with a star, like this:
>
> /animals/*/cats
> /animals/*/dogs
>
> If we select all four of the above URLs in a single statement, I want
> to order them **as if the directories were in different cells and I
> ordered ascending from the first cell, down to the last.**
>
> So I want those URLs back like this --
>
> /animals/*/cats
> /animals/domesticated/cats
> /animals/*/dogs
> /animals/domesticated/dogs
>
> -- since "*" (star) comes before the "d" in "domesticated." Put
> another way, I want SQL to evaluate the second directory in the string
> as a single value bound by the slashes ("*" or "domesticated") rather
> than a collection of characters.
>
> Effectively, I want to replicate the result that would occur if I had
> the data organized into different cells like this --
>
> field1 | field2 | field 3
> ----------------------------------
> animals | * | cats
> animals | * | dogs
> animals | domesticated | cats
> animals | domesticated | dogs
>
> -- then had this on my SQL: "ORDER BY field1, field2, field3".
>
> Possible?


select field1, field2, field3 from table where field1 = 'animals' and
field3 in ('cats','dogs');

or if it is a single field as in your initial query

where field1 like '/animals/%/cats' or field1 like '/animals/%/dogs'

or more broadly:

where field1 like '%/cats' or field1 like '%/dogs'
  Réponse avec citation
Vieux 12/02/2008, 02h33   #3
Michael Austin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: A thorny SQL question...

Deane wrote:
> (Sorry about the vague title, but I couldn't think of a title that
> even remotely fit this situation.)
>
> Consider a table with single column, consisting of URL paths in a
> VARCHAR field, like this:
>
> /animals/domesticated/cats
> /animals/domesticated/dogs
>
> However, say a directory can be "wildcarded" with a star, like this:
>
> /animals/*/cats
> /animals/*/dogs
>
> If we select all four of the above URLs in a single statement, I want
> to order them **as if the directories were in different cells and I
> ordered ascending from the first cell, down to the last.**
>
> So I want those URLs back like this --
>
> /animals/*/cats
> /animals/domesticated/cats
> /animals/*/dogs
> /animals/domesticated/dogs
>
> -- since "*" (star) comes before the "d" in "domesticated." Put
> another way, I want SQL to evaluate the second directory in the string
> as a single value bound by the slashes ("*" or "domesticated") rather
> than a collection of characters.
>
> Effectively, I want to replicate the result that would occur if I had
> the data organized into different cells like this --
>
> field1 | field2 | field 3
> ----------------------------------
> animals | * | cats
> animals | * | dogs
> animals | domesticated | cats
> animals | domesticated | dogs
>
> -- then had this on my SQL: "ORDER BY field1, field2, field3".
>
> Possible?



or look at some of the examples at:
http://dev.mysql.com/doc/refman/5.0/...functions.html

to extract and "split" your data...
  Réponse avec citation
Vieux 12/02/2008, 05h58   #4
Deane
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: A thorny SQL question...

On Feb 11, 6:22 pm, Michael Austin <maus...@firstdbasource.com> wrote:
> Deane wrote:
> > (Sorry about the vague title, but I couldn't think of a title that
> > even remotely fit this situation.)

>
> > Consider a table with single column, consisting of URL paths in a
> > VARCHAR field, like this:

>
> > /animals/domesticated/cats
> > /animals/domesticated/dogs

>
> > However, say a directory can be "wildcarded" with a star, like this:

>
> > /animals/*/cats
> > /animals/*/dogs

>
> > If we select all four of the above URLs in a single statement, I want
> > to order them **as if the directories were in different cells and I
> > ordered ascending from the first cell, down to the last.**

>
> > So I want those URLs back like this --

>
> > /animals/*/cats
> > /animals/domesticated/cats
> > /animals/*/dogs
> > /animals/domesticated/dogs

>
> > -- since "*" (star) comes before the "d" in "domesticated." Put
> > another way, I want SQL to evaluate the second directory in the string
> > as a single value bound by the slashes ("*" or "domesticated") rather
> > than a collection of characters.

>
> > Effectively, I want to replicate the result that would occur if I had
> > the data organized into different cells like this --

>
> > field1 | field2 | field 3
> > ----------------------------------
> > animals | * | cats
> > animals | * | dogs
> > animals | domesticated | cats
> > animals | domesticated | dogs

>
> > -- then had this on my SQL: "ORDER BY field1, field2, field3".

>
> > Possible?

>
> select field1, field2, field3 from table where field1 = 'animals' and
> field3 in ('cats','dogs');
>
> or if it is a single field as in your initial query
>
> where field1 like '/animals/%/cats' or field1 like '/animals/%/dogs'
>
> or more broadly:
>
> where field1 like '%/cats' or field1 like '%/dogs'


I don't want specific rows. I want the all records in the table,
ordered as I specified.

Deane
  Réponse avec citation
Vieux 12/02/2008, 09h59   #5
Luuk
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: A thorny SQL question...

Deane schreef:
> (Sorry about the vague title, but I couldn't think of a title that
> even remotely fit this situation.)
>
> Consider a table with single column, consisting of URL paths in a
> VARCHAR field, like this:
>
> /animals/domesticated/cats
> /animals/domesticated/dogs
>
> However, say a directory can be "wildcarded" with a star, like this:
>
> /animals/*/cats
> /animals/*/dogs
>
> If we select all four of the above URLs in a single statement, I want
> to order them **as if the directories were in different cells and I
> ordered ascending from the first cell, down to the last.**
>
> So I want those URLs back like this --
>
> /animals/*/cats
> /animals/domesticated/cats
> /animals/*/dogs
> /animals/domesticated/dogs
>
> -- since "*" (star) comes before the "d" in "domesticated." Put
> another way, I want SQL to evaluate the second directory in the string
> as a single value bound by the slashes ("*" or "domesticated") rather
> than a collection of characters.
>
> Effectively, I want to replicate the result that would occur if I had
> the data organized into different cells like this --
>
> field1 | field2 | field 3
> ----------------------------------
> animals | * | cats
> animals | * | dogs
> animals | domesticated | cats
> animals | domesticated | dogs
>
> -- then had this on my SQL: "ORDER BY field1, field2, field3".
>
> Possible?


"ORDER BY CONCAT(field1, '/', field2, '/', field3)"
will do the same ordering as in your 1st example

--
Luuk
  Réponse avec citation
Vieux 12/02/2008, 10h15   #6
Rik Wasmus
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: A thorny SQL question...

On Tue, 12 Feb 2008 00:32:34 +0100, Deane <deane.barker@gmail.com> wrote:

> (Sorry about the vague title, but I couldn't think of a title that
> even remotely fit this situation.)
>
> Consider a table with single column, consisting of URL paths in a
> VARCHAR field, like this:
>
> /animals/domesticated/cats
> /animals/domesticated/dogs
>
> However, say a directory can be "wildcarded" with a star, like this:
>
> /animals/*/cats
> /animals/*/dogs
>
> If we select all four of the above URLs in a single statement, I want
> to order them **as if the directories were in different cells and I
> ordered ascending from the first cell, down to the last.**
>
> So I want those URLs back like this --
>
> /animals/*/cats
> /animals/domesticated/cats
> /animals/*/dogs
> /animals/domesticated/dogs
>
> -- since "*" (star) comes before the "d" in "domesticated." Put
> another way, I want SQL to evaluate the second directory in the string
> as a single value bound by the slashes ("*" or "domesticated") rather
> than a collection of characters.
>
> Effectively, I want to replicate the result that would occur if I had
> the data organized into different cells like this --
>
> field1 | field2 | field 3
> ----------------------------------
> animals | * | cats
> animals | * | dogs
> animals | domesticated | cats
> animals | domesticated | dogs
>
> -- then had this on my SQL: "ORDER BY field1, field2, field3".


It would be much simpler if it wasn't a 'set' string of '/animals/*/cats',
but some hierarchical table. Splitting strings is quite cumbersome in
MySQL. Would having a seperate hierachical table be possible?
--
Rik Wasmus
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 01h55.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,15512 seconds with 14 queries