我的加入查询在这里,我想在MySql查询中销售价格原始价格之间多少%?
SELECT DISTINCT (CASE
WHEN b.method = 'checkmo' THEN 'Check / Money order'
ELSE 'Credit Card (saved)'
END) AS 'Payment Method',a.increment_id as 'Ref-Order Number',a.store_name as 'purchased From (Store)', a.created_at as 'Purchased On',CONCAT (customer_firstname,' ',customer_lastname) as 'Sender-Store Name',CONCAT (customer_firstname,' ',customer_lastname) as 'Attention',c.telephone as 'Phone',c.street as 'Shipping Street',c.city as 'Shipping City',c.region as 'Shipping State',c.postcode as 'Shipping Zip',d.Sku as 'SKU',name as 'Name', round(d.base_price,2) as 'Sale Price', round(e.price,2) as 'Original Price', round(base_grand_total,2) as 'G.T.(Base)',round(grand_total,2) as 'G.T.(Purchased)',round(d.qty_ordered) as 'Product Qty Ordered',status as 'Status',a.coupon_code as 'Coupon Code',a.customer_email as 'Email'
FROM sales_flat_order_item d left outer join sales_flat_order a on d.order_id = a.entity_id left outer join sales_flat_order_payment b on d.order_id = b.entity_id left outer join sales_flat_order_address c on a.customer_id = c.entity_id left outer join catalog_product_index_price
e on d.product_id = e.entity_id where status != 'canceled' and d.base_price > 0 and e.customer_group_id = 0
答案 0 :(得分:1)
我通过将round((e.price/d.base_price)*100) as 'Percentage'
添加到SELECT
语句来解决它:
SELECT DISTINCT (CASE
WHEN b.method = 'checkmo' THEN 'Check / Money order'
ELSE 'Credit Card (saved)'
END) AS 'Payment Method',a.increment_id as 'Ref-Order Number',a.store_name as 'purchased From (Store)', a.created_at as 'Purchased On',CONCAT (customer_firstname,' ',customer_lastname) as 'Sender-Store Name',CONCAT (customer_firstname,' ',customer_lastname) as 'Attention',c.telephone as 'Phone',c.street as 'Shipping Street',c.city as 'Shipping City',c.region as 'Shipping State',c.postcode as 'Shipping Zip',d.Sku as 'SKU',name as 'Name', round(e.price,2) as 'Original Price', round(d.base_price,2) as 'Sale Price', round((d.base_price/e.price)*100) as 'Percentage', round(base_grand_total,2) as 'G.T.(Base)',round(grand_total,2) as 'G.T.(Purchased)',round(d.qty_ordered) as 'Product Qty Ordered',status as 'Status',a.coupon_code as 'Coupon Code',a.customer_email as 'Email'
FROM sales_flat_order_item d left outer join sales_flat_order a on d.order_id = a.entity_id left outer join sales_flat_order_payment b on d.order_id = b.entity_id left outer join sales_flat_order_address c on a.customer_id = c.entity_id left outer join catalog_product_index_price
e on d.product_id = e.entity_id where status != 'canceled' and d.base_price > 0 and e.customer_group_id = 0