Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何获取所选日期所需列的总和_C#_Sql Server_Wpf - Fatal编程技术网

C# 如何获取所选日期所需列的总和

C# 如何获取所选日期所需列的总和,c#,sql-server,wpf,C#,Sql Server,Wpf,这是数据库图片 我设计的后端代码 if (startdate.Text == "" || enddate.Text == null) { MessageBox.Show("Please Select The Date"); } else { con.Open(); SqlCommand cmd = new SqlCommand("Here i need que

这是数据库图片

我设计的后端代码

if (startdate.Text == "" || enddate.Text == null)
        {
            MessageBox.Show("Please Select The Date");
        }
        else
        {
            con.Open();
            SqlCommand cmd = new SqlCommand("Here i need query for total bags", con);
            SqlDataReader reader = cmd.ExecuteReader();
            reader.Read();
            string val = reader.GetValue(0).ToString();
            decimal valu = Convert.ToDecimal(val);
            Int32 value = Convert.ToInt32(valu);
            bags.Text = value.ToString();
            con.Close();
        }
我的应用程序设计

这里我需要填充值

还有我需要的问题

(1) 按选定日期列出的行李总数

(1.1)按选定名称和日期列出的行李总数

(2) 按选定日期划分的信贷总额

(2.1)按选定名称和日期列出的信贷总额

(3) 按选定日期划分的利润总额

(3.1)按选定名称和日期划分的利润总额

这里是全面数据查询

select r.id,r.datee,r.time,c.name,r.description,r.vanda,r.bag,r.price,r.credit,r.debit from records as r, customer as c where r.cusid = c.id and c.name = 'aizaz' and r.datee between '1/1/2016' and '12/12/2017' order by r.datee asc;
(一)

1.1)


如果您只想选择单个值

(一)

1.1)

我相信您现在可以创建其他查询:)

SQL超级快速指南:)
最简单的查询如下:

select <List of columns you want to be shown>
from <table name>
where <conditions you want>
选择
从…起
哪里
如果要获得sum,需要将
sum()写为

,并且需要将此结构用作要显示的列之一(选择后)。就像1.1的例子一样

   select sum(r.bag) as SumOfBags
   from records as r, customer as c
   where r.cusid = c.id and c.name = 'aizaz' and r.datee between '1/1/2016' and '12/12/2017'
我几乎可以肯定这会起作用:)


如果空元素出现问题,可以尝试

   select sum(r.bag) as SumOfBags
   from records as r
   inner join customer as c
   on r.cusid = c.id 
   where r.datee between '1/1/2016' and '12/12/2017' and c.name = 'aizaz'

请准确地提一下你的问题好的,有什么问题吗?你有第一,继续添加你需要的标准(哦,当你只制作1个数字时,你不需要orderby查看数据库和设计的图片请阅读并编辑你的问题,以包含相关的细节,这样我们才能真正提供帮助。示例数据应该是DDL+DML语句的形式,并且所需的结果应该清晰。你应该自己付出一些努力想想我需要的第二个……谢谢,让我试着编辑该查询,选择r.id、r.Date、r.time、c.name、r.description、r.vanda、r.bag、r.price、r.credit、r.Debt作为r,客户作为c,其中r.cusid=c.id和c.name='aizaz'和r.Date'2016年1月1日至2017年12月12日的订单由r.Date asc完成;该查询显示您的所有记录努力,但你需要理解我从其他表中加入的名称,这就是为什么查询看起来像这样选择r.id,r.datee,r.time,c.name,r.description,r.vanda,r.bag,r.pri‌​ce,r.credit,r.debit从记录中作为r,客户作为c,其中r.cusid=c.id和c.name='aizaz'和r.datee在'2016年1月1日'和'2017年12月12日'之间由r.datee asc订购,您需要编辑此项。我只需要一个单元格作为结果w!!!非常感谢您这样的天才(^ ^)两个查询都很好。你能告诉我哪一个查询更合适吗?嗯,有时候你想使用两个表的id。然后你可以使用“from tab1,tab2”。但是,您可能在其中一个表中找不到某些id。然后呢?这就是加入的时刻。您想要的所有详细信息都可以在此处找到:。使用加入而不仅仅是coma的第二个原因是它可以更快(查询越复杂,“加入”越好)嗯…明白了!明白了你知道我怎么才能得到这个值吗
 Select sum(bag) as SumOfBags
from TableName
where Dates = WhatEverYouWant and Names = WhatEverYouWant
select <List of columns you want to be shown>
from <table name>
where <conditions you want>
   select sum(r.bag) as SumOfBags
   from records as r, customer as c
   where r.cusid = c.id and c.name = 'aizaz' and r.datee between '1/1/2016' and '12/12/2017'
   select sum(r.bag) as SumOfBags
   from records as r
   inner join customer as c
   on r.cusid = c.id 
   where r.datee between '1/1/2016' and '12/12/2017' and c.name = 'aizaz'