logo
down
shadow

Trying to get TOP 10 products per sales channel


Trying to get TOP 10 products per sales channel

By : user2951857
Date : November 18 2020, 03:49 PM
should help you out I have found some answers on this, but nothing helped me here. I need a query to find the top 10 products for every sales channel (5 in total) within a month. I've tried my luck with a monstrous union all query, but I don't get the results I need. (I think the query I've written isn't the best, anyway...) , Try this:
code :
SELECT A.SKU, A.ProductName, A.SalesChannel, A.pq
FROM (SELECT A.SKU, A.ProductName, A.SalesChannel, A.pq, 
             IF(@SalesChannel = @SalesChannel:=A.SalesChannel, @RowId:=@RowId + 1, @RowId:=1) AS RowNum
      FROM (SELECT a.SKU, a.ProductName, b.SalesChannel, SUM(a.PurchasedQuantity) as pq
            FROM all_all_orders_items a
            INNER JOIN all_all_orders b ON b.AmazonOrderID = a.AmazonOrderID
            WHERE b.SalesChannel IN (1, 2, 3, 4, 5) AND b.PurchaseDate  BETWEEN NOW() - INTERVAL 30 DAY AND NOW()
            GROUP BY a.SKU, b.SalesChannel
            ORDER BY b.SalesChannel, pq DESC
          ) AS A, (SELECT @SalesChannel:=0, @RowId:=1) AS B
      ORDER BY A.SalesChannel, A.pq DESC
     ) AS A 
WHERE A.RowNum <= 10
ORDER BY A.SalesChannel, A.RowNum;


Share : facebook icon twitter icon
Select top sales products

Select top sales products


By : Sachin Dhakad
Date : March 29 2020, 07:55 AM
this will help I have three tables like this , This should work :
code :
SELECT p.*, sum(po.quantity) qty
FROM products p
LEFT OUTER JOIN product_order po ON po.product_id = p.id
LEFT OUTER JOIN orders        o  ON o.id          = po.order_id
WHERE o.status != 'REJECTED'
GROUP BY po.product_id
ORDER BY qty DESC, p.created_at
SQL - Products with No Sales

SQL - Products with No Sales


By : Thoom yashwanth redd
Date : March 29 2020, 07:55 AM
This might help you I'm trying to list all the Products that have had no sales. I'm really close but I'm trying to use the NOT EXISTS statement to display all the ProductID's that are in the Product table, but not in the Orderline table; and hence have no sales. My code is as follows; , You can avoid the Subselect by simply doing a LEFT JOIN:
code :
SELECT product.productid
FROM product
LEFT JOIN orderline USING (productid)
WHERE orderline.productid IS NULL
ORDER BY product.productid
pgsql -Showing top 10 products's sales and other products as 'others' and its sum of sales

pgsql -Showing top 10 products's sales and other products as 'others' and its sum of sales


By : dson120
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further I have a table called "products" where it has 100 records with sales details. My requirement is so simple that I was not able to do it. , As @e4c5 suggests, use UNION:
code :
select id, prod_cat, sum(total_sales) as total_sales
with
  totals as (
    select --pc.m_product_category_id as id,
           pc.name as prod_cat,
           sum(i.grandtotal) as total_sales,
           ROW_NUMBER() over (order by sum(i.grandtotal) desc) as rank
    from adempiere.c_invoice i
    join adempiere.c_invoiceline il on (il.c_invoice_id=i.c_invoice_id)
    join adempiere.m_product p on (p.m_product_id=il.m_product_id)
    join adempiere.m_product_category pc on (pc.m_product_category_id=p.m_product_category_id)
    where i.dateacct >= date_trunc('year', now()) and i.dateacct < date_trunc('year', now()) + interval '1' year
    group by pc.m_product_category_id, pc.name
    ),
  rankedothers as (
    select prod_cat, total_sales, rank
    from totals where rank <= 10
    union
    select 'Others', sum(total_sales), 11
    from totals where rank > 10
    )
select prod_cat, total_sales
from ranked_others
order by rank
Order products by sales within 30 days followed by those without sales

Order products by sales within 30 days followed by those without sales


