🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: chile.comp.programacion
Article #3305

Re: consulta mysql

#3305
From: Jos� Miguel Santib��ez
Date: Fri, 08 Apr 2005 05:42
61 lines
2512 bytes
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`, `fechac`)
 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

-- 
                           Jose M. Santiba�ez A.
                             <jms@nivel5.cl>
                           <http://caos.cl/jms>
Technical Details
Message-ID: <Xns9632115AD8204jmsnews@200.27.221.71>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!news.kjsl.com!news1.nivel5.cl!news.vcd.cl!not-for-mail
References: <d34hfe$e77$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>
Organization: Caos Consultores
Message-ID: <Xns9632115AD8204jmsnews@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 01:42:34 -0400
X-Trace: news.vcd.cl!not-for-mail 1112935354 61-58-112.adsl.terra.cl (8 Apr 2005 01:42:34 -0400)
Lines: 61
X-Authenticated-User: jms
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!news.kjsl.com!news1.nivel5.cl!news.vcd.cl!not-for-mail