Article View: cn.comp.database
Article #67Re: 帮人问个SQL语句
From: Lee Put
Date: Thu, 29 Jun 2006 18:14
Date: Thu, 29 Jun 2006 18:14
13 lines
2213 bytes
2213 bytes
> 现在偶要得到下面查询结果 > > > ClassName ProductName > Class_a1 Product_a1, Product_a2 > Class_b1 Product_b1 > Class_c1 Product_c1, Product_c2, Product_c3 > Class_d1 > > 请问这样的SELECT语句要怎么写? 这里面你的结果要求也算是有问题的,因为SELECT的操作对象都是关系,关系本身来讲可以俗称为一张二维表,所以你的结果要求应该是: ClassName ProductName Class_a1 Product_a1 Class_a1 Product_a2 Class_b1 Product_b1 Class_c1 Product_c1 Class_c1 Product_c2 Class_c1 Product_c3 Class_d1 NULL 那么针对这个结果来讲,我们操作就可以直接用连接就行了! 如下: SELECT ClassName, ProductName FROM Class, Product WHILE Class.ClassID=Product.ClassID; 这样子可以满足上述要求了!如果你的数据库还有进下不要求的话,那么还需要进一步把SQL查询进行加工。
Technical Details
Message-ID:
<1151604847.535053.91780@m73g2000cwd.googlegroups.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!postnews.google.com!m73g2000cwd.googlegroups.com!not-for-mailReferences:
<e7d5na$s4h$1@news.yaako.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 1106d1,c944b8eba60875d8 X-Google-Attributes: gid1106d1,public X-Google-Language: Chinese,GB Path: arc1-ca.pugleaf.net!g2news2.google.com!postnews.google.com!m73g2000cwd.googlegroups.com!not-for-mail From: "Lee Put" <urgentmind@gmail.com> Newsgroups: cn.comp.database Subject: Re: 帮人问个SQL语句 Date: 29 Jun 2006 11:14:07 -0700 Organization: http://groups.google.com Lines: 14 Message-ID: <1151604847.535053.91780@m73g2000cwd.googlegroups.com> References: <e7d5na$s4h$1@news.yaako.com> NNTP-Posting-Host: 222.244.117.38 Mime-Version: 1.0 Content-Type: text/plain; charset="gb2312" Content-Transfer-Encoding: base64 X-Trace: posting.google.com 1151604853 29734 127.0.0.1 (29 Jun 2006 18:14:13 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 29 Jun 2006 18:14:13 +0000 (UTC) In-Reply-To: <e7d5na$s4h$1@news.yaako.com> User-Agent: G2/0.2 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.0; zh-CN; rv:1.8.0.4) Gecko/20060508 Firefox/1.5.0.4,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: m73g2000cwd.googlegroups.com; posting-host=222.244.117.38; posting-account=ZaKbcA0AAAAGPFf5Me9tOZ4A5KimBDJw