SQL练习
father表 son表
fid fname sid sname fid height money
1 a 100 s1 1 1.7 7000
2 b 101 s2 2 1.6 8000
3 c 102 s3 2 1.8 9000s
create table father(
fid number primary key,
fname varchar(10)
);
create table son(
sid number primary key,
sname varchar(10),
fid number,
height number,
money number
);
select t.*, t.rowid from father t;
select t.*, t.rowid from son t;
1、查询sid、sname、fid
select sid,sname,fid from son;
2、查询各儿子涨价20%以后的新学费,注意,8000块以下的不涨价。
select money*1.2 as new_money from son where money>=8000
union all
select money from son where money<8000;
select '涨了' as 涨价情况,money*1.2 as new_money from son where money>=8000
union all
select '没涨',money from son where money<8000;
select money,money*1.2 as new_money from son where money>=8000
union all
select money,null from son where money<8000;
select son.*,(case when money<8000 then money
when money>=8000 then money*1.2 end)as new_money
from son;
--函数
create or replace function f_get_new_money(p_money son.money%type)
return number
as
begin
if(p_money>=8000)then
return p_money*1.2;
else
return p_money;
end if;
end;
select son.*,scott.f_get_new_money(money) as new_money from son;
--一题多解,下面的题目也是按照这种思路(1.用SQL 2.如果做不来,用函数一定可以)
3、查询sid、sname、fname。
--语法 from t1 join t2 on t1.id=t2.id
SELECT s.sid,s.sname,f.fname
from father f JOIN son s ON f.fid=s.fid;
相关文档:
Sql代码
--采用SQL语句实现sql2005和Excel 数据之间的数据导入导出,在网上找来一--下,实现方法是这样的:
--Excel---->SQL2005 导入:
select * into useinfo from O ......
一、SQL SERVER 和ACCESS的数据导入导出
常规的数据导入导出:
使用DTS向导迁移你的Access数据到SQL Server,你可以使用这些步骤:
○1在SQL SERVER企业管理器中的Tools(工具)菜单上,选择Data Transformation
○2Services(数据转换服务),然后选择 czdImport Dat ......
1. 说明:复制表(只复制结构,源表名:a,新表名:b)
SQL: select * into b from a where 1<>1;
2. 说明:拷贝表(拷贝数据,源表名:a,目标表名:b)
SQL: insert into b(a, b, c) select d, e, f from b;
3. 说明:显示文章、提交人和最后回复时间
SQL: select a.title, a.username, b.ad ......
<%
SQL1 = "update table1 set a=b where id=1"
Conn.ExeCute SQL1
SQL2 = "update table2 set a=b where id=2"
Conn.ExeCute SQL2
SQL3 = "update table3 set a=b where id=3"
Conn.ExeCute SQL3
%>
&nb ......
发布日期 : 1/14/2005 | 更新日期 : 1/14/2005
John Papa
用户定义的函数 (UDF) 是准备好的代码片段,它可以接受参数,处理逻辑,然后返回某些数据。根据 SQL Server Books Online,SQL Server™ 2000 中的 UDF 可以接受从 0 到 1024 的任意个数的参数,不过我必须承认,我还未尝试将 1024 个参数传递到 UDF 中。 ......