sql一对多查询
Ⅰ sql一对多查询
select客户表.客户编号,nvl(stat.c,0)
from客户表
leftjoin(select客户编号,sum(商品价格)cfrom交易表groupby客户编号)statonstat.客户编号=客户表.客户编号
Ⅱ sql 一对多统计查询
借一下1L的语句
select u.id,u.niceName,u.imei,u.address,u.mobile,v.次数
from users as u ,
(select count(1) 次数,imei from reback Where [time]>'2012-11-06'
and [time]<'2012-11-07' group by imei ) v
where v.imei = u.imei
order by v.次数 desc
然后顺便一提,4000w的表,那么time、imei两列都要加索引,还有users表中的imei也要加索引
Ⅲ 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两张表一对多如何查询
selectGoods.trumbnail
fromGoods
leftjoinPictureonGoods.picture=Picture.id
Ⅳ sql 两表 一对多查询问题
你的表b里应该有一个员工编号或者姓名之类的字段吧
那就直接从表b里查询就行
select
employeeID,
score
from
tableB
where
employeeID=12345
select
employeename,
score
from
tableB
where
employeename='aaaaa'
Ⅵ sql语句一对多表的查询方式怎么写
使用SELECT子句进行多表查询
SELECT a.id,a.user, b.message FROM user AS a,message AS b WHERE a.id=b.id
Ⅶ 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语句
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 一对多的查询
你怎么俩table1,后一个叫table2吧
执行以下语句
selectt1.考试学号,t1.科目,t2.考试成绩
from
(selecta.科目,a.科目ID,b.考试学号
from
(select科目,科目IDfromtable1)asa,
(selectdistinct考试学号fromtable2)asb)ast1leftjoin
table2ast2ont1.科目ID=t2.科目IDandt1.考试学号=t2.考试学号
结果截图
下边还有几条没显示全,凑合看吧