SELECT
t1.*,
t1.goods_name AS goodsName,
ifnull(t2.share_amount,0) AS shareAmount,
ifnull(t2.share_percent,0) AS sharePercent,
ifnull(t2.inner_share_amount,0) AS innerShareAmount,
ifnull(t2.inner_share_percent,0) AS innerSharePercent,
sum(if(t2.del=0 and t2.stock_num is NOT NULL,t2.stock_num,0)) AS stockNum,
t3.`name` AS categoryName,
t2.bar_code
FROM
goods t1
join goods_company t4 on t1.goods_id = t4.goods_id
left join goods_spec t2 on t1.goods_id = t2.goods_id and t2.del = 0
left join goods_category t3 on t3.category_id = t1.category_id
WHERE
t1.del = 0
AND t4.company_id in
#{item}
AND t1.goods_type in
#{item}
AND t1.status = 1
AND t1.status = 0
AND t2.flag = 1
AND
(t1.goods_id like CONCAT('%', #{keyword},'%') OR t1.goods_name like CONCAT('%',#{keyword},'%') OR t3.`name`
like CONCAT('%',#{keyword},'%') OR CONCAT(t1.goods_name, '(', t2.`name`,')') like
CONCAT('%',#{keyword},'%'))
AND
t2.price BETWEEN #{startPrice} AND #{endPrice}
AND
t2.share_amount BETWEEN #{startShare} AND #{endShare}
AND
t3.category_id in
#{item}
AND
t1.status = #{status}
group by t1.goods_id
having sum(t2.stock_num) = 0
ORDER BY t1.sort_num desc,t1.create_time desc
ORDER BY t1.sort_num desc,${sortStr},t1.create_time desc
SELECT t1.*,
t1.goods_name AS goodsName,
ifnull(t2.share_amount, 0) AS shareAmount,
ifnull(t2.share_percent, 0) AS sharePercent,
sum(IF(t2.del = 0 AND t2.sold_num IS NOT NULL, t2.sold_num, 0)) AS soldNum,
sum(IF(t2.del = 0 AND t2.stock_num IS NOT NULL, t2.stock_num, 0)) AS stockNum
FROM goods_template gt
LEFT JOIN goods t1 ON gt.goods_id = t1.goods_id
LEFT JOIN goods_spec t2 ON t1.goods_id = t2.goods_id
WHERE gt.template_id = #{commonTemplateId}
and t1.del = 0
GROUP BY t1.goods_id
ORDER BY t1.sort_num DESC
select count(1) 'total', sum(if(status = true, 1, 0)) 'csz', sum(if(status = false, 1, 0)) 'ckz'
from goods a join goods_company b on a.goods_id = b.goods_id
where del = false
AND b.company_id in
#{companyWechatId}
group by a.goods_id
SELECT
count(*) total
FROM
(
SELECT
sum( c.stock_num ),
c.goods_id
FROM
goods_spec c
JOIN goods t1
JOIN goods_company b ON t1.goods_id = b.goods_id
WHERE
c.del = FALSE
AND b.company_id in
#{companyWechatId}
GROUP BY
goods_id
HAVING
sum( stock_num ) = 0
) t
select count(DISTINCT t1.goods_id)
FROM goods t1 join goods_company b on t1.goods_id = b.goods_id
left join goods_spec t2 on t1.goods_id = t2.goods_id
WHERE t1.del = 0
AND t2.flag = 1
and t2.del = 0
AND b.company_id in
#{companyWechatId}
select a.* from goods_category a
join goods b on a.category_id = b.category_id
where b.goods_id=#{goodsId}
update goods_spec
set inner_share_amount = share_amount , inner_share_percent = share_percent
where inner_share_amount is null and inner_share_amount is null and company_id = #{companyWechatId}
select
a.goods_id,
a.img_url,
a.goods_name,
a.status,
(select count(DISTINCT goods_id) from goods_package_pop where goods_package_id= a.goods_id) 'goodsNums',
a.package_min_amount,
a.package_min_share_amount,
use_coupon,
count(DISTINCT c.order_id) 'orderNums',
sum(c.pay_amount) 'orderPayAmount',
a.package_user_type,
a.company_name
from goods a
left join order_info c on c.promotion_package_goods_id=a.goods_id and c.order_status in ('DFH','YFH','OVER')
where a.goods_type='PACKAGE'
and a.del = 0
AND a.company_id in
#{companyWechatId}
AND(a.goods_id like CONCAT('%', #{keyword},'%') OR a.goods_name like CONCAT('%',#{keyword},'%'))
AND
a.package_min_amount BETWEEN #{startPrice} AND #{endPrice}
AND
a.package_min_share_amount BETWEEN #{startShare} AND #{endShare}
AND
a.category_id in
#{item}
AND
a.status = #{status}
group by a.goods_id
ORDER BY a.sort_num desc,a.create_time desc
ORDER BY a.sort_num desc,${sortStr},a.create_time desc
SELECT
${ex.selected}
FROM goods a
${ex.query}
ORDER BY a.create_time DESC
${ex.orderBy}