几个简单的基本的sql语句
选择:select * from table1 where 范围
插入:insert into table1(field1,field2) values(value1,value2)
删除:delete from table1 where 范围
更新:update table1 set field1=value1 where 范围
查找:select * from table1 where field1 like ’%value1%’
排序:select * from table1 order by field1,field2 [desc]
总数:select count ( *) as totalcount from table1
求和:select sum(field1) as sumvalue from table1
平均:select avg(field1) as avgvalue from table1
最大:select max(field1) as maxvalue from table1
最小:select min(field1) as minvalue from table1
初学者必须掌握滴 ......
在Oracle SQL中取数据时有时要用到in 和 exists 那么他们有什么区别呢?
1 性能上的比较
比如Select * from T1 where x in ( select y from T2 )
执行的过程相当于:
select *
from t1, ( select distinct y from t2 ) t2
where t1.x = t2.y;
相对的
select * from t1 where exists ( select null from t2 where y = x )
执行的过程相当于:
for x in ( select * from t1 )
loop
if ( exists ( select null from t2 where y = x.x )
then
OUTPUT THE RECORD
end if
end loop
表 T1 不可避免的要被完全扫描一遍
分别适用在什么情况?
以子查询 ( select y from T2 )为考虑方向
如果子查询的结果集很大需要消耗很多时间,但是T1比较小执行( select null from t2 where y = x.x )非常快,那么exists就比较适合用在这里
相对应得子查询的结果集比较小的时候就应该使用in.
2 含义上的比较
在标准的scott/tiger用户下
EMPNO
ENAME
JOB
MG ......
在Oracle SQL中取数据时有时要用到in 和 exists 那么他们有什么区别呢?
1 性能上的比较
比如Select * from T1 where x in ( select y from T2 )
执行的过程相当于:
select *
from t1, ( select distinct y from t2 ) t2
where t1.x = t2.y;
相对的
select * from t1 where exists ( select null from t2 where y = x )
执行的过程相当于:
for x in ( select * from t1 )
loop
if ( exists ( select null from t2 where y = x.x )
then
OUTPUT THE RECORD
end if
end loop
表 T1 不可避免的要被完全扫描一遍
分别适用在什么情况?
以子查询 ( select y from T2 )为考虑方向
如果子查询的结果集很大需要消耗很多时间,但是T1比较小执行( select null from t2 where y = x.x )非常快,那么exists就比较适合用在这里
相对应得子查询的结果集比较小的时候就应该使用in.
2 含义上的比较
在标准的scott/tiger用户下
EMPNO
ENAME
JOB
MG ......
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import xml.dao.admin.AdminArea;
public class NativeSQLQuery extends HibernateDaoSupport {
/**
* 将数据库查询出的数据转化为AdminArea
* @param queryString 查询admin_area表数据的sql语句
* @param pojoClass
* @param jdbcTemplate
* @return
*/
public List<? extends AdminArea> findObjectBySql(String queryString,
Class<? extends AdminArea> pojoClass, JdbcTemplate jdbcTemplate) {
Session session = this.getSession();
/**
* 使用SQL构造查询对象,此SQL是可以被JDBC接受的SQL,如SELECT * from XXX_TABLE
*/
Query query = session.createSQLQuery(queryString);
/**
* 设置结果集转换器
*/
&nbs ......
资料引用:http://www.knowsky.com/339654.html
我的操作系统为Windows 2003 Server , 文件系统NTFS, 在SQL Server 2005 Express 上附加(Attach)从另外一台电脑Copy过来的数据库后,数据库为“只读”。如下图:
解决办法:
打开 SQL Server Configuration Manager, 打开SQL Server SQLEXPRESS 的属性,如下图:
在内置帐号处,把“网络服务”改成“本地系统”,重新启动SQL Server 2005 Express 后,再附加(Attach)数据库一切正常。
总结:之所以附加(Attach)上的数据库为“只读”,是因为启动SQL Server 的默认的启动帐号“网络服务”对所附加(Attach)的数据库文件的权限不够造成的。
......
SELECT id,ip,from_unixtime(last_task_request_time) t1, from_unixtime(last_task_finish_time) t2
from yq_nodemanage
WHERE node_type=1
ORDER BY t1 DESC;
SELECT sum(unix_timestamp(gather_time)-unix_timestamp(publish_time))/(count(*)*60) from yq_bbs_docinfo
WHERE unix_timestamp(publish_time)>unix_timestamp(now())-12*3600
AND publish_time<gather_time; ......
在性能上,mysql是相当出色的,桌面格式myisam数据库与磁盘非常地兼容而不占用过多的cpu和内存,mysql内部很多时候都使用64位整数处理。yahoo就使用mysql后台数据库。
但mysql缺少一些附加功能,没有SqlServer全面。
sqlserver稳定型强,但必须增加额外复杂操作,磁盘存储,内存损耗等,对硬件软件要求都很高。
这两个数据库都能够在.net或j2ee下运行正常,都能够利用raid。 ......
在性能上,mysql是相当出色的,桌面格式myisam数据库与磁盘非常地兼容而不占用过多的cpu和内存,mysql内部很多时候都使用64位整数处理。yahoo就使用mysql后台数据库。
但mysql缺少一些附加功能,没有SqlServer全面。
sqlserver稳定型强,但必须增加额外复杂操作,磁盘存储,内存损耗等,对硬件软件要求都很高。
这两个数据库都能够在.net或j2ee下运行正常,都能够利用raid。 ......