new sql qianyi

-- 1未使用 == 3已激活未使用

-- 1发放 == 1人工补发

SELECT

info.coupon_batch_id AS '优惠券批次Id',

CONCAT("'",info.coupon_batch_sn) AS '优惠券批次号',

CONCAT("'",info.coupon_sn)  AS '编号',

CONCAT("'",ecp.outer_user_id)  as '国美在线用户ID',

3 AS '使用状态',

(batch.limit_money * 100) AS '满多少元使用',

1 AS '发放方式',

info.effect_time AS '优惠券的生效时间',

info.expire_time AS '优惠券的过期时间',

info.create_time AS '发放时间',

info.effect_time AS '激活时间',

info.update_time AS '使用时间',

DATEDIFF(info.expire_time,info.effect_time) AS '有效天数',

1 AS '生效类型',

NULL AS '是否为自动退款优惠券',

NULL AS '退款时间',

info.user_id AS '用户ID(原来美信的用户ID)',

usa.order_id  as '订单号',

usa.create_time as '使用时间'

FROM

sp_coupon_info info

LEFT JOIN sp_coupon_batch batch

on info.coupon_batch_sn=batch.coupon_batch_sn

left join ecp_users ecp

on info.user_id=ecp.id

left join  sp_coupon_usages usa

on  usa.coupon_batch_sn=batch.coupon_batch_sn

WHERE

batch.shop_id=475

AND info.`status` = 1

AND batch.batch_type = 1

AND info.receive_type = 1

ORDER BY info.id desc

-- 2已使用 == 4已使用未关闭

-- 1发放 == 1人工补发

SELECT

info.coupon_batch_id AS '优惠券批次Id',

CONCAT("'",info.coupon_batch_sn) AS '优惠券批次号',

CONCAT("'",info.coupon_sn)  AS '编号',

CONCAT("'",ecp.outer_user_id)  as '国美在线用户ID',

4 AS '使用状态',

(batch.limit_money * 100) AS '满多少元使用',

1 AS '发放方式',

info.effect_time AS '优惠券的生效时间',

info.expire_time AS '优惠券的过期时间',

info.create_time AS '发放时间',

info.effect_time AS '激活时间',

info.update_time AS '使用时间',

DATEDIFF(info.expire_time,info.effect_time) AS '有效天数',

1 AS '生效类型',

NULL AS '是否为自动退款优惠券',

NULL AS '退款时间',

info.user_id AS '用户ID(原来美信的用户ID)',

usa.order_id  as '订单号',

usa.create_time as '使用时间'

FROM

sp_coupon_info info

LEFT JOIN sp_coupon_batch batch

on info.coupon_batch_sn=batch.coupon_batch_sn

left join ecp_users ecp

on info.user_id=ecp.id

left join  sp_coupon_usages usa

on  usa.coupon_batch_sn=batch.coupon_batch_sn

WHERE

batch.shop_id=475

AND info.`status` = 2

AND batch.batch_type = 1

AND info.receive_type = 1

ORDER BY info.id desc

-- 4已过期 == 6已过期作废

-- 1发放 == 1人工补发

SELECT

info.coupon_batch_id AS '优惠券批次Id',

CONCAT("'",info.coupon_batch_sn) AS '优惠券批次号',

CONCAT("'",info.coupon_sn)  AS '编号',

CONCAT("'",ecp.outer_user_id)  as '国美在线用户ID',

6 AS '使用状态',

(batch.limit_money * 100) AS '满多少元使用',

1 AS '发放方式',

info.effect_time AS '优惠券的生效时间',

info.expire_time AS '优惠券的过期时间',

info.create_time AS '发放时间',

info.effect_time AS '激活时间',

info.update_time AS '使用时间',

DATEDIFF(info.expire_time,info.effect_time) AS '有效天数',

1 AS '生效类型',

NULL AS '是否为自动退款优惠券',

NULL AS '退款时间',

info.user_id AS '用户ID(原来美信的用户ID)',

usa.order_id  as '订单号',

usa.create_time as '使用时间'

FROM

sp_coupon_info info

LEFT JOIN sp_coupon_batch batch

on info.coupon_batch_sn=batch.coupon_batch_sn

left join ecp_users ecp

on info.user_id=ecp.id

left join  sp_coupon_usages usa

on  usa.coupon_batch_sn=batch.coupon_batch_sn

WHERE

batch.shop_id=475

AND info.`status` = 4

AND batch.batch_type = 1

AND info.receive_type = 1

ORDER BY info.id desc

-- 1未使用 == 3已激活未使用

-- 2领取 == 7用户激活

SELECT

info.coupon_batch_id AS '优惠券批次Id',

CONCAT("'",info.coupon_batch_sn) AS '优惠券批次号',

CONCAT("'",info.coupon_sn)  AS '编号',

CONCAT("'",ecp.outer_user_id)  as '国美在线用户ID',

3 AS '使用状态',

(batch.limit_money * 100) AS '满多少元使用',

7 AS '发放方式',

info.effect_time AS '优惠券的生效时间',

info.expire_time AS '优惠券的过期时间',

info.create_time AS '发放时间',

info.effect_time AS '激活时间',

info.update_time AS '使用时间',

DATEDIFF(info.expire_time,info.effect_time) AS '有效天数',