By : harish
Date : March 29 2020, 07:55 AM
I hope this helps you . You can use a case when expression for that. The expression that gives you the sold quantity in the last 30 days is:
code :
sum(case when orders.sold_time >= date_add(curdate(), interval -30 day) 
         then orders_products.products_quantity 
    end)
order by sum(case when o.sold_time >= date_add(curdate(), interval -30 day) 
                  then op.products_quantity 
             end),
         sum(op.products_quantity)
INNER JOIN products_description p2
       ON p2.products_id = pd.products_id
      AND p2.language_id = 10
table with sales and quantity of products - add column that count the products

table with sales and quantity of products - add column that count the products


By : user3725213
Date : March 29 2020, 07:55 AM
Does that help i have this table: , You can use window function :
code :
sum(quantity)  over (partition by product)
update t1
       set t1.quantity = (select sum(t.quantity) 
                          from #t as t  
                          where t.product = t1.product
                         )
from #t t1;
Related Posts Related Posts :
  • select the records with the highest amount
  • Changing Mysql golbal variable
  • How to create Effective Indexing on MySQL
  • `require': Incorrect MySQL client library version
  • How to save a FirstName of a Person efficiently without duplicate entries
  • Can I store my own sql query by mysql special function and execute stored query later?
  • MySQL comma separated field query
  • Why does the same exact query produce 2 different MySQL explain results?
  • Suppress warning output in bash
  • Doctrine "on update CURRENT_TIMESTAMP" annotation (Symfony2)
  • Designing "Friend" relationships across two mysql tables
  • Importing sql file using phpmyadmin in EasyPHP
  • Easy PHP and mysql ..php cannot see database on local pc (all works on server)
  • MySQL join optimization - bypassing filesort
  • How to Select record with the maximum value in a GROUP BY?
  • MySQL Innodb Full text Proximity Search Gives Horrible Performance
  • MySQL best approach for db normalising, relationships and foreign keys
  • How to update one table based on the count value of another table while matching ids?
  • MAMP Pro 5.1.1-terminates MySQL when quitting
  • SQL - Get date of most votes cast
  • "Fuzzier" search in mysql
  • Tracing mysqld Using SystemTap
  • SELECT + INSERT + Query Cache = MySQL lock up
  • SQL vs. NoSQL for medium complexity search systems
  • SQL Error when creating table
  • Is it possible to write a query to compare rows to other rows in same table?
  • Display all duplicate records based multiple columns
  • summing time column in mysql
  • InnoDB: Cannot open table
  • Why is IN() considered O(logN) operation?
  • Can a deadlock occur on commit?
  • Is there a fast way to do a '%phrase%' search in any DB?
  • Is using an IN over a huge data set a good idea?
  • How can I know if a table is already arranged in ascending order in MySQL?
  • MySQL - Designing database for a simple game
  • Why am I getting "Host '192.168.1.220' is not allowed to connect to this MySQL server"?
  • what type of password hash? possible mysql hash?
  • MySQL - Using a date range vs functions
  • Using IS NULL and COALESCE in OrderBy Doctrine Querybuilder
  • How to merge MySQL columns into one column if there are empty values in the table?
  • Cardinality Confusion
  • Renaming column multiple ids in SELECT
  • Group all from and to messages per user
  • How to handled the null values in WHERE IN condition in mysql
  • Is it okay to update primary key field to shift a record to the top?
  • Stop query through pdo
  • How to check whether particular value in field in MySQL exists
  • Execute a statement for every table in a database
  • insertion 74G data into mysql table cost more then 2 days, how to improve insert performance
  • Where can I see the differents "Hibernate Console Configurations" in Eclipse
  • MySql | relational database vs non relational database in terms of Performance
  • Exporting mysql database using mysqldump including procedures
  • Trigger MySQL not working
  • How do I update values for individual rows quickly?
  • MySQL join query with multiple where condition
  • MySQL stored procedure is not working
  • MySQL - Order By exact match at the end
  • Select max date or null date from same table MySQL
  • Best solution workaround for needing a mysql event on insert?
  • MySQL select several columns of several tables at the same time without using JOIN
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org