当前位置: 编程技术>综合
本页文章导读:
▪Django项目5 准备工作
django-admin.py startproject web05
django-admin.py startapp blog
blog注册到settings.py中
python manage.py runserver配置url
from django.conf.urls.defaults import patterns, include, url
urlpatterns = patterns('',
url(r'^blog/index.........
▪oralce中的join 连接 Joins
A join is a query that combines rows from two or more tables, views, or materialized views. Oracle Database performs a join whenever multiple tables appear
in the FROM clause of the query. The select list of the query can select any colu.........
▪qt 窗口默认居中 添加头文件:
#include
<QDesktopWidget>
int main(int
argc,
char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
w.move ((QApplication::desktop()->width() - w.width())/2,(QApplication::desktop()->h.........
[1]Django项目5
来源: 互联网 发布时间: 2013-11-07
准备工作
django-admin.py startproject web05 django-admin.py startapp blog blog注册到settings.py中 python manage.py runserver配置url
from django.conf.urls.defaults import patterns, include, url urlpatterns = patterns('', url(r'^blog/index/$','blog.views.index'), )配置views
#coding:utf8 from django.http import HttpResponse from django.template import loader,Context import datetime def index(req): #req只是用来request而已,用别名也可 t=loader.get_template('index.html') now = datetime.datetime.now() emps = [ {}, {}, {}, ] c=Context({ 'a':123, 'now':now, }) html = t.render(c) return HttpResponse(html)配置html,过滤器!
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title></title> </head> <body> {{a|add:'2'}}<br /> {{now|date:'Y m d H i s'}} </body> </html>
作者:forgetbook 发表于2013-1-6 17:01:16 原文链接
阅读:40 评论:0 查看评论
[2]oralce中的join 连接
来源: 互联网 发布时间: 2013-11-07
Joins A join is a query that combines rows from two or more tables, views, or materialized views. Oracle Database performs a join whenever multiple tables appear in the FROM clause of the query. The select list of the query can select any columns from any of these tables. If any two of these tables have a column name in common, then you must qualify all references to these columns throughout the query with table names to avoid ambiguity. Join Conditions Most join queries contain at least one join condition, either in the FROM clause or in the WHERE clause. The join condition compares two columns, each from a different table. 1.To execute a join, Oracle Database combines pairs of rows, each containing one row from each table, for which the join condition evaluates to TRUE. The columns in the join conditions need not also appear in the select list. 2.To execute a join of three or more tables, Oracle first joins two of the tables based on the join conditions comparing their columns and then joins the result to another table based on join conditions containing columns of the joined tables and the new table. Oracle continues this process until all tables are joined into the result. The optimizer determines the order in which Oracle joins tables based on the join conditions, indexes on the tables, and, any available statistics for the tables. -- 连接分类 1.Equijoins 等值连接 示例如下: An equijoin is a join with a join condition containing an equality operator. An equijoin combines rows that have equivalent values for the specified columns. Depending on the internal algorithm the optimizer chooses to execute the join, the total size of the columns in the equijoin condition in a single table may be limited to the size of a data block minus some overhead. The size of a data block is specified by the initialization parameter DB_BLOCK_SIZE. SELECT last_name, job_id, departments.department_id, department_name FROM employees, departments WHERE employees.department_id = departments.department_id ORDER BY last_name; SELECT last_name, job_id, departments.department_id, department_name FROM employees, departments WHERE employees.department_id = departments.department_id AND job_id = 'SA_MAN' ORDER BY last_name; 2.Self Joins 自连接 示例如下:(同一个表的等值连接) SELECT e1.last_name||' works for '||e2.last_name "Employees and Their Managers" FROM employees e1, employees e2 WHERE e1.manager_id = e2.employee_id AND e1.last_name LIKE 'R%'; 3.笛卡尔积 Cartesian Products 3.1 Inner Joins 内连接 An inner join (sometimes called a simple join) is a join of two or more tables that returns only those rows that satisfy the join condition. 3.2 Outer Joins 外连接 (左外连接,右外连接,全外连接) An outer join extends the result of a simple join. An outer join returns all rows that satisfy the join condition and also returns some or all of those rows from one table for which no rows from the other satisfy the join condition. To write a query that performs an outer join of tables A and B and returns all rows from A (a left outer join), use the LEFT [OUTER] JOIN syntax in the FROM clause, or apply the outer join operator (+) to all columns of B in the join condition in the WHERE clause. For all rows in A that have no matching rows in B, Oracle Database returns null for any select list expressions containing columns of B. To write a query that performs an outer join of tables A and B and returns all rows from B (a right outer join), use the RIGHT [OUTER] JOIN syntax in the FROM clause, or apply the outer join operator (+) to all columns of A in the join condition in the WHERE clause. For all rows in B that have no matching rows in A, Oracle returns null for any select list expressions containing columns of A. To write a query that performs an outer join and returns all rows from A and B, extended with nulls if they do not satisfy the join condition (a full outer join), use the FULL [OUTER] JOIN syntax in the FROM clause. 3.3 Antijoins 反连接 An antijoin returns rows from the left side of the predicate for which there are no corresponding rows on the right side of the predicate. That is, it returns rows that fail to match (NOT IN) the subquery on the right side. 反关连的基本语法 反连接是从一个结果集合中返回不在另一个结果集中的数据行。 3.4 Semijoins 半连接 A semijoin returns rows that match an EXISTS subquery without duplicating rows from the left side of the predicate when multiple rows on the right side satisfy the criteria of the subquery. Semijoin and antijoin transformation cannot be done if the subquery is on an OR branch of the WHERE clause. 在我们查看一个数据集中某些字段存在于另一个数据集合中的记录时,常常会用到in 或者exists。在执行计划中会看到join semi。 3.5 自然连接 natural join 3.6 交叉连接 cross join ----------------------------------------------------------------- 测试 create table stu( id number(10), name varchar2(100), phone varchar2(20) ); create table cause( id number(10), name varchar2(100), sid number(10) ); insert into stu values(1,'AAA','123456789'); insert into stu values(2,'BBB','777777777'); insert into stu values(3,'CCC','555555555'); insert into stu values(4,'DDD','222222222'); insert into cause values(1,'JAVA',1); insert into cause values(2,'HIBERNATE',1); insert into cause values(3,'ORACLE',2); insert into cause values(4,'XML',3); insert into cause values(5,'HTML',0); commit; select * from stu; select * from cause; 自然连接:将关联对象所有相同名称的列进行等值连接。 insert into stu values(6,'MMMMM','222222222'); insert into cause values(6,'MMMMM',0); commit; select * from stu natural join cause ; select a.*,b.* from stu a natural join cause b;--自然连接的列不能用别名分别指定并显示在select结果中,打印的时候只输出一列 select a.id,b.name from stu a natural join cause b; select id,name from stu a natural join cause b;--资源连接的列不要指定属于哪个对象 select * from stu natural join cause using(id);--自然连接不能使用usiing 等值连接 就是 内连接 ??? 从结果上看这两个结果是一样的 select * from stu s,cause c where s.id=c.sid; select s.*,c.* from stu s,cause c where s.id=c.sid; select s.*,c.* from stu s,cause c where s.id>c.sid; 内连接 (inner可以省略) select * from stu s inner join cause c on s.id=c.sid; select * from stu s join cause c on s.id=c.sid; select * from stu s join cause c on s.id>c.sid; select * from stu s join cause c on s.id=c.id; select * from stu s join cause c using(id); select s.*,c.* from stu s join cause c using(id);--using用到的列在select时不能指定所属表,打印的时候只输出一列 select * from stu s join cause c using(id,name); select * from stu s inner join cause c on s.id=c.sid where s.name='AAA'; select * from stu s join cause c on s.id=c.sid; 外连接 --用using的话要保证对象之间有相同的列明 左外连接 select * from stu s left outer join cause c on s.id=c.sid; select * from stu s,cause c where s.id=c.sid(+); select * from stu s left outer join cause c using(id);--用using的话要保证对象之间有相同的列明 右外连接 select * from stu s right outer join cause c on s.id=c.sid; select * from stu s,cause c where s.id(+)=c.sid; 全外连接 等于左连接和右连接的union select * from stu s full outer join cause c on s.id=c.sid; select * from stu s,cause c where s.id=c.sid(+) union all select * from stu s,cause c where s.id(+)=c.sid; select * from stu s,cause c where s.id=c.sid(+) union select * from stu s,cause c where s.id(+)=c.sid; 交叉连接=笛卡尔积 select * from stu s cross join cause c; select * from stu s , cause c; --不写where条件 反连接 Using Antijoins: Example The following example selects a list of employees who are not in a particular set of departments: SELECT * FROM employees WHERE department_id NOT IN (SELECT department_id FROM departments WHERE location_id = 1700) ORDER BY last_name; 半连接 Using Semijoins: Example In the following example, only one row needs to be returned from the departments table, even though many rows in the employees table might match the subquery. If no index has been defined on the salary column in employees, then a semijoin can be used to improve query performance. SELECT * FROM departments WHERE EXISTS (SELECT * FROM employees WHERE departments.department_id = employees.department_id AND employees.salary > 2500) ORDER BY department_name; 注意事项: 1、如果在使用using关键字时,而且select的结果列表项中包含了using关键字所指明的那个关键字,那么请不要在select的结果列表项中对该关键字指明它属于哪个表。 2、using中仅能使用一个列名。 3、natural join关键字和using关键字是互斥的,也就是说不能同时出现。
作者:Rookie_CEO 发表于2013-1-6 16:54:37 原文链接
阅读:40 评论:0 查看评论
[3]qt 窗口默认居中
来源: 互联网 发布时间: 2013-11-07
添加头文件:
#include <QDesktopWidget>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
w.move ((QApplication::desktop()->width() - w.width())/2,(QApplication::desktop()->height() - w.height())/2);
return a.exec();
}
作者:aile770339804 发表于2013-1-6 16:50:57 原文链接
阅读:42 评论:0 查看评论
最新技术文章: