串联查询 [英] Concatenating Queries

查看:80
本文介绍了串联查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将两个查询合并在一起,但是它们的结构不完全相同.

查询之一的结构是:名称,部门,总销售费用

查询二的结构是:名称,部门,总计
数据查询一个.

fred dvd's 250
戴夫唱片300
唐表音乐150


数据查询二

fred dvd's 100
戴夫记录350
丹尼斯DVD 200

结果查询

fred dvd的250100
戴夫记录300350
唐表音乐150 0
丹妮丝DVD 0 200

谢谢

Scott

I need to join two queries together but they don''t have exactly the same structure..

the structure of query one is : name, department, totalsalesafrica

the sturcture of query two is : name, department, totalsaleseurope

Data query one..

fred dvd''s 250
dave records 300
don sheetmusic 150


Data query two

fred dvd''s 100
dave records 350
denise dvd''s 200

Resultant query

fred dvd''s 250 100
dave records 300 350
don sheetmusic 150 0
denise dvd''s 0 200

Thanks

Scott

推荐答案

您可以尝试
You could try
<br />
select name,department,totalsalesafrica as Salesafrica, 0 as SalesEurope from table1<br />
UNION<br />
select name,department,0 as Salesafrica, totalsaleseurope as SalesEurope from table2


您可以使用内部选择.我不知道如何设置您的表,但这将是这样的:

You could use inner selects. I dont'' know how your tables are setup but it would be something like this:

SELECT NAME, DEPT, 
(SELECT SUM(SALES) FROM TblSales WHERE TblSales.REGION=''AFRICA'' AND TblSales.NAME=TblCustomers.NAME AND TblSales.DEPT=TblCustomers.DEPT) AS AfricaSales, 
(SELECT SUM(SALES) FROM TblSales WHERE TblSales.REGION=''EUROPE'' AND TblSales.NAME=TblCustomers.NAME AND TblSales.DEPT=TblCustomers.DEPT) AS EuropeSales 
FROM TblCustomers


这篇关于串联查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