ICPNO NOT NULL VARCHAR2(6)
SERVICE_ID NOT NULL VARCHAR2(10)
STAT_MIN NOT NULL DATETIME
MT_RECV_OK NOT NULL NUMBER(10)
请写出一条SQL语句同时满足以下3个条件: 计算MT_RECV_OK的总和(显示为total),并以此对结果集进行升序排序 以ICPNO和SERVICE_ID两个字段进行分组 所得出数据的STAT_MIN必须为大于2003年1月1号0时0分并且小于2003 年2月1号0时0分 期望的输出结果如下: ICPNO SERVICE_ID TOTAL ———— —————— ———————————— 901001 7700 271965 901001 7800 3857795 答:
select ICPNO,SERVICE_ID,sum(MT_RECV_OK) TOTAL from ismg_icp_flow where STAT_MIN between to_date(‘2003-1-1‘,‘yyyy-mm-dd‘) and to_date(‘2003-2-1‘,‘yyyy-mm-dd‘) group by ICPNO,SERVICE_ID order by TOTAL;
Student(S#,SN,SD)学生表 Course(C#,CN,T#)课程表 SC(S#,C#,score)成绩表 1.查询选了课程‘税收’的学生的学号和名字 答:
select SN,SD from Student where S# in( select S# from Course C , SC where C.C#=SC.C# and CN= ’税收基础’);
2.查询选课数量大于5的学生的学号和名字 答:
select SN,SD from Student where S# in ( select S# from SC group by S# having count(distinct C#) > 5); )
3.建立一个学生表students,包括name,age,head_teacher,id,score(姓名,年龄,班主任,学号,成绩) Create table students ( Id number(9) not null primary key, Name varchar2(40) not null, Age int check(age between 0 and 100), Head_teacher vachar2(40), Score float );
4.对上表插入一条记录,姓名:张三,年龄:18,班主任:李四,学号:22 Insert into student(id,name,age,head_teacher) values(‘22’,’张三’,’18’,’李四’);
5.对上表中的age+name创建一个索引,并说明它的作用和使用方法 Create index student_index on students(age,name);
A(id ,name,regdate) B(id,groupid) C(id,name2) 写出下面的SQL语句
A)统计A表中每个月注册用户数 select count(*),to_char(regdate,‘yyyymm‘) from A group by to_char(regdate,‘yyyymm‘);
B)统计A表中有姓名相同的用户数 select count(*) from (select name from A group by name having count(*) >1);
C)如果表A中有姓名相同的用户,把相同的查出,写入表C中 nsert into C(name2) select name from A group by name having count(*) >1;
D)A中ID有多个相同的数据,A中姓名相同的ID只保留注册时间最大的数据 delete from E where e.regdate < (select max(regdate) from a X where E.id = X.id)
获取系统当前时间
select to_char(sysdate, ‘yyyy-MM-dd HH24:mi:ss‘) from dual;
分页查询
select *
from (
select t.*, rownum rn
from (
select p.xm_id,p.is_std,p.param_id,p.param_name,p.beizhu,p.std_jg,p.condition_id,
p.condition,p.num_type,p.department,p.customer_id,x.custom_xm_name,p.unit,p.measure_unit
from
jc_cw_price_fssd
p,jc_xtcs_xm x
<where>
p.customer_id = #{customer_id} and p.customer_id = x.customer_id
and p.plan_id = #{plan_id}
<if test="custom_xm_name != null and custom_xm_name != ‘‘ ">
and x.custom_xm_name like ‘%‘||#{custom_xm_name}||‘%‘
</if>
<if test="param_name != null and param_name != ‘‘">
and p.param_name like ‘%‘||#{param_name}||‘%‘
</if>
<if test="array != null">
and p.xm_id in
<foreach collection="array" item="xm_id" open="(" separator="," close=")">
#{xm_id}
</foreach>
</if>
and p.xm_id = x.xm_id
</where>
<if test="param_name_order == null and param_name_order == ‘‘">
order by x.custom_xm_name,p.param_name,p.condition_id asc
</if>
<if test="param_name_order != null and param_name_order != ‘‘">
order by x.custom_xm_name,${param_name_order},p.condition_id asc
</if>
) t where rownum <=#{end}
)where rn >=#{start}
原文地址:https://www.cnblogs.com/lianghaode/p/9102442.html