1 AS '生效类型',

NULL AS '是否为自动退款优惠券',

NULL AS '退款时间',

info.user_id AS '用户ID(原来美信的用户ID)',

usa.order_id  as  '订单号',

usa.create_time as '使用时间'

FROM

sp_coupon_info info

LEFT JOIN sp_coupon_batch batch

on info.coupon_batch_sn=batch.coupon_batch_sn

left join ecp_users ecp

on info.user_id=ecp.id

left join  sp_coupon_usages usa

on  usa.coupon_batch_sn=batch.coupon_batch_sn

WHERE

batch.shop_id=475

AND info.`status` = 1

AND batch.batch_type = 1

AND info.receive_type = 2

ORDER BY info.id desc

-- 2已使用 == 4已使用未关闭

-- 2领取 == 7用户激活

SELECT

info.coupon_batch_id AS '优惠券批次Id',

CONCAT("'",info.coupon_batch_sn) AS '优惠券批次号',

CONCAT("'",info.coupon_sn)  AS '编号',

CONCAT("'",ecp.outer_user_id)  as '国美在线用户ID',

4 AS '使用状态',

(batch.limit_money * 100) AS '满多少元使用',

7 AS '发放方式',

info.effect_time AS '优惠券的生效时间',

info.expire_time AS '优惠券的过期时间',

info.create_time AS '发放时间',

info.effect_time AS '激活时间',

info.update_time AS '使用时间',

DATEDIFF(info.expire_time,info.effect_time) AS '有效天数',

1 AS '生效类型',

NULL AS '是否为自动退款优惠券',

NULL AS '退款时间',

info.user_id AS '用户ID(原来美信的用户ID)',

usa.order_id  as '订单号',

usa.create_time as '使用时间'

FROM

sp_coupon_info info

LEFT JOIN sp_coupon_batch batch

on info.coupon_batch_sn=batch.coupon_batch_sn

left join ecp_users ecp

on info.user_id=ecp.id

left join  sp_coupon_usages usa

on  usa.coupon_batch_sn=batch.coupon_batch_sn

WHERE

batch.shop_id=475

AND info.`status` = 2

AND batch.batch_type = 1

AND info.receive_type = 2

ORDER BY info.id desc

-- 4已过期 == 6已过期作废

-- 2领取 == 7用户激活

SELECT

info.coupon_batch_id AS '优惠券批次Id',

CONCAT("'",info.coupon_batch_sn) AS '优惠券批次号',

CONCAT("'",info.coupon_sn)  AS '编号',

CONCAT("'",ecp.outer_user_id)  as '国美在线用户ID',

6 AS '使用状态',

(batch.limit_money * 100) AS '满多少元使用',

7 AS '发放方式',

info.effect_time AS '优惠券的生效时间',

info.expire_time AS '优惠券的过期时间',

info.create_time AS '发放时间',

info.effect_time AS '激活时间',

info.update_time AS '使用时间',

DATEDIFF(info.expire_time,info.effect_time) AS '有效天数',

1 AS '生效类型',

NULL AS '是否为自动退款优惠券',

NULL AS '退款时间',

info.user_id AS '用户ID(原来美信的用户ID)',

usa.order_id  as '订单号',

usa.create_time as '使用时间'

FROM

sp_coupon_info info

LEFT JOIN sp_coupon_batch batch

on info.coupon_batch_sn=batch.coupon_batch_sn

left join ecp_users ecp

on info.user_id=ecp.id

left join  sp_coupon_usages usa

on  usa.coupon_batch_sn=batch.coupon_batch_sn

WHERE

batch.shop_id=475

AND info.`status` = 4

AND batch.batch_type = 1

AND info.receive_type = 2

ORDER BY info.id desc ;

--批次表    平台店铺编码要改

SELECT

CONCAT("'",b.coupon_batch_sn) AS '批次编号',

b.batch_name AS '批次名称',

0 AS '批次锁定状态',

0 AS '优惠券类型',

1 AS '生效类型',

b.discount AS '面值',

b.limit_money AS '满多少元可用',

b.start_time AS '有效期开始时间',

b.end_time AS '有效期结束时间',

DATEDIFF(b.end_time,b.start_time) AS '有效天数',

b.all_quantity AS '优惠券数量',

b.shop_id AS '店铺编码',

81012772 AS '对应的平台店铺编码',

s.nickname AS '创建人(店铺管理员账号)',

CONCAT("'",s.outer_user_id) AS '对应的国美在线账号',

b.create_time AS '创建时间',

b.shop_name AS '店铺名称'

FROM

sp_coupon_batch b,ecp_users s, xpop_shop p

WHERE

b.shop_id = 475

and b.creator_id=s.id

and b.shop_id = p.shop_no

order by b.id desc;

-- 店铺券限领

SELECT

concat("'",h.coupon_batch_sn),

h.limit_receive,

h.creator_id,

concat("'",s.outer_user_id),

h.create_time,

h.shop_id,

p.platform_shop_code

FROM

sp_coupon_batch h,ecp_users s, xpop_shop p

WHERe

h.shop_id = 475

and h.creator_id=s.id

and h.shop_id = p.shop_no

order by h.id desc;

你可能感兴趣的:(new sql qianyi)