This topic has been archived. It cannot be replied.
-
工作学习 / IT技术讨论 / 呼叫SQL高手,小的有个query不会写,劳驾!!!我有两个table,一个ZipCode,有2个colum,Zip和Area(zip所属的area).另外一个table叫Report,有很多colum但是其中有一个是Zip.
现在我有一个Zip code,称为myZip.
我的query是要count在Report里边,有多少个和myZip属同一个Area的纪录。
我怎么都晕了?看着挺简单的,一定是今天早上donut吃多了。谢谢大家了!
-goldsky(泥锅泥碗泥滚蛋);
2003-12-5
{295}
(#1500104@0)
-
==>select count(*) from Report where zip in
(select zip from ZipCode where area in
(select Area from ZipCode where zip = 'myZip'
))
-cnyouyou(游啊游,游到外婆桥);
2003-12-5
{133}
(#1500111@0)
-
OR==>select count(*) from Report a, ZipCode b where a.zip=b.zip and b.area in
(select Area from ZipCode where zip = 'myZip'
)
-cnyouyou(游啊游,游到外婆桥);
2003-12-5
{124}
(#1500119@0)
-
select count(*) from report where zip in (select zip from zipcode where area in (select area from zipcode where zip=myzip))
-pasu(InTheSky);
2003-12-5
(#1500114@0)
-
select count(report.zip) from report,zipcode where zipcode.zip=report.zip and zipcode.area=(select area from zipcode where zipcode.zip=myzip)
-oceandeep(北极熊·戟兵);
2003-12-5
(#1500118@0)
-
你这个的概念更看一条用户记录对应的manager的manager下有多少人差不多.select r.*, (
select count(*) from report where zip in (
select zip from zipcode where area = /*如果area 返回多行, 用in*/ (select area from zipcode where zip = r.zip)
))
from report r
还应当有更简单的方法, Oracle 有统计方法可以用, 自己去找找吧.
-anno(烦人);
2003-12-5
{299}
(#1500131@0)
-
感激涕零感激涕零呀
-goldsky(泥锅泥碗泥滚蛋);
2003-12-5
(#1500134@0)
-
临“表”涕零?
-wmcn(偷得浮生半日闲);
2003-12-5
(#1500522@0)
-
如果我的CS数据库期末考试出这样简单QUERY题就好了, 以后还有QUERY问题放上来好了, 我肯定帮你.
-samgod(小虾);
2003-12-8
(#1505998@0)