select count(*) as jysum
from Member, Card ,Trading
where Member.ID=Card.UserID and Card.State<>'3' and (Member.ID=Trading.buyID or Member.ID=Trading.sellID )
group by Member.ID
select distinct Member.ID,Member.Acc,Member.Peoplename,Member.Mobile,Card.State
from Member, Card ,Trading
where Member.ID=Card.UserID and Card.State<>'3' and (Member.ID=Trading.buyID or Member.ID=Trading.sellID )
第一段查的结果为
jysum
A条
B条
C条
第二段的结果为
.ID .Acc .Peoplename .Mobile .State
1 XX XX XX XX
2 XX XX XX XX
3 XX XX XX XX
我想对上面2段SQL语句进行合并,合并的效果为
.ID .Acc .Peoplename .Mobile .State jysum
1 XX XX XX XX A条
2 XX XX XX XX B条
3 XX XX XX XX C条
意思是,ID为1的出现了A条(比如5条)ID为2的出现了B条(比如3)
原始
select Member.ID,Member.Acc,Member.Peoplename,Member.Mobile,Card.State
from Member, Card ,Trading
where Member.ID=Card.UserID and Card.State<>'3' and (Member.ID=Trading.buyID or Member.ID=Trading.sellID )
效果为
.ID .Acc .Peoplename .Mobile .State
1 XX XX XX XX
1 XX XX XX XX
1 XX XX XX XX
1 XX XX XX XX
1 XX XX XX XX
2 XX XX XX XX
2 XX XX XX XX
2 XX XX XX XX
------解决方案--------------------
- SQL code
SELECT Member.ID , Member.Acc , Member.Peoplename , Member.Mobile , Card.STATE , COUNT(1) AS jysumFROM Member , Card , TradingWHERE Member.ID = Card.UserID AND Card.State <> '3' AND ( Member.ID = Trading.buyID OR Member.ID = Trading.sellID )GROUP BY Member.ID , Member.Acc , Member.Peoplename , Member.Mobile , Card.STATE