我可以比较Access中同一个表中的两行,只输出一行吗?

编程入门 行业动态 更新时间:2024-10-27 07:23:13
本文介绍了我可以比较Access中同一个表中的两行,只输出一行吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有查询输出两个不同处理器的下一个结果:

I have query that output the next results for two different Processor:

如果处理器有多行,我需要选择一个缺少DateFilled(最小New_Grand_Total)的行并保留此记录。如果处理器有一行,我需要保留它。

If Processor has more than one row I need select one that had missing DateFilled (smallest New_Grand_Total) and keep this record. If Processor has one row I need to keep it.

我不确定如何比较行i只访问和输出其中一个。

I am not sure how compare row i Access and output only one of them.

推荐答案

您好 ElenaVarganova,

您曾提到过,"如果处理器有多行,我需要选择一个缺少DateFilled(最小New_Grand_Total)的行并保留此记录。如果处理器有一行我需要保留它。"

you had mentioned that,"If Processor has more than one row I need select one that had missing DateFilled (smallest New_Grand_Total) and keep this record. If Processor has one row I need to keep it."

我尝试创建一个类似你的表。

i try to create a Table like yours.

从您的描述看起来您有两个条件。

from your description it looks like you have 2 conditions.

(1)选择一个缺少DateFilled

(1) select one that had missing DateFilled

(2)最小New_Grand_Total

(2) smallest New_Grand_Total

然后我创建一个表单和On_Load事件我把代码放在下面。

then i create one form and On_Load Event i put code below.

Option Compare Database Private Sub Form_Load() Dim rs, rs1 As DAO.Recordset Dim db As Database Dim strSQL, strSQL1 As String Set db = CurrentDb strSQL = "SELECT * from product_data" Set rs = db.OpenRecordset(strSQL) If rs.RecordCount >= 1 Then strSQL1 = "SELECT * from product_data where New_Grand_Total=(select min(New_Grand_Total) from product_data ) and DateFilled is null;" Set rs1 = db.OpenRecordset(strSQL1) Me.Text0.Value = rs1!DateReceived Me.Text2.Value = rs1!Processor Me.Text4.Value = rs1!new_refund Me.Text6.Value = rs1!New_Grand_Total Me.Text8.Value = rs1!New_Tot_Without_Refund Me.Text10.Value = rs1!DateFilled Else Me.Text0.Value = rs!DateReceived Me.Text2.Value = rs!Processor Me.Text4.Value = rs!new_refund Me.Text6.Value = rs!New_Grand_Total Me.Text8.Value = rs!New_Tot_Without_Refund Me.Text10.Value = rs!DateFilled End If Set rs = Nothing Set rs1 = Nothing End Sub

输出:

以上只是一个给你一个想法的例子。您需要根据您的要求修改查询,代码和逻辑。如果你正在触发相同的查询,那么你不需要多次执行它,你可以显示第一个查询的结果。如果您要执行多个查询,则可以根据上述代码中的要求进行设置。

above is just an example to give you an idea. youneed tomodify the query, codeand logic based on your requirement. if you are firing the same query then you not need to execute it multiple times and you can display the result from the first query. if you have multiple query to execute then you can set it as per your requirement in code above.

问候

Deepak

更多推荐

我可以比较Access中同一个表中的两行,只输出一行吗?

本文发布于:2023-10-31 07:58:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1545507.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:两行   Access

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!