sumif sql通过vb.net中的OLEDB

发布于 2025-01-29 06:05:20 字数 3541 浏览 5 评论 0原文

我希望在“ BLC”列中的数据库“ GSGTS/T3”中的SUMIF结果,其中包含“ PNM”列中的数字标准。我无法为SUMIF过程创建SQL。下面的说明:

  • “ PNM”中的数字值为185000的结果,即1000
QTY  CIU        DPR
10    100000     5   =10X10000X(1-5/100)= 95000
5     20000      10  =5X20000X(1-10/100)= 95000
TOTAL                =185000   
GSDTS AS t1                 
PNM     ITM        QTY  CIU    NOD  DPR
1000    TEST 1000   10  10000   01  5
1000    TEST 1001   5   20000   02  10
1002    TEST 1000   12  10000   01  15
1002    TEST 1001   6   20000   02  6

GSGTS AS t3                             
CSB GDN             PNM      DTS     DUD    SAC  DIS    BLC  DIS2
    A.04.01.002.001 1000    13-May-22       01-01           
    A.04.01.002.001 1002    13-May-22       01-02           
result                              
GSGTS AS t3                             
CSB GDN              PNM    DTS       DUD   SAC  DIS    BLC    DIS2
    A.04.01.002.001 1000    13-May-22       01-01       185000  
    A.04.01.002.001 1002    13-May-22       01-02       214800  

Private Sub fillDataGridView3()
        Try
            'Dim query As String = "select PNM, sum((qty*ciu)*(1-dpr/100)) AS BLC from GSDTS group by PNM"
 Dim sql As String = "update GSGTS SET BLC=( select sum((qty*ciu)*(1-dpr/100.0)) from GSDTS t2 WHERE GSGTS.[PNM] = t2.[PNM] ) WHERE GDN = 'A.04.01.002.001';"
            Using con As OleDbConnection = New OleDbConnection(cn)
                Using cmd As OleDbCommand = New OleDbCommand(query, con)
                    'cmd.Parameters.AddWithValue("@CODE", ComboBox1.SelectedValue)
                    Using da As New OleDbDataAdapter(cmd)
                        Dim dt As DataTable = New DataTable()
                        da.Fill(dt)
                        da.Dispose()
                        source3.DataSource = dt
                        Me.DataGridView3.DataSource = source3
                        Me.DataGridView3.Refresh()
                    End Using
                End Using
            End Using
        Catch ex As Exception
        End Try
    End Sub
Sub UpdateGsgts()
    Try
        'Dim sql As String = "update GSGTS as t3 inner join GSDTS as t2 on t3.[PNM] = t2.[PNM] set t3.[BLC] = [CIU] WHERE GDN = 'A.04.01.002.001'AND PNM=@PNM"
           Dim sql As String = "select PNM, sum((qty*ciu)*(1-dpr/100)) AS BLC from GSDTS group by PNM"
        Using conn As New OleDbConnection(cn),
               cmd As New OleDbCommand(sql, conn)
               'cmd.Parameters.AddWithValue("@PNM", ComboBox1.SelectedValue)
            conn.Open()
            cmd.ExecuteNonQuery()
        End Using

    Catch myerror As OleDbException
        MessageBox.Show("Error: " & myerror.Message)
    End Try
End Sub

“带有结果的数据库”

“错误操作必须使用可更新查询”

I want sumif results in the database "GSGTS/t3" in the "BLC" column with the number criteria in the "PNM" column. I haven't been able to create sql for the sumif process. With the explanation below :

  • the result of the value of 185000 for the number in the column "PNM" which is 1000
QTY  CIU        DPR
10    100000     5   =10X10000X(1-5/100)= 95000
5     20000      10  =5X20000X(1-10/100)= 95000
TOTAL                =185000   
GSDTS AS t1                 
PNM     ITM        QTY  CIU    NOD  DPR
1000    TEST 1000   10  10000   01  5
1000    TEST 1001   5   20000   02  10
1002    TEST 1000   12  10000   01  15
1002    TEST 1001   6   20000   02  6

GSGTS AS t3                             
CSB GDN             PNM      DTS     DUD    SAC  DIS    BLC  DIS2
    A.04.01.002.001 1000    13-May-22       01-01           
    A.04.01.002.001 1002    13-May-22       01-02           
result                              
GSGTS AS t3                             
CSB GDN              PNM    DTS       DUD   SAC  DIS    BLC    DIS2
    A.04.01.002.001 1000    13-May-22       01-01       185000  
    A.04.01.002.001 1002    13-May-22       01-02       214800  

Private Sub fillDataGridView3()
        Try
            'Dim query As String = "select PNM, sum((qty*ciu)*(1-dpr/100)) AS BLC from GSDTS group by PNM"
 Dim sql As String = "update GSGTS SET BLC=( select sum((qty*ciu)*(1-dpr/100.0)) from GSDTS t2 WHERE GSGTS.[PNM] = t2.[PNM] ) WHERE GDN = 'A.04.01.002.001';"
            Using con As OleDbConnection = New OleDbConnection(cn)
                Using cmd As OleDbCommand = New OleDbCommand(query, con)
                    'cmd.Parameters.AddWithValue("@CODE", ComboBox1.SelectedValue)
                    Using da As New OleDbDataAdapter(cmd)
                        Dim dt As DataTable = New DataTable()
                        da.Fill(dt)
                        da.Dispose()
                        source3.DataSource = dt
                        Me.DataGridView3.DataSource = source3
                        Me.DataGridView3.Refresh()
                    End Using
                End Using
            End Using
        Catch ex As Exception
        End Try
    End Sub
