sql语句
select *from student
select student_id from student
select student_id ,student_name from student
select student_id student_name from student 将student_name 作为student_id的别名处理
如: select student_id a from student
select a=student_id from student
从student表中分别检索出学生的学号、姓名信息并分别加上“学生”、“学号”的标题信息。
select 学号=student_id,学生=student_name from student
大部分查询都不是针对表中所有行的查询,而是从整个表中选出符合条件的信息,要实现这样的查询就要用到
从student_course表中检索成绩小于60分的学生信息。
select grade from student_course where grade<60
select * from student_course order by student_id
select top 50 percent *from student_course order by student_id 输出总行数的一半
select top 10 *from student_course order by student_id 输出前10行
‘2007-11-18’ convert cast
date'2007-11-18'
student_course表中检索成绩介于60至80分之间的学生信息。
select student_id,grade from student_course where grade between 60 and 80
从student_course表中检索学号为‘g9940202’,‘g9940204’,‘g9940206’的学生信息。
select *from student_course where (student_id='g9940202')or(student_id='g9940204')or(student_id='g9940206')
select *from student_course
select distinct student_id from student_course
select *from student_course where (student_id='g9940202')or(student_id='g9940204')or(student_id='g9940206') order by student_id
从student表中分别检索出姓张的所有同学的资料;名字的第二个字是“红”或“虹”的所有同学的资料
select *from student
select *from student where student_name like '张%'and student_name like '%红'or student_name like '%虹'
select *from student where student_name like '_[红,虹]%'
SELECT * from student WHERE student_name LIKE '_[红,虹]%'
SELECT * from student WHERE student_name LIKE '_[^红,虹]%'
SELECT * from&nbs
相关文档:
SQL宝典
SQL必知必会第三版
SQL入门经典第四版
Sams Teach Yourself SQL in 10 Minutes Third Edition
SQL The Complete Reference
......
SQL Server 得到行号的SQL
使用临时表:
select id=identity(int,1,1),value into #temp from YourTable
select * from #temp
drop table #temp
取得第11到20行记录:
select IDENTITY(in ......
Last login: Mon Feb 8 14:13:19 2010 from 192.168.1.249
ipnet
-bash-3.00$
-bash-3.00$ ipnet
-bash: ipnet: command not found
-bash-3.00$ su - oracle
Password:
eastcsu: incorrect password
-bash-3.00$ eastcom
-bash: eastcom: command not found
-bash-3.00$ su - oracle
Password:
[oracl ......
1、在数据库建表的时候字段直接设置为DATETIME类型;
2、执行插入的时候使用如下语句:
PreparedStatement pstmt = conn.prepareStatement("insert into guestbook(gst_user,gst_title,gst_content,gst_ip,gst_time) values(?,?,?,?,getdate())");
3、要把日期从数据库中取出,执行如下语句:
......
1 用UNION替换OR (适用于索引列)
通常情况下, 用UNION替换WHERE子句中的OR将会起到较好的效果. 对索引列使用OR将造成全表扫描. 注意, 以上规则只针对多个索引列有效.
如果有column没有被索引, 查询效率可能会因为你没有选择OR而降低. 在下面的例子中, LOC_ID 和REGION上都建有索引.
高效: SELECT LOC_ID , LOC_DESC , ......