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.考試學號
結果截圖
下邊還有幾條沒顯示全,湊合看吧