1、 delete tablename where 自动编号 not in(select min(自动编号) from tablename group by 学号,姓名,课程编号,课程名称,分数)一个叫department的表,里面只有一个字段name,一共有4条纪录,分别是a,b,c,d,对应四个球对,现在四个球对进行比赛,用一条sql语句显示所有可能的比赛组合.你先按你自己的想法做一下,看结果有我的这个简单吗?答:select a.name, b.name from team a, team b where a.name b.Debit101ccur*面试题:怎么把这样一个表儿yearmont
2、h amount1991 1 1.1 2 1.2 3 1.3 4 1.41992 2.1 2.2 2.3 2.4查成这样一个结果year m1m2m3m41991 1.1 1.2 1.3 1.41992 2.1 2.2 2.3 2.4 答案一、select year, (select amount fromaaa m where month=1and m.year=aaa.year) as m1,aaa m where month=2and m.year=aaa.year) as m2,aaa m where month=3and m.year=aaa.year) as m3,aaa m wh
3、ere month=4and m.year=aaa.year) as m4from aaagroup by year这个是ORACLE中做的:select * from (select name, year b1, lead(year) over(partition by name order by year) b2, lead(m,2) over(partition by name order by year) b3,rank()over(partition by name order by year) rk from t) where rk=1;精妙的SQL语句!精妙SQL语句作者:不详
4、发文时间:2003.05.29 10:55:05 说明:复制表(只复制结构,源表名:a 新表名:b) SQL: select * into b from a where 11 拷贝表(拷贝数据,源表名:a 目标表名: insert into b(a, b, c) select d,e,f from b;显示文章、提交人和最后回复时间 select a.title,a.username,b.adddate from table a,(select max(adddate) adddate from table where table.title=a.title) b 外连接查询(表名1:a 表名
5、2: select a.a, a.b, a.c, b.c, b.d, b.f from a LEFT OUT JOIN b ON a.a = b.c 日程安排提前五分钟提醒 select * from 日程安排 where datediff(minute,f开始时间,getdate()5 两张关联表,删除主表中已经在副表中没有的信息 delete from info where not exists ( select * from infobz where info.infid=infobz.infid ) - SELECT A.NUM, A.NAME, B.UPD_DATE, B.PREV_
6、UPD_DATE FROM TABLE1, (SELECT X.NUM, X.UPD_DATE, Y.UPD_DATE PREV_UPD_DATE FROM (SELECT NUM, UPD_DATE, INBOUND_QTY, STOCK_ONHAND FROM TABLE2 WHERE TO_CHAR(UPD_DATE,YYYY/MM) = TO_CHAR(SYSDATE, ) X, (SELECT NUM, UPD_DATE, STOCK_ONHAND ) = TO_CHAR(TO_DATE(TO_CHAR(SYSDATE, ) /01,YYYY/MM/DD) - 1, ) ) Y, W
7、HERE X.NUM = Y.NUM (+) AND X.INBOUND_QTY + NVL(Y.STOCK_ONHAND,0) desc course_v Name Null? Type - - - COURSEID NUMBER COURSENAME VARCHAR2(10) SCORE NUMBER select * from course_v;COURSEID COURSENAME SCORE - - - select courseid, coursename ,score ,decode(sign(score-60),-1,) as mark from course_v;COURSE
8、ID COURSENAME SCORE MARK - - - - 5 servlet 80 passid proid proname 1 1 M 1 2 F 2 1 N 2 2 G 3 1 B 3 2 A 查询后的表:id pro1 pro2 1 M F 2 N G 3 B A 写出查询语句解决方案 sql求解 表a 列 a1 a2 记录 1 a 1 b 2 x 2 y 2 z 用select能选成以下结果吗?1 ab 2 xyz 使用pl/sql代码实现,但要求你组合后的长度不能超出oracle varchar2长度的限制。下面是一个例子 create or replace type str
9、ings_table is table of varchar2(20);/ create or replace function merge (pv in strings_table) return varchar2 is ls varchar2(4000);begin for i in 1.pv.count loop ls := ls | pv(i);end loop;return ls;end;create table t (id number,name varchar2(10);insert into t values(1,Joan);JackTominsert into t value
10、s(2,RoseJennycolumn names format a80;select t0.id,merge(cast(multiset(select name from t where t.id = t0.id) as strings_table) names from (select distinct id from t) t0;drop type strings_table;drop function merge;drop table t;用sql:Well if you have a thoretical maximum, which I would assume you would
11、 given the legibility of listing hundreds of employees in the way you describe then yes. But the SQL needs to use the LAG function for each employee, hence a hundred emps a hundred LAGs, so kind of bulky. This example uses a max of 6, and would need more cut n pasting to do more than that. select de
12、ptno, dname, emps 2 from ( 3 select d.deptno, d.dname, rtrim(e.ename |, | 4 lead(e.ename,1) over (partition by d.deptno 5 order by e.ename) |6 lead(e.ename,2) over (partition by d.deptno 7 order by e.ename) |8 lead(e.ename,3) over (partition by d.deptno 9 order by e.ename) |10 lead(e.ename,4) over (
13、partition by d.deptno 11 order by e.ename) |12 lead(e.ename,5) over (partition by d.deptno 13 order by e.ename),) emps, 14 row_number () over (partition by d.deptno 15 order by e.ename) x 16 from emp e, dept d 17 where d.deptno = e.deptno 18 ) 19 where x = 1 20 / DEPTNO DNAME EMPS - - - 10 ACCOUNTIN
14、G CLARK, KING, MILLER 20 RESEARCH ADAMS, FORD, JONES, ROONEY, SCOTT, SMITH 30 SALES ALLEN, BLAKE, JAMES, MARTIN, TURNER, WARD also 先create function get_a2;create or replace function get_a2( tmp_a1 number) return varchar2 Col_a2 varchar2(4000);Col_a2:=;for cur in (select a2 from unite_a where a1=tmp_
15、a1) loop Col_a2=Col_a2|cur.a2;return Col_a2;end get_a2;select distinct a1 ,get_a2(a1) from unite_a 1 ABC 2 EFG 3 KMN一个SQL 面试题 去年应聘一个职位未果,其间被考了一个看似简单的题,但我没有找到好的大案.不知各位大虾有无好的解法?题为:有两个表, t1, t2,Table t1:SELLER | NON_SELLER- -A BA CA DB AB CB DC AC BC DD AD BD CTable t2:SELLER | COUPON | BAL- - -A 9 100B 9 200C 9 300D 9 400A 9.5 100B 9.5 20A 10 80要求用SELECT 语句列出如下结果:-如A的SUM(BAL)为
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1