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 > prefix best match
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
prefix best match

Réponse
 
LinkBack Outils de la discussion
Vieux 30/10/2007, 03h04   #1
Oliver
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut prefix best match

Hi,

I have a table containing calls to different destinations, and a table
with cost and prefixes.
I would like to select just the best match prefix for any given call
(e.g. for the call with dst 123, the prefix 12 and the prefix 1 would
both match, but 123 would be the best match)

These are the tables which I'm testing with

calls
+---------------------+--------+-----+---------+
| calldate | callid | dst | billsec |
+---------------------+--------+-----+---------+
| 0000-00-00 00:00:00 | 1 | 123 | 40 |
| 0000-00-00 00:00:00 | 2 | 123 | 240 |
| 0000-00-00 00:00:00 | 3 | 123 | 245 |
| 0000-00-00 00:00:00 | 4 | 123 | 0 |
+---------------------+--------+-----+---------+

tariff
+-------------+--------+------+
| destination | prefix | cost |
+-------------+--------+------+
| Cost 1 | 1 | 50 |
| Cost 2 | 12 | 50 |
| Cost | 234 | 100 |
+-------------+--------+------+



Any suggestion how I can do this?

Thakns,
Oliver

  Réponse avec citation
Vieux 30/10/2007, 09h49   #2
Pavel Lepin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: prefix best match


Oliver <oli77za@yahoo.co.uk> wrote in
<1193706246.690698.301340@d55g2000hsg.googlegroups .com>:
> I have a table containing calls to different destinations,
> and a table with cost and prefixes.
> I would like to select just the best match prefix for any
> given call (e.g. for the call with dst 123, the prefix 12
> and the prefix 1 would both match, but 123 would be the
> best match)
>
> These are the tables which I'm testing with


[snip]

There's probably a better solution, but a quick hack would
be:

SELECT *
FROM
calls AS c LEFT JOIN
(SELECT
pc.callid,MIN(LENGTH(pt.prefix)) AS l
FROM
calls AS pc LEFT JOIN
tariff AS pt ON LOCATE(pt.prefix,pc.dst)=1
GROUP BY pc.callid
) AS pl ON c.callid=pl.callid LEFT JOIN
tariff AS t ON
LOCATE(t.prefix,c.dst)=1 AND LENGTH(t.prefix)=pl.l;

--
It is rare to find learned men who are clean, do not stink,
and have a sense of humour. -- Liselotte in a letter to
Sophie, 30 Jul 1705
  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 00h37.


É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,11498 seconds with 10 queries