首頁  >  文章  >  資料庫  >  数据库表查询高级 触发器游标等

数据库表查询高级 触发器游标等

WBOY
WBOY原創
2016-06-07 17:38:10853瀏覽

SQL语句的执行顺序 SELECT 语句的处理顺序。 1.FROM 2.ON 3.JOIN 4.WHERE 5.GROUP BY 6.WITH CUBE 或 WITH ROLLUP 7.HAVING 8.SELECT 9.DISTINCT 10.ORDER BY 11.TOP 类型转换函数和union CAST ( expression AS data_type) CONVERT ( data_type, expression,

SQL语句的执行顺序

  SELECT 语句的处理顺序。

1.FROM

2.ON

3.JOIN

4.WHERE

5.GROUP BY

6.WITH CUBE 或 WITH ROLLUP

7.HAVING

8.SELECT

9.DISTINCT

10.ORDER BY

11.TOP

  类型转换函数和union

CAST ( expression AS data_type)

CONVERT ( data_type, expression,[style])

Select ‘您的班级编号’+ 1 错误这里+是数学运算符

SELECT FIdNumber,

CAST(RIGHT(sNo,3) AS int) as 后三位的整数形式,

CAST(RIGHT(sNo,3) AS int)+1 as 后三位加1,

CONVERT(int,RIGHT(sNo,3))/2 as 后三位除以2

FROM student

select fname,LEN(FName) as '名字的长度' from MyStudent

--CAST ( 要转换的数据/字段AS 目标数据类型)

select

cast(ISNULL(fmath,0) as varchar(10))+

cast(ISNULL(fenglish,0) as varchar(10))

from MyStudent

select cast(1 as varchar(10))+cast(1 as varchar(10))

--CONVERT ( 目标数据类型, 待转的数据或字段)

select Convert(varchar(10),1)+ Convert(varchar(10),1)

select * from MyStudent

select Convert(varchar(10),fage)+fgender from MyStudent

select CONVERT(varchar(20), getdate(),23)

--union联合后会删除相同内容的行,union all不会

--union 1)列数相同 2)对应列的类型相同

select * from newStudent union all

select * from newStudent2

--显示班级的数学和英语成绩,,以及总成绩?

select fname,fmath,fenglish from newStudent

union all

select '总分:',sum(fmath),sum(fenglish) from newStudent

select 1,80,100 union all

select 1,80,100 union

select 3,50,59 union all

select 4,66,89 union

select 5,59,100

存储过程(procedure)

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn