1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
| create or replace view v_emp as select * from emp insert into v_emp values(1111,'HWZ','CLERK',null,trunc(sysdate),888,null,40) delete from emp where empno=1111
create or replace view v_emp_avgsal as select deptno,avg(sal) 平均工资 from emp group by deptno select * from v_emp_avgsal update v_emp_avgsal set 平均工资=round(平均工资)
create or replace view v_avg as select sno,avg(score) 平均成绩 from sc group by sno order by sno with read only update v_avg set 平均成绩=round(平均成绩)
create sequence seq_emp start with 1 increment by 1
select seq_emp.nextval from dual select seq_emp.currval from dual insert into emp values(seq_emp.currval,'hwz','CLERK',1111,trunc(sysdate),888,null,40) select *from emp
alter sequence seq_emp increment by 10 select seq_emp.nextval from dual insert into emp values(seq_emp.currval,'hwz2','CLERK',1111,trunc(sysdate),666,null,40)
create table t_dic( type varchar2(10), name varchar2(20), key varchar2(10) unique, value varchar2(20) not null );
select * from t_dic for update
create table goods( id varchar2(32) primary key, type varchar2(10) references t_dic(key), name varchar2(100), inprice number(10,2), outprice number(10,2), tjdw varchar2(10) references t_dic(key), qualitydate number(4) check(qualitydate>0) );
select * from goods for update
create table stock( id varchar2(32) primary key, goodsid varchar2(32) references goods(id), sl number(4), intime date default sysdate, productime date );
create table income( id varchar2(32) primary key, goodsid varchar2(32) references goods(id), stockid varchar2(32) references stock(id), sl number(4) check(sl>0), discount number(4,1), allprice number(8,1), outtime date default sysdate );
create table outcome( id varchar2(32) primary key, goodsid varchar2(32) references goods(id), stockid varchar2(32) references stock(id), sl number(4,1) check(sl>0), allprice number(8,1), intime date default sysdate ); drop table outcome
select * from t_dic select * from goods select * from stock select * from income select * from outcome
create index idx_stock_goodsid on stock(goodsid)
alter table goods add constraint wyys unique(name)
insert into stock(id,goodsid,sl,intime,productime) select g.id id, g.id goodsid, floor(dbms_random.value(100, 300)) sl, trunc(sysdate) - 30 intime, trunc(sysdate - dbms_random.value(30,90)) productime from goods g order by g.id
delete from stock
select * from goods g join stock s on s.id=g.id where productime+qualitydate<sysdate
select * from goods g join stock s on s.id=g.id where productime+qualitydate+10<sysdate
create sequence seq_stock start with 12 increment by 1
drop sequence seq_stock select seq_stock.nextval from dual select seq_stock.currval from dual
create sequence seq_outcome start with 1 increment by 1
drop sequence seq_outcome select seq_outcome.nextval from dual select seq_outcome.currval from dual
insert into stock select seq_stock.nextval,id,50,trunc(sysdate),trunc(sysdate)-20 from goods where id in (select id from goods where name = '脉动' or name='可口可乐')
insert into outcome select seq_outcome.nextval,id,seq_outcome.nextval,50,inprice*50,trunc(sysdate) from goods where id in (select id from goods where name = '脉动' or name='可口可乐')
delete from outcome
select * from income
create sequence seq_intcome start with 1 increment by 1
drop sequence seq_income select seq_income.nextval from dual select seq_income.currval from dual
insert into income(id, goodsid, stockid, sl, discount, allprice, outtime) values( seq_income.nextval, (select id from goods where name = '泰山'), (select s.id from stock s join goods g on s.goodsid = g.id where g.name = '泰山'), 1, 1, (select outprice from goods where name = '泰山')*1, sysdate );
update stock set sl = sl - 1 where goodsid = (select id from goods where name = '泰山') and sl > 0;
select s.*, outprice*sl 总价, inprice*sl 进货价 from stock s join goods g on g.id=s.id
select * from ( select g.id, g.outprice * sum(s.sl) 总价 from stock s join goods g on s.goodsid = g.id where g.type = 'g02' group by g.id, g.outprice order by sum(s.sl) desc ) where rownum = 1;
select name from goods where outprice between 5 and 10
select name from goods where name like '%山%'
select * from outcome where intime = trunc(sysdate)
select name from( select name from goods order by length(name) desc ) where rownum = 1;
select case when g.type in('g01','g02') then (g.name) else '其他' end 名称, sum(s.sl) 库存 from stock s join goods g on g.id=s.goodsid group by case when g.type in('g01','g02') then (g.name) else '其他' end order by 库存
update goods set name='可比克薯片(袋装)' where name='可比克薯片'
select * from goods order by outprice desc
select sum(allprice) 销售额, sum(allprice-inprice*sl) 毛利润 from income i join goods g on g.id=i.goodsid
with 昨日销售 as ( select g.type as 类型代码,sum(i.sl) as 销售总量 from income i join goods g on i.goodsid = g.id where trunc(i.outtime) = trunc(sysdate) - 1 group by g.type ) select d.name 类型名称, y.销售总量 from 昨日销售 y join t_dic d on y.类型代码 = d.key where y.销售总量 = (select max(销售总量) from 昨日销售);
19. 查询出烟类,近10天的销售情况,展示出物品名称,卖出数量,总价格,毛利润 20. 根据天数分组,汇总近10天每天的销售情况,毛利润和总价格 21. 创建视图,展示当月销售物品中,分类统计各类物品的销售数量,总进价,总卖出价,毛利润 22. 在物品表里查出利润率最大的物品 23. 因为某人讲价,于当前时间,以8折卖出馒头50个,在进账表和库存表做出相应修改
|