当前位置:首页 » 编程语言 » 一对多sql查询

一对多sql查询

发布时间: 2022-06-29 22:11:27

㈠ 求一对多查询的sql语句

select
*
from
(select
id,sum(money)
as
mm
from
a表
group
by
id)
aaa,
(select
id,sum(money)
as
nn
from
b表
group
by
id)
bbb
where
aaa.id=bbb.id
and
aaa.mm=bbb.nn;
-----------------------------
说明:
先用语句,得到aaa,bbb两个临时表,里面是(id,钱的求和);
然后叠加一个查询,从表aaa,表bbb中,用条件,筛选出需要的记录(id相等,钱求和相等);mm,nn是我为了字段查看方便,设置的两个临时字段名。
-----------------------------
如果你是用workbench,语句正确执行要写成一行。

㈡ sql一对多查询

select客户表.客户编号,nvl(stat.c,0)
from客户表
leftjoin(select客户编号,sum(商品价格)cfrom交易表groupby客户编号)statonstat.客户编号=客户表.客户编号

㈢ sql 一对多的查询

你怎么俩table1,后一个叫table2吧

执行以下语句

selectt1.考试学号,t1.科目,t2.考试成绩
from
(selecta.科目,a.科目ID,b.考试学号
from
(select科目,科目IDfromtable1)asa,
(selectdistinct考试学号fromtable2)asb)ast1leftjoin
table2ast2ont1.科目ID=t2.科目IDandt1.考试学号=t2.考试学号

结果截图

下边还有几条没显示全,凑合看吧

㈣ sql 一对多查询

交给我吧,典型的交叉查询,行列转换
select s.StudentName,
(case r.Subject when '语文' then r.Math end) as 语文,
(case r.Subject when '数学' then r.Math end) as 数学,
(case r.Subject when '英语' then r.Math end) as 英语,
(case r.Subject when '物理' then r.Math end) as 物理,
(case r.Subject when '地理' then r.Math end) as 地理
from Student s,Results r
where s.StudentId=r.StudentId

能用的话记得给分哦~

㈤ sql一对多的查询代码怎么查

代码如下:

SELECT a.trumbnail, b.url, c.url

FROM Goods a, Picture b, Picture c

WHERE a.picture=b.id AND a.picture=c.id

㈥ sql 两表 一对多查询问题

你的表b里应该有一个员工编号或者姓名之类的字段吧
那就直接从表b里查询就行
select
employeeID,
score
from
tableB
where
employeeID=12345
select
employeename,
score
from
tableB
where
employeename='aaaaa'

㈦ 一对多sql联合查询:

select t1.id,t1.name,min(t2.type) from t1 left join t2 on t1.id=t2.pid group by t1.id,t1.name
不知道你要取的单条是靠哪个条件选择的,暂时取最小

㈧ sql 如何一对多的查询

select d.*, c.成绩, c.时间
from 主表 d,
(select b.*
from (select id, max(时间) max_date from 从表 group by id) a,
从表 b
where a.id = b.id
and a.max_date = b.时间) c
where c.id = d.id

㈨ sql语句一对多表的查询方式怎么写

使用SELECT子句进行多表查询
SELECT a.id,a.user, b.message FROM user AS a,message AS b WHERE a.id=b.id

㈩ SQL一对多查询问题

select t1.学号,t1.姓名,t1.性别,t2.科目,t2.成绩 from 总表 t1,分表 t2 where t1.学号=t2.学号 order by t1.学号

另你说的跨行显示如果是值相同就合并上下两个单元格的意思的话,是可以的,要在后台写代码合并单元格。
protected void GridView2_DataBound(object sender, EventArgs e)
{
int inArA;
int inArB;
int intspan;
string temp="",temp1="";
for (inArA = 0; inArA < GridView2.Rows.Count; inArA++)
{
GridViewRow _itm = GridView2.Rows[inArA];
intspan = 1;
temp = GridView2.Rows[inArA].Cells[0].Text;

#region IP不同导致出现两条记录时,开始合并
for (inArB = inArA + 1; inArB < GridView2.Rows.Count; inArB++)
{
temp1 = GridView2.Rows[inArB].Cells[0].Text;
if (String.Compare(temp, temp1) == 0)
{
intspan++;
//GridView2.Rows[inArA].Cells[0].RowSpan = intspan;//学号合并
//GridView2.Rows[inArA].Cells[1].RowSpan = intspan;//姓名合并
//GridView2.Rows[inArA].Cells[2].RowSpan = intspan;//性别合并
GridView2.Rows[inArA].Cells[3].RowSpan = intspan;//科目不合并
GridView2.Rows[inArA].Cells[4].RowSpan = intspan;//成绩不合并

//GridView2.Rows[inArB].Cells[0].Visible = false;
//GridView2.Rows[inArB].Cells[1].Visible = false;
//GridView2.Rows[inArB].Cells[2].Visible = false;
GridView2.Rows[inArB].Cells[3].Visible = false;
GridView2.Rows[inArB].Cells[4].Visible = false;
}
else
{
break;
}
}
#endregion
inArA = inArB - 1;

}
}

希望对你有帮助

热点内容
算法牛 发布:2024-05-05 22:43:40 浏览:718
grublinux引导 发布:2024-05-05 22:37:56 浏览:214
unix高级编程第三版pdf 发布:2024-05-05 22:32:09 浏览:958
手机wap网站源码 发布:2024-05-05 22:27:44 浏览:259
python修改文件某一行 发布:2024-05-05 22:18:22 浏览:457
md5加密64 发布:2024-05-05 21:59:30 浏览:527
259pp页面访问升级 发布:2024-05-05 21:47:51 浏览:89
迅雷阻止上传 发布:2024-05-05 21:26:19 浏览:914
数据库运维题 发布:2024-05-05 21:21:47 浏览:962
RM魔塔编程 发布:2024-05-05 21:21:47 浏览:286