Sub UpdateGsgts()
    Try
        'Dim sql As String = "update GSGTS as t3 inner join GSDTS as t2 on t3.[PNM] = t2.[PNM] set t3.[BLC] = [CIU] WHERE GDN = 'A.04.01.002.001'AND PNM=@PNM"
           Dim sql As String = "select PNM, sum((qty*ciu)*(1-dpr/100)) AS BLC from GSDTS group by PNM"
        Using conn As New OleDbConnection(cn),
               cmd As New OleDbCommand(sql, conn)
               'cmd.Parameters.AddWithValue("@PNM", ComboBox1.SelectedValue)
            conn.Open()
            cmd.ExecuteNonQuery()
        End Using

    Catch myerror As OleDbException
        MessageBox.Show("Error: " & myerror.Message)
    End Try
End Sub

DATABASE WITH RESULT
syntax error (missing operator)
RESULT

error operation must use an updateable query

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

め七分饶幸 2025-02-05 06:05:20

您可以计算pnm明智blc如下:

架构和插入语句:

 create table GSDTS ( PNM int, ITM varchar(100), QTY int, CIU int, NOD int, DPR int);
 insert into GSDTS values(1000,    'TEST 1000',   10,  10000,   01,  5);
 insert into GSDTS values(1000,    'TEST 1001',   5,   20000,   02,  10);
 insert into GSDTS values(1002,    'TEST 1000',   12,  10000,   01,  15);
 insert into GSDTS values(1002,    'TEST 1001',   6,   20000,   02,  6);

查询:

 select PNM, sum((qty*ciu)*(1-dpr/100)) BLC from GSDTS
 group by PNM

输出:

pnmblc
1000185000.0000
1002214800.0000.0000

db< 这里

“ https://dbfiddle.uk/?rdbms=mysql_8.0&fiddle = c6bf68e50cac5f4aeaeaeae4ae4c974ef1d64c4f1d64c4f

create table GSDTS ( PNM int, ITM varchar(100), QTY int, CIU int, NOD int, DPR int);
   insert into GSDTS values(1000,    'TEST 1000',   10,  10000,   01,  5);
   insert into GSDTS values(1000,    'TEST 1001',   5,   20000,   02,  10);
   insert into GSDTS values(1002,    'TEST 1000',   12,  10000,   01,  15);
   insert into GSDTS values(1002,    'TEST 1001',   6,   20000,   02,  6);
   
   
   create table GSGTS (GDN varchar(50), PNM int, BLC int);
   insert into GSGTS values('A.04.01.002.001',1000,    0);
   insert into GSGTS values('A.04.01.002.001',1002,    0);

>在

 select * from GSGTS

rel =“ nofollow bollow noreferrer”> nore noreferrer “ :

| GDN             |  PNM | BLC
| :-------------- | ---: | --:
| A.04.01.002.001 | 1000 |   0
| A.04.01.002.001 | 1002 |   0

更新查询:

update GSGTS SET BLC=( select sum((qty*ciu)*(1-dpr/100.0)) from GSDTS t2 WHERE GSGTS.[PNM] = t2.[PNM] ) WHERE GDN = 'A.04.01.002.001';

更新后从GSGTS表中进行选择:

select * from GSGTS

输出:

| GDN             |  PNM |    BLC
| :-------------- | ---: | -----:
| A.04.01.002.001 | 1000 | 185000
| A.04.01.002.001 | 1002 | 214800

db<这里

You can calculate PNM wise BLC as below:

Schema and insert statements:

 create table GSDTS ( PNM int, ITM varchar(100), QTY int, CIU int, NOD int, DPR int);
 insert into GSDTS values(1000,    'TEST 1000',   10,  10000,   01,  5);
 insert into GSDTS values(1000,    'TEST 1001',   5,   20000,   02,  10);
 insert into GSDTS values(1002,    'TEST 1000',   12,  10000,   01,  15);
 insert into GSDTS values(1002,    'TEST 1001',   6,   20000,   02,  6);

Query:

 select PNM, sum((qty*ciu)*(1-dpr/100)) BLC from GSDTS
 group by PNM

Output:

PNMBLC
1000185000.0000
1002214800.0000

db<>fiddle here

Update query:

Schema and insert statements:

create table GSDTS ( PNM int, ITM varchar(100), QTY int, CIU int, NOD int, DPR int);
   insert into GSDTS values(1000,    'TEST 1000',   10,  10000,   01,  5);
   insert into GSDTS values(1000,    'TEST 1001',   5,   20000,   02,  10);
   insert into GSDTS values(1002,    'TEST 1000',   12,  10000,   01,  15);
   insert into GSDTS values(1002,    'TEST 1001',   6,   20000,   02,  6);
   
   
   create table GSGTS (GDN varchar(50), PNM int, BLC int);
   insert into GSGTS values('A.04.01.002.001',1000,    0);
   insert into GSGTS values('A.04.01.002.001',1002,    0);

Select from GSGTS table:

 select * from GSGTS

Output:

| GDN             |  PNM | BLC
| :-------------- | ---: | --:
| A.04.01.002.001 | 1000 |   0
| A.04.01.002.001 | 1002 |   0

Update query:

update GSGTS SET BLC=( select sum((qty*ciu)*(1-dpr/100.0)) from GSDTS t2 WHERE GSGTS.[PNM] = t2.[PNM] ) WHERE GDN = 'A.04.01.002.001';

Select from GSGTS table after update:

select * from GSGTS

Output:

| GDN             |  PNM |    BLC
| :-------------- | ---: | -----:
| A.04.01.002.001 | 1000 | 185000
| A.04.01.002.001 | 1002 | 214800

db<>fiddle here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文