PHWinfo banniere

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

Réponse
 
LinkBack Outils de la discussion
Vieux 14/10/2007, 13h13   #1
Anders Norrbring
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut with query...

I'm trying to set up a query, but I don't really get the result I
expected, so can someone please me out here?

The query I've built is this:

SELECT a1.username FROM accountuser AS a1
LEFT JOIN (freeaccounts AS f1, payments AS p1)
ON (a1.username = p1.username
AND p1.username = f1.username)
WHERE a1.username LIKE 'cit%'
AND a1.imp + a1.pp + a1.se + a1.auth != 0
AND (f1.free IS NULL OR f1.free = false)
AND (p1.validdate < UNIX_TIMESTAMP(NOW()) OR p1.validdate IS NULL)

The accountuser table is always fully populated.
The freeaccounts and payments tables are only occupied with the
'username' field if it's been used previously, so they may not contain
any data.

What I expect to get from the query is 'username' from the accountuser
table when:

The a1.username starts with 'cit',
AND
Any of a1.imp, a1.pp, a1.se or a1.auth is not 0,
AND
f1.free is either not populated or false.
AND
p1.validdate is either not populated, or the timestamp is before NOW.

Everything seems to work except for the passed time check. If I set
p1.validdate to a timestamp for something next week, the username is
still returned in the result.

Grateful for any hints...
Anders.

  Réponse avec citation
Vieux 14/10/2007, 16h48   #2
mysql@subtropolix.org
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: with query...

Anders Norrbring wrote:
> I'm trying to set up a query, but I don't really get the result I
> expected, so can someone please me out here?
>
> The query I've built is this:
>
> SELECT a1.username FROM accountuser AS a1
> LEFT JOIN (freeaccounts AS f1, payments AS p1)
> ON (a1.username = p1.username
> AND p1.username = f1.username)
> WHERE a1.username LIKE 'cit%'
> AND a1.imp + a1.pp + a1.se + a1.auth != 0
> AND (f1.free IS NULL OR f1.free = false)
> AND (p1.validdate < UNIX_TIMESTAMP(NOW()) OR p1.validdate IS NULL)
>
> The accountuser table is always fully populated.
> The freeaccounts and payments tables are only occupied with the
> 'username' field if it's been used previously, so they may not contain
> any data.
>
> What I expect to get from the query is 'username' from the accountuser
> table when:
>
> The a1.username starts with 'cit',
> AND
> Any of a1.imp, a1.pp, a1.se or a1.auth is not 0,
> AND
> f1.free is either not populated or false.
> AND
> p1.validdate is either not populated, or the timestamp is before NOW.
>
> Everything seems to work except for the passed time check. If I set
> p1.validdate to a timestamp for something next week, the username is
> still returned in the result.
>


Put the last line (the tests on p1.validdate) in the JOIN condition instead.

brian
  Réponse avec citation
Vieux 14/10/2007, 18h54   #3
Anders Norrbring
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut SV: with query...


> Hello
> where is the FROM for f1 table?
> Martin--


Why would there be any "FROM" for the f1 table? It's not needed in the result.

Anyway, I've come up with a query that actually seems to do what I'm looking for;

SELECT a1.username FROM accountuser AS a1
LEFT JOIN payments AS p1 ON (a1.username = p1.username)
LEFT JOIN freeaccounts AS f1 ON (a1.username = f1.username)
WHERE a1.username LIKE 'cit%'
AND a1.imp + a1.pp + a1.se + a1.auth != 0
AND (p1.validdate < UNIX_TIMESTAMP(NOW()) OR p1.validdate IS NULL)
AND (f1.free = false OR f1.free IS NULL)

Thanks for the hints, you who gave them..

Anders.

> ----- Original Message -----
> From: "Anders Norrbring" <lists@norrbring.se>
> To: <mysql@lists.mysql.com>
> Sent: Sunday, October 14, 2007 7:13 AM
> Subject: with query...
>
>
> > I'm trying to set up a query, but I don't really get the result I
> > expected, so can someone please me out here?
> >
> > The query I've built is this:
> >
> > SELECT a1.username FROM accountuser AS a1
> > LEFT JOIN (freeaccounts AS f1, payments AS p1)
> > ON (a1.username = p1.username
> > AND p1.username = f1.username)
> > WHERE a1.username LIKE 'cit%'
> > AND a1.imp + a1.pp + a1.se + a1.auth != 0
> > AND (f1.free IS NULL OR f1.free = false)
> > AND (p1.validdate < UNIX_TIMESTAMP(NOW()) OR p1.validdate IS NULL)
> >
> > The accountuser table is always fully populated.
> > The freeaccounts and payments tables are only occupied with the
> > 'username' field if it's been used previously, so they may not

> contain
> > any data.
> >
> > What I expect to get from the query is 'username' from the

> accountuser
> > table when:
> >
> > The a1.username starts with 'cit',
> > AND
> > Any of a1.imp, a1.pp, a1.se or a1.auth is not 0,
> > AND
> > f1.free is either not populated or false.
> > AND
> > p1.validdate is either not populated, or the timestamp is before NOW.
> >
> > Everything seems to work except for the passed time check. If I set
> > p1.validdate to a timestamp for something next week, the username is
> > still returned in the result.
> >
> > Grateful for any hints...
> > Anders.
> >
> >
> > --
> > MySQL General Mailing List
> > For list archives: http://lists.mysql.com/mysql
> > To unsubscribe:

> http://lists.mysql.com/mysql?unsub=mgainty@hotmail.com
> >
> >


  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 05h14.


Édité par : vBulletin® version 3.7.4
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,09750 seconds with 11 queries