Table:Product: ┌───┬─────┐ │ ID │Name │ ├───┼─────┤ │ 1 │Product1 │ ├───┼─────┤ │ 2 │Product2 │ ├───┼─────┤ │ 3 │Product3 │ ├───┼─────┤ │ 4 │Product4 │ ├───┼─────┤ │ 5 │Product5 │ └───┴─────┘ Demand: write out the SQL sentence which will run as the form below without changing of the original table and data ┌───┬────┬───┬───┬───┐ │ ID │Name │ In │ Out │ Save │ ├───┼────┼───┼───┼───┤ │ 1 │Product1│ 100 │ 8 │ 92 │ ├───┼────┼───┼───┼───┤ │ 2 │Product2│ 74 │ 11 │ 63 │ ├───┼────┼───┼───┼───┤ │ 3 │Product3│ 65 │ 3 │ 62 │ ├───┼────┼───┼───┼───┤ │ 4 │Product4│ 10 │ 0 │ 10 │ ├───┼────┼───┼───┼───┤ │ 5 │Product5│ 0 │ 0 │ 0 │ └───┴────┴───┴───┴───┘ 以上是我以前去家公司 那公司给的数据库的笔试题... LZ 有空可以做的试试 .. 只有30分钟 我当时没有做出来..
关注下,应该是会考一些数据库设计相关知识,不同数据库的差别,jdbc的相关知识
范式(第一,二,三,BC范式),无损连接,依赖 约束(primary key, default, check, not null, 外键) 视图在DB中有什么作用 查询(句法结构,左,右,内连接,子查询, order by, group by having,集函数) 如何对查询优化(例如,上百万条记录,进行分页处理) 有时还问问存储过程,触发器(例如函数和存储过程的区别?)
请问save这个字段是怎么来的?
如果是oracle,这样做: select p.pro_id,sum(decode(il.inout,'in',il.num,'out',0,null,0)) cin, sum(decode(il.inout,'out',il.num,'in',0,null,0)) cout, sum(decode(il.inout,'in',il.num,'out',il.num*(-1),null,0)) csave from product p left join InOutList il on p.pro_id=il.productid group by p.pro_id测试通过。
http://topic.csdn.net/u/20090302/13/1F448418-A3E3-41A9-9788-BE03872471BB.html
┌───┬─────────┬─────┬───┬───┐
│AutoID│RecordTime │ProductID │InOut │ Num │
├───┼─────────┼─────┼───┼───┤
│ 1 │2007-12-3 11:39:25│ 1 │ out │ 3 │
├───┼─────────┼─────┼───┼───┤
│ 2 │2007-12-4 10:39:25│ 2 │ out │ 2 │
├───┼─────────┼─────┼───┼───┤
│ 3 │2007-12-5 11:39:25│ 1 │ out │ 5 │
├───┼─────────┼─────┼───┼───┤
│ 4 │2007-12-5 11:39:26│ 2 │ out │ 9 │
├───┼─────────┼─────┼───┼───┤
│ 5 │2007-12-5 11:39:27│ 3 │ out │ 3 │
├───┼─────────┼─────┼───┼───┤
│ 6 │2007-12-5 09:39:25│ 2 │ in │ 10 │
├───┼─────────┼─────┼───┼───┤
│ 7 │2007-12-5 13:39:56│ 3 │ in │ 5 │
├───┼─────────┼─────┼───┼───┤
│ 8 │2007-12-6 09:39:30│ 2 │ in │ 6 │
├───┼─────────┼─────┼───┼───┤
│ 9 │2007-12-6 09:39:31│ 2 │ in │ 8 │
├───┼─────────┼─────┼───┼───┤
│ 10 │2007-12-6 09:39:32│ 1 │ in │ 100 │
├───┼─────────┼─────┼───┼───┤
│ 11 │2007-12-6 09:39:33│ 2 │ in │ 50 │
├───┼─────────┼─────┼───┼───┤
│ 12 │2007-12-6 09:39:34│ 3 │ in │ 60 │
├───┼─────────┼─────┼───┼───┤
│ 13 │2007-12-6 09:39:35│ 4 │ in │ 10 │
└───┴─────────┴─────┴───┴───┘
Table:Product:
┌───┬─────┐
│ ID │Name │
├───┼─────┤
│ 1 │Product1 │
├───┼─────┤
│ 2 │Product2 │
├───┼─────┤
│ 3 │Product3 │
├───┼─────┤
│ 4 │Product4 │
├───┼─────┤
│ 5 │Product5 │
└───┴─────┘ Demand: write out the SQL sentence which will run as the form below without changing of the original table and data
┌───┬────┬───┬───┬───┐
│ ID │Name │ In │ Out │ Save │
├───┼────┼───┼───┼───┤
│ 1 │Product1│ 100 │ 8 │ 92 │
├───┼────┼───┼───┼───┤
│ 2 │Product2│ 74 │ 11 │ 63 │
├───┼────┼───┼───┼───┤
│ 3 │Product3│ 65 │ 3 │ 62 │
├───┼────┼───┼───┼───┤
│ 4 │Product4│ 10 │ 0 │ 10 │
├───┼────┼───┼───┼───┤
│ 5 │Product5│ 0 │ 0 │ 0 │
└───┴────┴───┴───┴───┘ 以上是我以前去家公司 那公司给的数据库的笔试题... LZ 有空可以做的试试 .. 只有30分钟 我当时没有做出来..
约束(primary key, default, check, not null, 外键)
视图在DB中有什么作用
查询(句法结构,左,右,内连接,子查询, order by, group by having,集函数)
如何对查询优化(例如,上百万条记录,进行分页处理)
有时还问问存储过程,触发器(例如函数和存储过程的区别?)
select p.pro_id,sum(decode(il.inout,'in',il.num,'out',0,null,0)) cin,
sum(decode(il.inout,'out',il.num,'in',0,null,0)) cout,
sum(decode(il.inout,'in',il.num,'out',il.num*(-1),null,0)) csave
from product p
left join InOutList il on p.pro_id=il.productid
group by p.pro_id测试通过。