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 > combine two queries and compute from values
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
combine two queries and compute from values

Réponse
 
LinkBack Outils de la discussion
Vieux 12/10/2007, 14h26   #1
omeldoid@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut combine two queries and compute from values

i have two tables that share a field with items. i can count the
occurences for each table like "select count(item), item from items1
group by item" and the same for items2. now i want to compute the
ratio between the item count for each item from items1and items2. is
this possible in one query? if not, how would you suggest i approach
this problem? any pointers much appreciated,

andrej

  Réponse avec citation
Vieux 15/10/2007, 12h38   #2
Jack Vamvas
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: combine two queries and compute from values

Are you using stored procedures?
One approach could be:
declare 2 variables , gateher the COUNT information and then calculate ratio
Another approach is to do JOIN on the tables and calculate the ratio on the
fly

--

Jack Vamvas
___________________________________
Search IT jobs from multiple sources- http://www.ITjobfeed.com




<omeldoid@gmail.com> wrote in message
news:1192191998.860353.68470@t8g2000prg.googlegrou ps.com...
>i have two tables that share a field with items. i can count the
> occurences for each table like "select count(item), item from items1
> group by item" and the same for items2. now i want to compute the
> ratio between the item count for each item from items1and items2. is
> this possible in one query? if not, how would you suggest i approach
> this problem? any pointers much appreciated,
>
> andrej
>



  Réponse avec citation
Vieux 15/10/2007, 13h27   #3
Captain Paralytic
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: combine two queries and compute from values

On 12 Oct, 13:26, omeld...@gmail.com wrote:
> i have two tables that share a field with items. i can count the
> occurences for each table like "select count(item), item from items1
> group by item" and the same for items2. now i want to compute the
> ratio between the item count for each item from items1and items2. is
> this possible in one query? if not, how would you suggest i approach
> this problem? any pointers much appreciated,
>
> andrej


Assuming that you have some sort of primary key for these tables
(which I have called id)

SELECT
i1.item,
count( DISTINCT i1.item, i1.id ) / count( DISTINCT i2.item, i2.id )
FROM items1 i1
JOIN items2 i2 USING ( item )
GROUP BY i1.item

  Réponse avec citation
Vieux 20/10/2007, 12h49   #4
omeldoid@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: combine two queries and compute from values

On Oct 15, 1:27 pm, Captain Paralytic <paul_laut...@yahoo.com> wrote:
> SELECT
> i1.item,
> count( DISTINCT i1.item, i1.id ) / count( DISTINCT i2.item, i2.id )
> FROM items1 i1
> JOIN items2 i2 USING ( item )
> GROUP BY i1.item


thank you very much! based on your suggestion i've found the following
to do what i want (the trick is to count the dates):

select
t1.item,
count(distinct t1.date) / count(distinct t2.date)
from
items1 as t1
join
items2 as t2 using(item)
group by t1.item;

however, it is rather slow.



  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 01h04.


É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 4,24729 seconds with 12 queries