SQL CASE的用法,比想象中的强大
表如下
一条语句显示所有大于25岁和下的人,以上的人显'大龄'
select case when age>25 then '大龄' else '小龄' end as 年龄级别,count(*) as 人数 from infor group by case when age>25 then '大龄' else '小龄' end
相关文档:
table a(id, type):
id type
----------------------------------
1 1
2 1
3 &n ......
--当前使用的数据库是 系统自带的 master
create database temp1
go --此处不加go的话下面use temp1 会报错:找不到存储过程 'temp1'。
use temp1
set xact_abort on
begin tran
create table [order]( --order是关键字必须用[ ];
id int
)
create table fOrder(
id int
)
-- 下面的操作主要是为了实现fO ......
---SQL实现完全排列组合
create function F_strSpit(@s varchar(200)) returns table
as
return(
select value=substring(@s,i,num)+substring(@s,num-1+j,1)
from (select num=number from spt_values where type='p' and number<len(@s) and number>0)TA,
(select i=number+1 from spt_values where type='p ......
方法一:
select CONVERT(varchar, getdate(), 120 )
2004-09-12 11:06:08
select replace(replace(replace(CONVERT(varchar, getdate(), 120 ),\'-\',\'\'),\' \',\'\'),\':\',\'\')
20040912110608 h
select CONVERT(varchar(12) , getdate(), 111 )
2004/09/12
select CONVERT(varchar(12) , getdate(), 11 ......
信息表(infor)工资表(pay)
内连接
select pay.name,infor.AGE,PAY.MONEY,infor.email from pay join infor on infor.name=PAY.name
左外连接
select pay.name,infor.AGE,PAY.MONEY,infor.email from pay left join infor on infor.name=PAY.name
PS:结果有王五,工资为0
右外连接
select pay.name,info ......