Mysql-MySql Query and inventory query

Source: Internet
Author: User
Substring (num) ASreal_stock, comment 'who _ tmp_real_stock2 'ADDUNIQUE ('goods _ id_new') SELECTa. goods_idasgoods_id, cat_id, d. real_stock,... mysqlselect

Create table who_tmp_real_stock2
Select sum (num) AS real_stock, goods_id AS goods_id_new
FROM who_goods_stock
Group by goods_id_new
ALTER TABLEwho_tmp_real_stock2
Add unique (goods_id_new)
SELECT a. goods_id as goods_id, cat_id, d. real_stock, a. goods_sn as goods_sn, goods_name, keywords, is_on_sale, is_delete,
Is_best, is_new, is_hot, is_promote, shop_price * 100 as shop_price, (shop_price * 6.3-in_price) * 1000 as profit,
Last_update, goods_number, goods_material, goods_color, B. goods_sku_value, customer_rate_num,
(C. sale_num * 15 + c. stock_num * 2) as stock_num, pattern_value, a. add_time

From who_goods_desc B,
Who_privilegestocknum c,
Who_goods a LEFT JOIN
Who_tmp_real_stock2 d ON a. goods_id = d. goods_id_new

Where a. goods_id = B. goods_id and
A. goods_id = c. goods_id and
A. goods_id> 0 and
C. stock_num> 0 and
Is_on_sale = 1 and
Is_delete = 0 and
Is_freeshipping = 0 and
A. goods_number> 0
Select .*
From who_goods
Where a. goods_id = $ id

SELECT a. goods_id AS goods_id, cat_id, a. goods_sn AS goods_sn, goods_name, keywords, is_on_sale, is_delete,
Is_best, is_new, is_hot, is_promote, shop_price * 100 AS shop_price, last_update, goods_number, goods_material,
Goods_color, pattern_value, c. real_stock
FROM who_goods AS,
Who_goods_desc AS B left join who_tmp_real_stock c ON B. goods_id = c. goods_id_new

WHERE a. goods_id = B. goods_id
AND is_on_sale = 1 AND
Is_delete = 0 AND
Is_freeshipping = 0 AND
A. goods_number> 0
If you want to obtain the product information whose inventory is greater than 0, do you know if this SQL statement is correct?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.