一个项目涉及到的50个Sql语句(整理版) 这个帖子的地址是 http://topic.youkuaiyun.com/u/20100517/17/B2AB9D5E-73A2-4F54-A7EC-40A5EABD8621.html
1.关于 nchar 和 nvarchar 和 char 和 varchar
nchar 是固定长度 Unicode 数据的数据类型,nvarchar 是可变长度 Unicode 数据的数据类型,二者均使用 UNICODE UCS-2 字符集
固定长度 (char) 或可变长度 (varchar) 非 Unicode 的字符数据 用N来标识 Unicode 数据类型
2.decimal 和 numeric
带定点精度和小数位数的 numeric 数据类型 decimal(18,2)最大长度是18位,小数点后是2位 cast(avg(b.score) as decimal(18,2))
3.SUBSTRING
SUBSTRING ( expression , start , length ) start 从1开始 SELECT x = SUBSTRING('abcdef', 2, 3)
4.IN 和 exists
select Student.* from Student , SC where Student.S# = SC.S# and SC.C# = '01'
and exists (Select 1 from SC SC_2 where SC_2.S# = SC.S# and SC_2.C# = '02') order by Student.S#
select Student.* from Student , SC where Student.S# = SC.S# and SC.C# = '01'
and Student.S# in (Select SC_2.S# from SC SC_2 where SC_2.S# = SC.S# and SC_2.C# = '02') order by Student.S#