SQL筆記

  • 38
  • 0
Select a.Years,
(Select Count(*) from table where Type = '代碼' and years = a.years) as '代碼異常',
(Select Count(*) from table where Type = '地址' and years = a.years) as '地址異常',
(Select Count(*) from table where Type = '電話' and years = a.years) as '電話異常'
from (Select Distinct years from table ) as a

 

...繼續閱讀 »

SQL Left join...on..

  • 57
  • 0

當我下指令
select  years, casecnt
from tablename
where CompanyName = 'A公司'
and Years between 2015 and 2019

結果是
years | casecnt
2018  | 3
2016  | 4
2015  | 7

但我希望能顯示結果如下

years | casecnt
2019  | 0
2018  | 3
2017  | 0
2016  | 4
2015  | 7       

...繼續閱讀 »

SQL取中間筆數

  • 713
  • 0

SQL取中間筆數的語法

https://social.msdn.microsoft.com/Forums/sqlserver/en-US/5e6c05cb-1129-4bfe-a45b-e8cb2892e240/how-select-range-10-to-20-record-of-sql-bank?forum=sqldataaccess

 

...繼續閱讀 »