SQL高手请进、谢谢! 有四张表,客户表,客户订单表,订单表,book表 .....写在问题补充里

作者&投稿:益路 (若有异议请与网页底部的电邮联系)
SQL高手请进,SQL语句查询试题~

表结构都不贴上来怎么帮你啊
难道是需要自己设计?

Create table #Custom
([CustomID] nvarchar(3),[Name] nvarchar(20))
Insert #Custom
select N'001','john' union all
select N'002','cathy' union all
select N'003','Alice' union all
select N'004','jack'

Create table #Product
([ProductId] nvarchar(3),[ProductName] nvarchar(20))
Insert #Product
select N'001','产品1' union all
select N'002','产品2' union all
select N'003','产品3' union all
select N'004','产品4'

Create table #Sales
([SalseID] nvarchar(3),[SalseName] nvarchar(20),[city] nvarchar(20))
Insert #Sales
select N'001','销售商1','beijing' union all
select N'002','销售商2','xian'

Create table #Order
([OrderID] nvarchar(3),[ProductId] nvarchar(3),
[CustomId] nvarchar(3),[SalesId] nvarchar(3))
Insert #Order
select N'001','001','001','001' union all
select N'002','002','001','001' union all
select N'003','001','002','002' union all
select N'004','003','003','002' union all
select N'005','004','002','002' union all
select N'006','002','004','001'


select count(*), productid from #ORder f
left join ((select customid,count(*) as countP from #Order
group by customid
having count(*)>=2)) a1 on a1.customId=f.customid
where countP>=2
group by productid
having count(*)>=2

select distinct f.customId,name from #ORder f
left join #sales a1 on a1.salseId=f.salesid
left join #custom a2 on a2.customid=f.customid
where a1.city='beijing'
--'beijing' 为输入的条件

CREATE TABLE
表名_客户表

列名1 类型 是否为空,
列名2 类型 是否为空,
列名3 类型 是否为空


例如:
Create table 客户表

姓名 char(16) NOT NULL,
电话 char(11) NOT NULL,
)

注意:在建表前先要选择数据库,

问题1:
select address, client_name, phone, order_id
from client A
inner join client_order B
on A.client_id =B.client_id --这个不用解释吧
问题2:
select tt1.client_name, sum(tt2.count*tt2.price) as total_price
from (select client_name, order_id
from client A
inner join client_order B
on A.client_id =B.client_id) tt1 --得到客户订单表
inner join (select order_id,count,price
from order C
inner join book D
on C.book_id=D.book_id) tt2 --得到订单价格表
on tt1. order_id=tt2.order_id --根据订单号做连接
group by tt1.client_name --根据客户名汇总金额


有两种方法,效率上没有任何区别.
1, Oracle的传统多表查询
SELECT c.CourseName, s.StartDate, i.FirstName
|| ' ' ||i.LastName as Instructor, l.City
FROM ScheduledClasses s, Instructors i, Courses c, Locations l
WHERE s.InstructorID = i.InstructorID
AND s.CourseNumber = c.CourseNumber
AND s.LocationId = l.LocationID
AND l.Country = ‘USA'

2, ANSI标准查询(Oracle 9i以上支持)
SELECT c.CourseName, s.StartDate, i.FirstName
|| ' ' ||i.LastName as Instructor, l.City
FROM Instructors i
JOIN ScheduledClasses s ON (i.InstructorID = s.InstructorID)
JOIN Courses c ON (s.CourseNumber = c.CourseNumber)
JOIN Locations l ON (s.LocationId = l.LocationID)
WHERE l.Country = ‘USA'

补充下:如果要求每张订单可以包含多种图书,应该如何修改Order表的主键?为保证每张订单只被一个客户拥有,应该在ClientOrder表上增加怎么样的约束(提示:使用索引)


英文高手 请进 欢迎 谢谢!拜托了 急!!!
1.to use the same cutter guides来指导(用户)使用同类型的刀具导轨,刀具导轨是一种工具。2.what are the lead-times to receive samples, including packaging of the products for final approval?人家只是在咨询你关于交货时间的具体细节,并没有说你的样品好坏。翻译:“在...

日语 高手请进 ~谢谢
私は夏が好きだが、夏の海がそれ以上だ。去年の夏のある朝、私は友达と一绪にしゃべったり、笑ったりして海に行くことになった。あの时夜はまだ明けてなく、太阳さえ升りはしなかった。私たちは少し騒いで疲れてから、みんなで砂浜に横になって海を见ながら话を交わしていた。私...

