---報表:城市、截止開通數、上週開通數、上上週開通數
--第一版
select cc.cityname ,
sum(t1.storecnt) as totalopencnt ,
sum(case t2.flag
when 1 then t1.storecnt
else 0
end) as weekopencnt ,
sum(case t3.flag
when 1 then t1.storecnt
else 0
end) as preweekopencnt
from dbo.rms_companylist cc
left join ( select c.companyno ,
count(c.companyno) storecnt
from dbo.crm_company c
left join dbo.crm_companystore cs on c.id = cs.companyid
where cs.isdelete = 0
and c.isdelete = 0
group by c.companyno
) t1 on t1.companyno = cc.companyno
left join ( select 1 as flag ,
companyno
from dbo.rms_companylist
where rowdate >= '2017-06-16'
and rowdate <= '2017-06-22'
) t2 on t2.companyno = cc.companyno
left join ( select 1 as flag ,
companyno
from dbo.rms_companylist
where rowdate >= dateadd(day, -7, '2017-06-16')
and rowdate <= dateadd(day, -7, '2017-06-22')
) t3 on t3.companyno = cc.companyno
where rowdate <= '2017-07-11'
and companyname != '房屋管家'
and companyname not like '%實惠%'
and companyname not like '%測試%'
and cityname in ( '上海', '杭州', '鄭州', '重慶', '武漢', '合肥', '濟南', '南京' )
group by cityname
--第二版
select cc.cityname ,
isnull(sum(1), 0) as totalopencnt ,
isnull(sum(case when rowdate >= '2017-06-16'
and rowdate <= '2017-06-22' then 1
else 0
end), 0) as weekopencnt ,
isnull(sum(case when rowdate >= dateadd(day, -7, '2017-06-16')
and rowdate <= dateadd(day, -7, '2017-06-22')
then 1
else 0
end), 0) as preweekopencnt
from dbo.rms_companylist cc
left join crm_company c on c.companyno = cc.companyno
left join crm_companystore cs on cs.companyid = c.id
where c.isdelete = 0
and cs.isdelete = 0
and exists ( select *
from rms_companylist e
where e.companyid = cc.companyid
and e.rowdate <= '2017-07-11'
and e.companyname != '房屋管家'
and e.companyname not like '%實惠%'
and e.companyname not like '%測試%'
and e.cityname in ( '上海', '杭州', '鄭州', '重慶', '武漢',
'合肥', '濟南', '南京' ) )
group by cityname
--第三版
select cc.cityname ,
sum(t1.storecnt) as totalopencnt ,
sum(case t2.flag
when 1 then t1.storecnt
else 0
end) as weekopencnt ,
sum(case t3.flag
when 1 then t1.storecnt
else 0
end) as preweekopencnt
from ( select cityname ,
rowdate ,
companyno ,
case when companyname = '房屋管家' then 0
when charindex('實惠', companyname) > 0 then 0
when charindex('測試', companyname) > 0 then 0
else 1
end as companystatus
from dbo.rms_companylist
) cc
left join ( select c.companyno ,
count(c.companyno) storecnt
from dbo.crm_company c
left join dbo.crm_companystore cs on c.id = cs.companyid
where cs.isdelete = 0
and c.isdelete = 0
group by c.companyno
) t1 on t1.companyno = cc.companyno
left join ( select 1 as flag ,
companyno
from dbo.rms_companylist
where rowdate >= '2017-06-16'
and rowdate <= '2017-06-22'
) t2 on t2.companyno = cc.companyno
left join ( select 1 as flag ,
companyno
from dbo.rms_companylist
where rowdate >= dateadd(day, -7, '2017-06-16')
and rowdate <= dateadd(day, -7, '2017-06-22')
) t3 on t3.companyno = cc.companyno
where rowdate <= '2017-07-11'
and cityname in ( '上海', '杭州', '鄭州', '重慶', '武漢', '合肥', '濟南', '南京' )
and companystatus = 1
group by cityname
--第四版
select cc.cityname ,
isnull(sum(1), 0) as totalopencnt ,
isnull(sum(case when rowdate >= '2017-06-16'
and rowdate <= '2017-06-22' then 1
else 0
end), 0) as weekopencnt ,
isnull(sum(case when rowdate >= dateadd(day, -7, '2017-06-16')
and rowdate <= dateadd(day, -7, '2017-06-22')
then 1
else 0
end), 0) as preweekopencnt
from ( select cityname ,
rowdate ,
companyno ,
case when companyname = '房屋管家' then 0
when charindex('實惠', companyname) > 0 then 0
when charindex('測試', companyname) > 0 then 0
else 1
end as companystatus
from dbo.rms_companylist
) cc
left join crm_company c on c.companyno = cc.companyno
left join crm_companystore cs on cs.companyid = c.id
where c.isdelete = 0
and cs.isdelete = 0
and cc.companystatus = 1
and cc.rowdate <= '2017-07-11'
and cc.cityname in ( '上海', '杭州', '鄭州', '重慶', '武漢', '合肥', '濟南', '南京' )
group by cityname
一次sql注入攻擊
喜歡學習 但是不想找漏洞 好麻煩 還不一定有乙個漏洞 是我在google上搜到的 畫面看著高大上 乙個頁面乙個頁面的找,尋找有輸入引數的地方,然後進行測試 本來我以為沒有注入的時候 突然 看到了一小句話 wow 有報錯資訊 可以進行報錯注入 想著可以提交烏雲了 然後先 order by 測試下有幾個...
ibatis一次sql過程
為了理清楚 ibatis一次sql過程中發生了什麼,本文將對ibatis一次sql過程做簡要的分析。string resource mybatis.cfg.xml reader reader resources.getresourceasreader resource sqlsessionfacto...
記一次sql查詢
效果圖 要查詢出如上圖的效果 知識點.1.多表巢狀查詢.2.輸出查詢結果,group concat函式 3.關聯查詢 select t1.學校,case when t1.年級 2017 then 1年級 when t1.年級 2016 then 2年級 when t1.年級 2015 then 3年...