一些稍微复杂点的sql语句

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了一些稍微复杂点的sql语句相关的知识,希望对你有一定的参考价值。

UPDATE test SET 
 content = REPLACE(content,‘国家级‘,‘‘),content = REPLACE(content,‘世界级‘,‘‘),content = REPLACE(content,‘最高级‘,‘‘)
,content = REPLACE(content,‘最佳‘,‘‘),content = REPLACE(content,‘首个‘,‘‘),content = REPLACE(content,‘首选‘,‘‘)
,content = REPLACE(content,‘唯一‘,‘‘),content = REPLACE(content,‘世界级‘,‘‘),content = REPLACE(content,‘世界级‘,‘‘)
,content = REPLACE(content,‘最好‘,‘‘),content = REPLACE(content,‘最大‘,‘‘),content = REPLACE(content,‘精确‘,‘‘)
,content = REPLACE(content,‘顶级‘,‘‘),content = REPLACE(content,‘最高‘,‘‘),content = REPLACE(content,‘最低‘,‘‘)
,content = REPLACE(content,‘最‘,‘‘),content = REPLACE(content,‘最具‘,‘‘),content = REPLACE(content,‘最便宜‘,‘‘)
,content = REPLACE(content,‘最新‘,‘‘),content = REPLACE(content,‘最先进‘,‘‘),content = REPLACE(content,‘最大程度‘,‘‘)
,content = REPLACE(content,‘最新技术‘,‘‘),content = REPLACE(content,‘最先进科学‘,‘‘),content = REPLACE(content,‘国家级产品‘,‘‘)
,content = REPLACE(content,‘填补国内空白‘,‘‘),content = REPLACE(content,‘绝对‘,‘‘),content = REPLACE(content,‘独家‘,‘‘)
,content = REPLACE(content,‘首家‘,‘‘),content = REPLACE(content,‘最先进‘,‘‘),content = REPLACE(content,‘万能‘,‘‘)
,content = REPLACE(content,‘第一品牌‘,‘‘),content = REPLACE(content,‘金牌‘,‘‘),content = REPLACE(content,‘名牌‘,‘‘)
,content = REPLACE(content,‘优秀‘,‘‘),content = REPLACE(content,‘最先‘,‘‘),content = REPLACE(content,‘顶级‘,‘‘)
,content = REPLACE(content,‘独家‘,‘‘),content = REPLACE(content,‘全网销量第一‘,‘‘),content = REPLACE(content,‘全球首发‘,‘‘)
,content = REPLACE(content,‘全国首家‘,‘‘),content = REPLACE(content,‘全网首发‘,‘‘),content = REPLACE(content,‘世界领先‘,‘‘)
,content = REPLACE(content,‘顶级工艺‘,‘‘),content = REPLACE(content,‘最新科学‘,‘‘),content = REPLACE(content,‘最新技术‘,‘‘)
,content = REPLACE(content,‘最先进加工工艺‘,‘‘),content = REPLACE(content,‘最时尚‘,‘‘),content = REPLACE(content,‘极品‘,‘‘)
,content = REPLACE(content,‘顶级‘,‘‘),content = REPLACE(content,‘顶尖‘,‘‘),content = REPLACE(content,‘终极‘,‘‘)
,content = REPLACE(content,‘王牌‘,‘‘),content = REPLACE(content,‘销量冠军‘,‘‘),content = REPLACE(content,‘最受欢迎‘,‘‘)
,content = REPLACE(content,‘NO.1‘,‘‘),content = REPLACE(content,‘Top1‘,‘‘),content = REPLACE(content,‘极致‘,‘‘)
,content = REPLACE(content,‘永久‘,‘‘),content = REPLACE(content,‘王牌‘,‘‘),content = REPLACE(content,‘掌门人‘,‘‘)
,content = REPLACE(content,‘领袖品牌‘,‘‘),content = REPLACE(content,‘独一无二‘,‘‘),content = REPLACE(content,‘独家‘,‘‘)
,content = REPLACE(content,‘绝无仅有‘,‘‘),content = REPLACE(content,‘前无古人‘,‘‘),content = REPLACE(content,‘史无前例‘,‘‘)
,content = REPLACE(content,‘第一‘,‘‘)
WHERE id = 2;
UPDATE shopnc_goods_common SET goods_body = 

INSERT(goods_body, INSTR(goods_body,‘<div class="p_titles_2">商品特色</div>‘), INSTR(goods_body,‘<div class="p_titles_2">商品参数</div>‘)- INSTR(goods_body,‘<div class="p_titles_2">商品特色</div>‘),‘‘)

WHERE gc_id_2 in (294,284,289,261,216) and goods_body LIKE ‘%商品特色%‘
SELECT shopnc_cps.order_sn as 订单号,shopnc_orders.buyer_name as 用户名,FROM_UNIXTIME(shopnc_orders.add_time,‘%Y-%m-%d %H:%i:%S‘) as 下单时间,
shopnc_order_goods.goods_name as 商品名称,shopnc_orders.store_name as 店铺名,shopnc_orders.CustomerNo as 用户编号,
CASE
WHEN shopnc_orders.order_state = ‘0‘ THEN ‘以取消‘
WHEN shopnc_orders.order_state = ‘10‘ THEN ‘未付款‘
WHEN shopnc_orders.order_state = ‘20‘ THEN ‘以付款‘
WHEN shopnc_orders.order_state = ‘30‘ THEN ‘以发货‘
WHEN shopnc_orders.order_state = ‘40‘ THEN ‘以收货‘
END AS  订单状态,