请教SQL查询问题,高手请进,感谢!
SELECT type,typeid,code,name,(SELECT RTRIM((SELECT ' '+RTRIM(context)+' ' FROM 表名 WHERE typeid=W.typeid ORDER BY ID FOR XML PATH (''))) context FROM 表名 W WHERE code='000'

高手请进,先谢谢了.
1、安装适合你的显卡驱动,你可以试试显卡自带驱动盘上的驱动,最新的未必最好。2、不同的操作系统,以及安装DX9.0C可能会造成你的显卡测试分数降低。3、安装主板驱动程序。NV的主板更是这样。4、检查你的显卡风扇是不是运装正常、

英语高手请进!请帮翻译成地道英文.谢谢!
I have received 250 dollars which you on 25th send. Because of yours peculiar circumstance, you may after arriving at Beijing the spare money 500 dollars, pays us with the cash way Beijing's colleague. Please understand before you have not paid the entire funds we to be unable ...

英语高手请进啊~翻译请尽量地道,谢谢了
surfing on the internet. I found a job recently, and kinda of busy this summer vacation. But I do remember you, thanks for you still remembering me. How about you? I think your life must be very funny and I am looking forward to hearing from you.希望我的答案令你满意。

紧急,QQ高手请速进,谢谢
第一,假如你是会员,可以直接发信息取回密码。第二,填写密码保护,取回密码。第三,填写号码申诉表,取回密码。第四,你可以再盗回来。第五,满足盗你号的人的要求也许他会还你密码。第六,他上线的话,用美人计(美男计)骗回密码。

电脑高手请进,急 谢谢咯
电脑高手请进,急 谢谢咯 我那台联想的买了不到一个月换了主板,昨天晚上用的时候屏幕一下黑屏,一下又有了,我电脑敲下,它就来了一闪一闪的,现在我拿到维修中心,它居然不出现同样的问题了,我想请问,怎样... 我那台联想的买了不到一个月换了主板,昨天晚上用的时候屏幕一下黑屏,一下又有了,我电脑敲下,它...

电脑高手请进!!谢谢!!
4.然后对磁盘进行碎片整理,整理过程中请退出一切正在运行的程序 \/*磁盘碎片整理对硬盘有损伤,所以不用非常勤的整理,需要时才整理*\/ 6.打开“我的电脑”-右键点系统盘-“属性”-“磁盘清理”-“其他选项”-单击系统还原一栏里的“清理”-选择“是”-ok了 7、在各种软硬件安装妥当之后,其实XP需要更新文件的时...

日语高手请进,帮忙翻一下,谢谢!
有可能导致灼伤,请不要溶解了的高温树脂。撒在地面上的球状树脂,有可能导致摔跤,请马上清扫。保管 :直射日光の当たらない热、発火源から离れた乾燥した场所で保管する。静电気灾害を防止する対策をとる。保存:请保存在阳光无法直接照射到的、没有明火的干燥场所。采取防静电措施。

和静县17794809644: 高手请进,关于SQL连接四个表的问题? -
贲眨清热: 如楼所说很正确,我只是加一点说明,必须加上四个表之间的关键字关系 否则会产生很大的数据冗余

和静县17794809644: sql查询问题,有4个表,学生表(sid,sname,cid)课程表(课程ID,KCNAME)成绩表(sid,kcid,score),班级表 -
贲眨清热: 这是思路 不是答案 假设 班级是a表 班级对应的学生是b表select a.*,b.chengji form a inner join b on a.xuehao=b.xuehao where 条件 order by id asc

和静县17794809644: sql问题 有四张表 查询每个客户所购买的书购买价格比同类书的平均当前价格高的图书书名以及客户 -
贲眨清热: SELECT b.title,c.cid FROM books b , customers c, pruchases pe WHERE b.bookId=pe.bookId AND c.cid=pe.cid AND pe.pprice > (SELECT AVG(p1.price) FROM books b1 , pricing p1 WHERE b1.bookId=p1.bookId AND category=b.category GROUP BY b1.category );

和静县17794809644: 4张表的SQL语句
贲眨清热: 不太清楚你的要求,但这种情况一般用 INNER JOIN 联接要用的表,一句中可以有好几个 INNER JOIN.例如:SELECT c1, c2, c3, ..... from tbl1 a INNER JOIN tbl2 b ON a.ID=b.ID INNER JOIN tbl2 c on b.ID=c.ID (或a.IDl=c.ID, 看需要而定)

和静县17794809644: 高手请进,关于SQL连接四个表的问题?from(表1innerj
贲眨清热: 在加一个inner 就可以了!

和静县17794809644: sql 多表统计查询问题,请高手帮忙看一下,万分感谢! -
贲眨清热: 测试一下如下写法:select a.name,b.id,count(*) as total,count(IIf(b.type = '表扬',1,0)) as 表扬,count(IIf(b.type = '金奖',1,0)) as 金奖,...

和静县17794809644: 求一条多表查询的sql语句,高手请进 -
贲眨清热: select 表1.*,表2.time1,表2.time2,表3.test from 表1,表2,表3 where 表1.cd=表2.id and 表1.cd=表3.id and (表1.time between('2008-4-1','yyyy-mm-dd') and ('2008-4-30','yyyy-mm-dd'))

和静县17794809644: oracle 中使用sql怎么进行多表查询,不仅仅是两张表,四张以上,有什么方法,请各位高手解惑,谢谢!以及 -
贲眨清热: 有两种方法,效率上没有任何区别. 1, Oracle的传统多表查询SELECT c.CourseName, s.StartDate, i.FirstName || ' ' ||i.LastName as Instructor, l.City FROM ScheduledClasses s, Instructors i, Courses c, Locations l WHERE s.InstructorID = i....

和静县17794809644: SQL四表查询.通过关键字找出表中对应字段记录,并通过这些记录找出另一表中对就所有唯一记录 -
贲眨清热:select 表2.合同编号, 表2.型号,表2.单价 from 表2,表1where (表2.合同编号=表1.合同编号) and (表2.型号=model-number) and (表1.客户名=client-name) order by 表2.合同编号 select 表4.报价单编号,表4.型号,表4.单价 from 表4,...

和静县17794809644: 高手请进,sql 多表联合查询语句怎么写 A表结构 id dw 1 aa 2 bb 3 cc 4 dd 5 ee 6 ff B表结构: -
贲眨清热: 你好!0) exprl from a,b where a.dw = b.dw(+) group by a.dwselect a.dw.dw), nvl(count(b 希望对你有所帮助,望采纳.

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网