group by在MySQL中无法与联合一起使用

时间:2019-01-19 07:23:05

标签: mysql laravel

我的查询遇到一个问题,其中group by不与工会合作。 下面是查询:

(select products.*, sum(100000) as count1, product_sku.price AS sku_price, product_sku.label AS sku_label from `products` left join `product_sku` on `products`.`id` = product_sku.product_id AND product_sku.is_primary = "Yes" AND products.is_variation = "Yes" where `product_name` = "testproduct1" and `status` = "Active" and exists (select * from `campaign` where `products`.`exclusive_for` = `campaign`.`id` and `status` = "Published" and `active_inactive` = "Active" or `products`.`exclusive_for` is null) group by `products`.`id` having id != 0)

union

(select products.*, ROUND ( (LENGTH(products.product_name)- LENGTH( REPLACE ( products.product_name, "testproduct1", "") ) ) / LENGTH("testproduct1") ) AS count1, product_sku.price AS sku_price, product_sku.label AS sku_label from `products` left join `product_sku` on `products`.`id` = product_sku.product_id AND product_sku.is_primary = "Yes" AND products.is_variation = "Yes" where (`products`.`product_name` LIKE "%testproduct1%" or `products`.`description` LIKE "%testproduct1%") and `status` = "Active" and exists (select * from `campaign` where `products`.`exclusive_for` = `campaign`.`id` and `status` = "Published" and `active_inactive` = "Active" or `products`.`exclusive_for` is null) having id != 0 )
group by `p_id`

请帮助我。

1 个答案:

答案 0 :(得分:0)

尝试这个

import random

def roll():
    f=0
    arry = []
    count = 0
    while count is not 100:
        numb = random.randint(1,6)
        if numb == 1 or numb == 2:
            f -= 1
        elif numb == 3 or numb == 4 or numb == 5:
            f += 1
        else:
            f = f + random.randint(1,6)
        count += 1
        arry.append(f)
    return arry
roll = roll()
print(roll)