[size=x-large]select
count(tsuser.fid),
(case when tsuser.fstoreid is not null then (select s.fname from tustore s where s.fid=tsuser.fstoreid ) end ) a, //使用者的門店id不未空 就顯示當前門店名稱
(case tcwxprofile.fissubscribe when 0 then '未關注' when 1 then '已關注' else '未關注' end ) sub,
count(case when tcwxprofile.fissubscribe=1 then tcwxprofile.fissubscribe end) s, //統計已關注
count(case when tcwxprofile.fissubscribe is null then tcwxprofile.fid when tcwxprofile.fissubscribe=0 then tcwxprofile.fid end) //統計取消關注或未關注
from tcwxprofile
inner join tsuser on tcwxprofile.fuserid=tsuser.fid
inner join tccustomer on tsuser.ftypeinstanceid=tccustomer.fid
group by a
order by count(tsuser.fid) desc[/size]
case 欄位名 when 值 then 結果
case when salary <= 500 then '1'
when salary > 500 and salary <= 600 then '2'
when salary > 600 and salary <= 800 then '3'
when salary > 800 and salary <= 1000 then '4'
else null end salary_class,
date_format(欄位名,'%y-%m-%d') 顯示2015-10-10
一句sql 分組統計數量
size x large select count tsuser.fid case when tsuser.fstoreid is not null then select s.fname from tustore s where s.fid tsuser.fstoreid end a,使用者的門店...
SQL 一句sql 分頁
有關分頁 sql 的資料很多,有的使用儲存過程,有的使用游標。本人不喜歡使用游標,我覺得它耗資 效率低 使用儲存過程是個不錯的選擇,因為儲存過程是經過預編譯的,執行效率高,也更靈活。先看看單條 sql 語句的分頁 sql 吧。方法1 適用於 sql server 2000 2005 select t...
一句SQL搞定分頁
xpsql 使用者名稱 like 王 sql string.format select from select row number over order by as keelid,from as keeltemp where keeltemp.keelid and keeltemp.keelid ...