查询多个参数 [英] Query with multiple parameters

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

问题描述

我有我的桌子:主要行动表。在我的表中,我有以下行来源:出勤,事件日期和收到的Req。我希望我的查询将出勤率与WHERE事件日期> = [输入开始日期:]和< = [输入结束
日期:]的日期参数相加。我还希望查询计算收到的请求收到的请求数> = [输入开始日期]和< = [输入结束日期]。谢谢。

I have my table: Main Ops Table. Inside my table I have the following row sources: Attendance, Event Date, and Req Received. I want my query to sum the attendance with the date parameter of WHERE Event Date >=[Enter Start Date:] And <=[Enter End Date:]. I also want the query to Count the req received WHERE Req Received >=[Enter Start Date] And <=[Enter End Date]. Thanks.

推荐答案

由于你想独立地将范围限制应用于两列,你需要使用一个子查询,例如



参数[输入开始日期] DATETIME,

[输入结束日期] DATETIME;
$
SELECT SUM(出勤)AS TotalAttendance,

    (SELECT COUNT(*)

      FROM [Main Ops Table]

      WHERE [收到的请求] > =  [输入开始日期]

      AND [Req Received] <  [输入结束日期] + 1)AS NumberReceived

FROM [主要操作表]

WHERE [事件日期]  > =&NBSP; [输入结束日期]

和[活动日期]  <&NBSP; [输入结束日期] +1;
$


注意将范围定义为开始日期之后或之后以及结束日期之后日期之前的方法,即更可靠,因为它允许表中的任何值在范围的最后一天具有非零时间元素,否则将排除

As you want to apply the range restriction to two columns independently, you'd need to use a subquery for one, e.g.

PARAMETERS [Enter Start Date] DATETIME,
[Enter End Date] DATETIME;
SELECT SUM(Attendance) AS TotalAttendance,
    (SELECT COUNT(*)
      FROM [Main Ops Table]
      WHERE [Req Received]  >=  [Enter Start Date]
      AND [Req Received]  <  [Enter End Date]+1) AS NumberReceived
FROM [Main Ops Table]
WHERE [Event Date]  >=  [Enter End Date]
AND [Event Date]  <  [Enter End Date]+1;

Note the method of defining the range as on or later than the start date and before the date following the end date, which is more reliable as it allows for any values in the table with a non-zero time of day element on the final day of the range, which would otherwise be excluded.


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

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