这是数据库图片
我的设计的后端代码
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();
}
我的应用设计
i need to fetch total bags,sales and profit Click here to Show Design
这里我需要填写值
还查询我需要的
(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;
答案 0 :(得分:0)
1)
Select Dates, Names, sum(bag) as SumOfBags
from TableName
group by Dates
1.1)
Select Dates, sum(bag) as SumOfBags
from TableName
group by Dates, Names
如果您只想选择单个值
1)
Select sum(bag) as SumOfBags
from TableName
where Date = WhatEverYouWant
1.1)
Select sum(bag) as SumOfBags
from TableName
where Dates = WhatEverYouWant and Names = WhatEverYouWant
我相信你现在可以创建其他查询:)
答案 1 :(得分:0)
SQL的超级快速指南:)
最简单的查询是这样的:
select <List of columns you want to be shown>
from <table name>
where <conditions you want>
如果你想得到总和,你需要写上sum(<column to be sumed>) as <alias for this column>
你需要使用这个结构作为你想要显示的一个列(选择后)。像1.1的例子一样
答案 2 :(得分:0)
SELECT to_date (CALL_DATE,'DD-MON-YYYY HH24:MI') AS DATET FROM XXXXXX
我几乎肯定会开始工作:)。
如果空元素出现问题,您可以尝试
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'