CASE
WHEN shopnc_goods.gc_id_1 = ‘1‘ THEN ‘汽车精品‘
WHEN shopnc_goods.gc_id_1 = ‘15‘ THEN ‘服装鞋帽‘
WHEN shopnc_goods.gc_id_1 = ‘53‘ THEN ‘箱包配饰‘
WHEN shopnc_goods.gc_id_1 = ‘77‘ THEN ‘数码家电‘
WHEN shopnc_goods.gc_id_1 = ‘124‘ THEN ‘个护彩妆‘
WHEN shopnc_goods.gc_id_1 = ‘159‘ THEN ‘家居日用‘
WHEN shopnc_goods.gc_id_1 = ‘215‘ THEN ‘珠宝收藏‘
WHEN shopnc_goods.gc_id_1 = ‘264‘ THEN ‘食品保健‘
WHEN shopnc_goods.gc_id_1 = ‘302‘ THEN ‘旅游度假‘
WHEN shopnc_goods.gc_id_1 = ‘313‘ THEN ‘母婴玩具‘
WHEN shopnc_goods.gc_id_1 = ‘319‘ THEN ‘燕京八绝‘
WHEN shopnc_goods.gc_id_1 = ‘354‘ THEN ‘手机充值‘
WHEN shopnc_goods.gc_id_1 = ‘355‘ THEN ‘其他分类‘
END as 商品分类,

CASE
WHEN shopnc_orders.payment_code = ‘offline‘ THEN ‘货到付款‘
WHEN shopnc_orders.payment_code = ‘online‘ THEN ‘在线支付‘
WHEN shopnc_orders.payment_code = ‘wxpay‘ THEN ‘微信支付‘
WHEN shopnc_orders.payment_code = ‘alipay‘ THEN ‘支付宝‘
WHEN shopnc_orders.payment_code = ‘unionpay‘ THEN ‘银联‘
WHEN shopnc_orders.payment_code = ‘pingan‘ THEN ‘平安银行‘
ELSE ‘不知道什么支付方式‘
END
as 支付方式,shopnc_order_goods.goods_id as 商品ID,shopnc_order_goods.goods_price as 商品价格,shopnc_order_goods.goods_pay_price as 订单支付价格,
shopnc_order_goods.goods_num as 商品数量,shopnc_order_goods.unit_code as 德珍商品编号,shopnc_order_goods.goods_usevipdiscount as 会员折扣,shopnc_order_goods.goods_usediscount as 代金券,
shopnc_order_goods.goods_useuserpoint as 使用购物金,shopnc_order_goods.goods_freight as 运费,shopnc_order_goods.living_goods_discount as 正在直播商品优惠,shopnc_order_goods.yihe_cuxiao as 移动端货到付款优惠,
shopnc_order_goods.gc_id as 商品分类 ,
CASE
WHEN shopnc_goods.gc_id_1 IN (15,53,124,159,264) AND shopnc_goods.goods_promotion_type =0 THEN ‘5%‘
WHEN shopnc_goods.gc_id_1 IN (15,53,124,159,264) AND shopnc_goods.goods_promotion_type != 0 THEN ‘3%‘
WHEN shopnc_goods.gc_id_1 IN (215,302) THEN ‘3%‘
WHEN shopnc_goods.gc_id_1 = ‘77‘ AND shopnc_goods.gc_id_2 != ‘110‘ THEN ‘3%‘
ELSE ‘0%‘
END as 佣金比例 ,

(CASE
WHEN shopnc_goods.gc_id_1 IN (15,53,124,159,264) AND shopnc_goods.goods_promotion_type =0 THEN 0.05
WHEN shopnc_goods.gc_id_1 IN (15,53,124,159,264) AND shopnc_goods.goods_promotion_type != 0 THEN 0.03
WHEN shopnc_goods.gc_id_1 IN (215,302) THEN 0.03
WHEN shopnc_goods.gc_id_1 = ‘77‘ AND shopnc_goods.gc_id_2 != ‘110‘ THEN 0.03
ELSE 0
END)*(shopnc_order_goods.goods_pay_price - 21) AS 佣金金额,‘16‘ AS 包装费 ,‘5‘ AS 邮费  ,
 shopnc_order_goods.rcb as 使用充值卡金额,shopnc_order_goods.pd as 使用预付款金额,

CASE
WHEN shopnc_cps.c_id = ‘17574‘ THEN ‘汽车精品‘
WHEN shopnc_cps.c_id = ‘18000‘ THEN ‘领克特‘
WHEN shopnc_cps.c_id = ‘19000‘ THEN ‘唯一传媒‘
END as cps来源,
 
CASE
WHEN shopnc_orders.client = ‘1‘ THEN ‘网站‘
WHEN shopnc_orders.client = ‘2‘ THEN ‘wap‘
WHEN shopnc_orders.client = ‘3‘ THEN ‘微信‘
END as 订单来源 ,
shopnc_order_push.order_push_sn as 德珍订单号

FROM shopnc_cps LEFT JOIN shopnc_orders ON shopnc_cps.order_sn = shopnc_orders.order_sn LEFT JOIN shopnc_order_goods ON shopnc_orders.order_id = shopnc_order_goods.order_id  LEFT JOIN
 shopnc_goods ON shopnc_order_goods.goods_id =shopnc_goods.goods_id  LEFT JOIN shopnc_order_push ON shopnc_orders.order_sn = shopnc_order_push.order_sn
 WHERE shopnc_orders.add_time >= ‘1435680000‘ and   shopnc_orders.add_time <= ‘1438358400‘ 

最后一个有点复杂

以上是关于一些稍微复杂点的sql语句的主要内容,如果未能解决你的问题,请参考以下文章

SQL编程第三章 复杂一点的查询

Sql Server——查询

解析稍微复杂一点的数据

求 存储过程和Sql语句之间的区别 余额准确越好

使用 with as 优化SQL

一个稍微有趣点的crackme