sql - vb.net 的 SUMIFS
问题描述
再会,
如何在 vb.net 的 sql 查询中做 sumifs
Private Sub txtProcYM_TextChanged(sender As Object, e As EventArgs) Handles txtProcYM.TextChanged
Try
query = "SELECT SUM(prdInput) FROM ProdOutput WHERE HELPER ='" & txtLot.Text & "-" & txtPartNumber.Text & "-" & txtProcess1.Text & "';"
retrieveSingleResult(query)
proc1QTYIn.Text = dt.Rows(0)("prdInput").ToString()
Catch ex As Exception
End Try
End Sub
这是我的代码。计划是根据帮助器 txtlot txtPartnumber 和 txprocess 获取列 prdInput 的总和。
我设法显示找到的查询的第一个 prdinput 但我需要它的总和,因为我有多个 txtlot 零件号和进程。
谢谢
编辑:我已经在查询中执行了 SUM(prdInput),但文本框中没有显示任何内容。
解决方案
您快到了。您只需为执行 sum 聚合的列起别名:
Private Sub txtProcYM_TextChanged(sender As Object, e As EventArgs) Handles txtProcYM.TextChanged
Try
query = "SELECT SUM(prdInput) AS prdInput FROM ProdOutput WHERE HELPER ='" & txtLot.Text & "-" & txtPartNumber.Text & "-" & txtProcess1.Text & "';"
retrieveSingleResult(query)
proc1QTYIn.Text = dt.Rows(0)("prdInput").ToString()
Catch ex As Exception
End Try
End Sub
使用格式化查询可能更容易看出差异:
SELECT
SUM(prdInput) AS prdInput --you forgot to give this column a name
FROM ProdOutput
WHERE HELPER = '" & txtLot.Text & "-" & txtPartNumber.Text & "-" & txtProcess1.Text & "';
推荐阅读
- java - 我怎样才能延迟点击按钮的动作,以便我可以存储一个 JSON 数组?
- maven - Jenkins:在 Docker 容器中发生 Maven 构建时如何使用 JUnit 插件
- c# - C# 单元测试 - 从 Http 响应断言 Json
- python - 循环数据库行并将字段复制到另一个字段
- php - 如何从 JSON 数组中计算值
- php - 有没有办法在网站自动化期间自动截取失败的屏幕截图?
- python - 使用 PIP 安装包,然后在安装了多个 Python 版本的系统上使用该包
- windows - 将批处理文件移动到批处理文件运行时添加的目录中
- amazon-cloudformation - Cloudformation 卡在 UPDATE_ROLLBACK_FAILED
- google-api - Google 拒绝敏感 GMail 范围的请求