惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The Cloudflare Blog
L
LangChain Blog
WordPress大学
WordPress大学
V
V2EX
M
MIT News - Artificial intelligence
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Stack Overflow Blog
Stack Overflow Blog
J
Java Code Geeks
F
Fortinet All Blogs
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
腾讯CDC
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
D
Docker
Recent Announcements
Recent Announcements
GbyAI
GbyAI
博客园 - 叶小钗
小众软件
小众软件
Hugging Face - Blog
Hugging Face - Blog
T
The Blog of Author Tim Ferriss
人人都是产品经理
人人都是产品经理
Engineering at Meta
Engineering at Meta
Y
Y Combinator Blog
雷峰网
雷峰网
The GitHub Blog
The GitHub Blog

博客园 - 冷风.net

以OO的思想利用JS來實現五子棋 開放幾個原來寫的js代碼,供大家娛樂一下 使用JS寫的第一個游戲[俄羅斯方塊] 假如現在讓你去說服客戶使用asp.net2.0開發系統,你會怎麼說服呢? 對象化javascript日期控件 - 冷风.net - 博客园 工作排程 防止圖片在WEB頁面上下載 - 冷风.net - 博客园 今天從新整理的大小寫數據轉換 - 冷风.net - 博客园 常用的XPATH說明 XmlHttp在DoNet中的完全应用---前/后台完成分离篇 系统用户权限与角色分析 学习设计模式之Composite 模式 改進Richer的WEB頁面進度條! 学习设计模式之Bridge模式 学习设计模式之生成器(Builder Pattern)模式 再谈Abstract Factory模式来实现数据库操作的类 Factory Method来实现数据库操作的类 不周表結構合併問題 利用線程實現錠時執行的運行模型
今天下午困惑的問題,終於TMD搞出來了
冷风.net · 2005-01-07 · via 博客园 - 冷风.net

今天下午郁悶,遇到了下面這個問題,應為以前對case用得少,所以開始沒有想到這上面來,還從什麼鬼游標等其它方面著首去想,真TMD的花了好久時間,後來看到CASE的用法後,呵呵,就簡單了

表名:TableName
字段名 日期
feild    date
abcde  20005-01-01
abc    20005-01-01
abcd   20005-01-01
abcde  20005-01-01
ab     20005-01-02
abc    20005-01-02
abcd   20005-01-02
abcde  20005-01-02
abcd   20005-01-03
abc    20005-01-03

現在查各日期內的字符串的長度為>=1,>=2,>=3,>=4,>=5的各有多少個
如上結果應為:
1   2   3   4   5  日期
4   4   4   3   2  20005-01-01
4   4   3   2   1  20005-01-02
2   2   2   1   0  20005-01-03

select len(field) as lenfield,date  into #countTable form TableName order by date
select sum(case when lenfield>=1 then 1 else 0) as fid1,
sum(case when lenfield>=2 then 1 else 0) as fid2,
sum(case when lenfield>=3 then 1 then 0) as fid3,
sum(case when lenfield>=4 then 1 then 0) as fid4,
sum(case when lenfield>=5 then 1 then 0) as fid5
into #returnTable
from #countTable
group by date
drop table #countTable
drop table #returnTable