select k.sectionname as 區域, p.partnercode as 經銷商編號,
p.partnername as 經銷商公司名稱,p.telephone as 經銷商聯絡**,
s.loginid as 會員登入帳號,s.[name] as 會員姓名,s.telephone as 會員聯絡**,
s.mobilephone as 會員手機,s.email as email,convert(varchar(10),p.joindate ,20) as
加入公司時間,isnull(m.livescore,0) as 目前活動積分,
isnull(m.salesscore,0) as 目前銷售積分,
isnull(isnull(sum(med.livescore),0)+isnull(sum(med.salesscore),0),0) as '全部已兌換積分',
convert(varchar(10),s.birthday,20) as 出生日期,
convert(varchar(20),sa.lastlogintime,20) as 最後一次登入時間
from partner as p
left join sales as s on p.partnerid=s.partnerid
left join memberscore as m on s.salesid =m.salesid
left join salesaccessinfo as sa on s.salesid=sa.salesid
left join memberscoreexchangedetail as med on s.salesid=med.salesid
inner join kmsectionpartnerrelation as kpr on kpr.partnerid=p.partnerid
inner join kmsection k on k.sectionid= kpr.sectionid
where (s.status =0 or s.status =2 )
group by p.partnercode ,p.partnername ,p.telephone ,
s.loginid ,s.[name],s.telephone ,
s.mobilephone,s.email,p.joindate,m.livescore ,
m.salesscore ,
s.birthday ,sa.lastlogintime ,k.sectionname
order by p.partnername ,s.[name]
sql 左聯 右聯 內聯的區別
如有表 a col1,col2 a,1b,1 b col1,col2 a,3c,2 內部聯接是指只返回符合聯接條件的資料,如select from a join b on a.col1 b.col1 只返回符合條件a.col1 b.col1的資料 結果如下 a,1,a,3 左外聯接不僅返回符合條件的...
關於資料庫內聯接和左聯接
在學習資料庫的時候選擇的是一本翻譯書,有些概念沒有搞清楚,現在總結一下。內聯接語句 select from table1 one inner join table2 two on one.table1 id two.table2 id 返回的結果是兩個表中都存在的匹配資料 左聯接語句select f...
SQL語句左聯 右聯 內聯的區別
關於sql語句連線的思考 create table test1 id bigint 20 not null auto increment,name varchar 20 default null,grade int 20 not null,primary key id insert into tes...