sql - Access 中的简单子(monad)查询

标签 sql database ms-access

我有一个子查询问题,我确信有一个非常非常简单的解决方案,但我不知道它是什么!

这就是我想要做的,我有两个表,比方说,客户和订单。显然,客户表存储了单个客户的列表,订单表存储了客户所下订单的列表。我正在尝试创建一个查询,该查询将返回每个客户的详细信息以及该客户下的总订单金额。尽我所能,我似乎无法让这个查询像它说的那样工作:

“您已经编写了一个可以返回多个字段的子查询,而无需在主查询的 from 子句中使用 EXISTS 保留字。”

我正在尝试处理这样的事情,请问有谁能告诉我哪里出了问题吗?

select
  customer.name,
  customer.address,
  (select sum(order.orderamount) from order, customer where order.customerid = customer.id)
from
  customer

谢谢!

最佳答案

select 
  customer.name, 
  customer.address, 
  (select sum(order.orderamount) from order where order.customerid = customer.id) as amount
from customer 

但是你可以在没有子查询的情况下做到这一点:

select 
  customer.name, 
  customer.address, 
  sum(order.orderamount) 
from order 
   join customer on order.customerid = customer.id
group by   customer.name,   customer.address

关于sql - Access 中的简单子(monad)查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8852859/

相关文章:

sql - 如何将 3 个 SQL 查询合并为 1 个?

xml - 如何正确使用AddBatch/withBatch将xml标签值批量插入数据库表

vb.net - OleDbAdapter错误,在封闭 block 中隐藏变量错误

SQL Server 子查询中的 ORDER BY 子句

sql - varchar(255) v tinyblob v tinytext

sql - PostgreSQL 将行转置为列

database - CoInitialize错误在线程内使用数据库

mysql - 连接两个表以替换第二个表中的新值(如果存在)

ms-access - 在 Access 2007 中绑定(bind)表单组合框

c - 在 C 程序的 MS Access 查询中使用变量