🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: chile.comp.programacion
Article #3308

Re: consulta mysql

#3308
From: Jos� Miguel Santib��ez
Date: Fri, 08 Apr 2005 06:05
85 lines
3522 bytes
En el cap�tulo anterior (news:d356cj$l4q$1@news1.nivel5.cl), "Rick_oj"
<rick_oj@[sin-esto]tutopia.com> dijo: 

> En las news:Xns9632115AD8204jmsnews@200.27.221.71, a Jos� Miguel
> Santib��ez se le ocurrio
> tipear:
>> En el cap�tulo anterior (news:d34hfe$e77$1@news1.nivel5.cl),
>> "Rick_oj" <rick_oj@[sin-esto]tutopia.com> dijo:
>>
>>> tengo la siguiente situacion (parecida)
>>> una tabla con compras por clientes para dicho articulo
>>> como puedo seleccionar que clientes no compro el articulo x,
>>> existe un where not? (toy medio oxidado con bdd)
>>>
>>>
>>
>> algo as�:
>>
>> CREATE TABLE `master` (
>>   `numero` varchar(20) NOT NULL default '0',
>>   `cliente` tinytext NOT NULL,
>>   `fecha` tinytext,
>>   PRIMARY KEY  (`numero`),
>>   KEY `numero` (`numero`)
>> );
>>
>> INSERT INTO `master` (`numero`, `cliente`, `fecha`)
>>  VALUES ('v1', 'lala', '2005-04-08'),
>>         ('v2', 'lele', '2005-04-08'),
>>         ('v3', 'lili', '2005-04-08'),
>>         ('v4', 'lolo', '2005-04-08');
>>
>>
>> CREATE TABLE `detalle` (
>>   `numero` varchar(20) NOT NULL default '0',
>>   `producto` int(11) NOT NULL default '0',
>>   `cantidad` tinyint(4) NOT NULL default '1',
>>   `precio` int(11) default NULL,
>>   PRIMARY KEY  (`numero`,`producto`),
>>   KEY `numprod` (`numero`,`producto`),
>>   KEY `producto` (`producto`)
>> );
>>
>> INSERT INTO `detalle` (`numero`, `producto`, `cantidad`, `precio`)
>>  VALUES ('v1', 1, 1, 10),
>>         ('v1', 2, 1, 10),
>>         ('v1', 3, 1, 10),
>>         ('v2', 1, 1, 10),
>>         ('v3', 1, 1, 10),
>>         ('v3', 2, 1, 10),
>>         ('v4', 2, 1, 10),
>>         ('v4', 3, 10, 100);
>>
>>
>> SELECT cliente
>> FROM master left join detalle on master.numero = detalle.numero
>>      and producto=3
>> where producto is null
>>
>> resultado:
>>
>> lele y lili
> 
>  con solo una tabla no se puede? si producto is not null en la tabla
>  como 
> puede el select ser where is null, me quedo esa duda mirando el manual
> de mysql (hace demasiado que vi sql)
> 
> 

A ver, si lo quieres hacer usando solo la tabla detalle (agreg�ndo ah� el 
cliente):

SELECT distinct t1.numero
FROM detalle AS t1
LEFT  JOIN detalle AS t2 ON t1.numero = t2.numero AND t2.producto =3
WHERE t2.producto IS  NULL 

(claro que tendr�a que ser t1.cliente, pero no quise cambiarlo para que 
funcione con lo de arriba)

-- 
                           Jose M. Santiba�ez A.
                             <jms@nivel5.cl>
                           <http://caos.cl/jms>
Technical Details
Message-ID: <Xns963215357D2F6jmsnews@200.27.221.71>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!nntp-server.pubsub.com!news1.nivel5.cl!news.vcd.cl!not-for-mail
References: <d34hfe$e77$1@news1.nivel5.cl> <Xns9632115AD8204jmsnews@200.27.221.71> <d356cj$l4q$1@news1.nivel5.cl>

Show Full Headers
Complete Article Headers
X-Google-Thread: 1593cb,9070da774c101bc6
X-Google-Attributes: gid1593cb,public
X-Google-Language: SPANISH,ASCII
Newsgroups: chile.comp.programacion
Subject: Re: consulta mysql
From: "Jos� Miguel Santib��ez" <jms@nospam.nivel5.cl>
References: <d34hfe$e77$1@news1.nivel5.cl> <Xns9632115AD8204jmsnews@200.27.221.71> <d356cj$l4q$1@news1.nivel5.cl>
Organization: Caos Consultores
Message-ID: <Xns963215357D2F6jmsnews@200.27.221.71>
User-Agent: Xnews/5.04.25
X-Face: +|NgjgFM{<rs%\Q|vUu16]a6,}?MJTA<!PEEI+x&Gw-Gyq+?$}fvo+.(,-r;)~Qzn)#{{nxU,OT?w^s<7m4ckCJ*L$c#I)yHL7b)GdU*#l
NNTP-Posting-Host: 61-58-112.adsl.terra.cl
Date: 8 Apr 2005 02:05:18 -0400
X-Trace: news.vcd.cl!not-for-mail 1112936718 61-58-112.adsl.terra.cl (8 Apr 2005 02:05:18 -0400)
Lines: 85
X-Authenticated-User: jms
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!nntp-server.pubsub.com!news1.nivel5.cl!news.vcd.cl!not-for-mail