sql remark

chomp
----------
primary key: unique and NOT NULL identifier to each record, special case of unique keys. So diff. with unique index:
(1) One is key, one is index;
(2) primary key NOT null.
----------
over: support function like count()rank()... func() over(), func() over(order by xxx), func() over(partition by xxx order by xxx)
order by: sequence to rank by
partition by: base on partition to build senquence, e.g. part_A:1,1,2,3...  part_B:1,2,2...
---------- rollup / cube 分组统计
GRADE     ID       NUM
------  ------   -------
  a       1         1
  a       2         2
  b       3         4
  b       4         4
select grade, ID, decode(grouping_id(grade,ID),1,'小计',3,'合计',ID) ID1, sum(num) from a group by rollup(grade,ID);
GRADE     ID      ID1     NUM
------  ------  ------  -------
  a       1       1        1
  a       2       2        2
  a      null    小计      3
  b       3       3        4
  b       4       4        4
  b      null    小计      8
 null    null    合计     11
rollup: {Col_1 subtotal}, {total}

select grade, ID, sum(num) from a group by cube(grade,ID);
GRADE     ID      NUM
------  ------  -------
  a       1        1
  a       2        2
  a      null      3
  b       3        4
  b       4        4
  b      null      8
 null     1        1
 null     2        2
 null     3        4
 null     4        4
 null    null     11
cube: {Col_1 subtotal}, {Col_2 subtotal}, {total}
-- http://download.oracle.com/docs/cd/B19306_01/server.102/b14223/aggreg.htm#i1007428

----------

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
--新建视图 v_desk create view v_desk as select a.*, b.usingType_code, b.sOrderNo from t_desk a left join t_using_desk b on a.id = b.desk_id go --新建台号时向 t_using_desk 插入记录 --台号显示的时候查 v_desk --去掉表 t_dish_orderedNumber --t_order有些字段改为float --t_order_temp增加 price float字段 --t_using_desk增加 sOrderNo nvarchar(20) 字段 --t_dishes 修改 ordered_number float ----------------------------- --发送过程:先选台号,若该台号处于正在使用状态(在表 t_using_desk 中 usingType_code = '02'), --则表明是加菜,从 t_using_desk 中获取该台号对应的 sOrderNo,传入存储过程 sp_orderDishes;(在 sp_orderDishes 中将有菜品的台号的 singType_code 置为‘02’,在结账时重新置为 ‘01’) --若该台号处于空闲状态(在表 t_using_desk 中 usingType_code = '01'),则表明该台号即将被使用,需生成 sOrderNo, 向 t_order 表中增加该订单的信息,然后执行存储过程 sp_orderDishes ------------------------- --创建存储过程 sp_orderDishes --1、将临时表 t_order_temp 中的数据插入到 t_order_dishes --2、将表 t_using_desk 中对应的 desk_id 的 usingType_code 置为 '02'(使用中) --3、更新 t_dishes 的 ordered_number --4、删除临时表 t_order_temp 中该 userId 对应的数据 --drop procedure sp_orderDishes create procedure sp_orderDishes @orderNo nvarchar(20), @userId uniqueidentifier, @deskId uniqueidentifier as begin transaction insert into t_order_dishes(sOrderNo, dish_id, price, order_num, subtotal, taste_id1, taste_id2, remark, waiter) select @orderNo, dish_id, price, order_num, price*order_num, taste_id1, taste_id2, remark, userId from t_order_temp where userId = @userId IF @@ROWCOUNT > 0 update t_using_desk set usingType_code = '02', sOrderNo = @orderNo where desk_id = @deskId if @@error 0 begin rollback transaction--发生错误则回滚事务,无条件退出l return end DECLARE @DishId uniqueidentifier declare @OrderNum float DECLARE My_Cursor CURSOR--定义游标 FOR (SELECT dish_id, order_num FROM t_order_temp where userId = @userId) --查出需要的集合放到游标中 OPEN My_Cursor; --打开游标 FETCH NEXT FROM My_Cursor INTO @DishId, @OrderNum; --读取第一行数据(将 t_order_temp 表中的 dish_id 放到 @DishId 变量中) WHILE @@FETCH_STATUS=0 BEGIN UPDATE t_dishes SET ordered_number = ordered_number + @OrderNum WH

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值