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

推荐订阅源

H
Help Net Security
博客园 - Franky
GbyAI
GbyAI
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
爱范儿
爱范儿
IT之家
IT之家
酷 壳 – CoolShell
酷 壳 – CoolShell
aimingoo的专栏
aimingoo的专栏
博客园_首页
MongoDB | Blog
MongoDB | Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Recent Announcements
Recent Announcements
Scott Helme
Scott Helme
有赞技术团队
有赞技术团队
M
MIT News - Artificial intelligence
C
CERT Recently Published Vulnerability Notes
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Jina AI
Jina AI
F
Fortinet All Blogs
N
Netflix TechBlog - Medium
L
LangChain Blog
L
LINUX DO - 最新话题
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
H
Hacker News: Front Page
MyScale Blog
MyScale Blog
P
Palo Alto Networks Blog
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
AI
AI
T
Troy Hunt's Blog
Microsoft Azure Blog
Microsoft Azure Blog
阮一峰的网络日志
阮一峰的网络日志
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Vercel News
Vercel News
Microsoft Security Blog
Microsoft Security Blog
罗磊的独立博客
S
Secure Thoughts
大猫的无限游戏
大猫的无限游戏
博客园 - 叶小钗
人人都是产品经理
人人都是产品经理
Blog — PlanetScale
Blog — PlanetScale
博客园 - 司徒正美
Apple Machine Learning Research
Apple Machine Learning Research
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 三生石上(FineUI控件)
S
Security @ Cisco Blogs
Cloudbric
Cloudbric
E
Exploit-DB.com RSS Feed
Attack and Defense Labs
Attack and Defense Labs

博客园 - brake

dataview 查询 - brake - 博客园 名言名心事 一个男人写给老婆的年终总结 一个系统工程,并不是说要每个部件能力都最强、系统最好、性能最优才是最好,关键是要协调,各个部件协调匹配才是最好 成功并没有模式,每个人走的路都不一样 让学习成为一种习惯,当学习成为一种习惯时,你就会欲罢不能.想不学都不行! 解析HTML文件 - 运用SgmlReader类来解析HTML文件 asp.net實現異步調用總結 資料表欄位自动增量属性去除 Illustrator工具也能匯出XAML Code 如何讀取http地址頁面內容,http地址有可能是夸網站 - brake - 博客园 从对技术“新”、“奇”、“特”的一味追捧,到对稳定系统、成熟产品的理性认识,以及多次探讨“业务”与“技术”的关系之后,没有最好的技术,只有恰当的技术! WCF議程 WCF开发指南(自编) C# 實現關機,重啟電腦 圖片從右向左出現 ASP导出Excel数据的四种方法 C#编写Windows服务的基本过程 C# 用SQLDMO.dll 备份和恢复数据库
SQL 查询关键字用法祥解
brake · 2009-06-28 · via 博客园 - brake

1 case关键字

-----case start-------------------------------------------------------------------------------------
/*
关键字 case 
case 语法
--------1-----------------------------------------------------------------------------------------------
case     <表达式A> 
     when  <Α> then   <值A>
     when  <表达式B> then   <值B>
     when  <表达式C> then   <值C>
     else <值D>
end
----------2---------------------------------------------------------------------------------------------
case       when  <条件表达式1> then   <值A>
    when  <条件表达式2> then   <值B>
    when  <条件表达式3> then   <值C>
    else <值D>
end
*/

create table tabCase (UID int ,Areaid varchar(10),price money)
insert into tabCase select 1,    'GD',    8
 
union  select  2,    'GD',    10
 
union  select 3,    'GX',    12
 
union  select 4,    'GX',    14
 
union  select 5,    'SD',    16
 
union  select 6,    'SD',    18
 
union  select 7,    'GX',    20
 
union  select 8,    'SD',    30
 
union  select 9,    'GX',    40
 
union  select 10,    'GD',    50

select UID , Areaid , price from tabCase

select UID, case areaid when 'GD' then '广东'
         
when 'GX' then '广西'
         
when 'SD' then '山东'
        
end as AreaidName 
,price 
    
from tabCase 
----------------------------------------------------------------------------------------------------
select UID, case areaid when 'GD' then '广东'
         
when 'GX' then '广西'
         
when 'SD' then '山东'
        
end as Areaid 
,
case when price <=10 then '超低价商品'  
    
when price <=20 then '低价商品'  
    
when price <=50 then '高价商品'  
    
end as price
    
from tab 
------------------------------------------------------------------------------------------
select Areaid
,GDCount 
= sum(case when areaid='GD' then 1 else 0 end )
,GXCount 
= sum(case when areaid='GX' then 1 else 0 end )
,SDCount 
= sum(case when areaid='SD' then 1 else 0 end )
from tab group by areaid

drop table tab 
-----case End-------------------------------------------------------------------------------------

2 convert 关键字

----convert start----------------------------------------------------
--
1 日期转换并格式化
select convert(varchar,getdate(),120) , convert(varchar,getdate(),108)
--2 其它数据类型转换
select convert(int '12'),convert(varchar,125)
----convert end----------------------------------------------------

100 豎表轉橫表

drop table tb
create table tb(UserName varchar(10) , Subject varchar(10) , Score int)
insert into tb values('張三' , '語文' , 74)
insert into tb values('張三' , '數學' , 83)
insert into tb values('張三' , '物理' , 93)
insert into tb values('李四' , '語文' , 74)
insert into tb values('李四' , '數學' , 84)
insert into tb values('李四' , '物理' , 94)
select UserName,sum(case when Subject= '物理' then Score else 0 end[物理],sum(case when Subject= '語文' then Score else 0 end[語文],sum(case when Subject= '數學' then Score else 0 end[數學] from tb group by UserName
declare @sql varchar(1000)
set @sql='select UserName'
select @sql=@sql+',sum(case when Subject= ''' +Subject+ ''' then Score else 0 end) ['+Subject+']' from (select distinct Subject from tb)a
set @sql = @sql + ' from tb group by UserName'
print @sql
exec(@sql

 3 比較二個日期區(DateS1,DateE1) , (DateS2,DateE2 )間是否有交集 ,有交集返回1,否則返回0

Code


4 SQL 分頁儲存過程

Code


5 根據 資料表生成新增SQL句語

Code


6 獲得表指定列的最大值加一

Code