Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2004
    Posts
    482
    Plugin Contributions
    0

    Default Query for Daily Sales [using mysql]

    There has to be a better mousetrap for what I need :)



    My current query looks like the following to pull all the class sums from the order totals table per day

    SELECT LEFT(date_purchased,10),
    (select SUM(zen_orders_total.value)
    FROM
    zen_orders_total
    INNER JOIN zen_orders ON zen_orders.orders_id = zen_orders_total.orders_id
    where zen_orders_total.class = "ot_subtotal" and left(date_purchased,10) = '2012-12-10'
    GROUP BY LEFT(date_purchased,10)
    order by date_purchased desc
    limit 1) as ot_subtotal,

    (select SUM(zen_orders_total.value)
    FROM
    zen_orders_total
    INNER JOIN zen_orders ON zen_orders.orders_id = zen_orders_total.orders_id
    where zen_orders_total.class = "ot_coupons" and left(date_purchased,10) = '2012-12-10'
    GROUP BY LEFT(date_purchased,10)
    order by date_purchased desc
    limit 1) as ot_coupons,

    (select SUM(zen_orders_total.value)
    FROM
    zen_orders_total
    INNER JOIN zen_orders ON zen_orders.orders_id = zen_orders_total.orders_id
    where zen_orders_total.class = "ot_shipping" and left(date_purchased,10) = '2012-12-10'
    GROUP BY LEFT(date_purchased,10)
    order by date_purchased desc
    limit 1) as ot_shipping,

    (select SUM(zen_orders_total.value)
    FROM
    zen_orders_total
    INNER JOIN zen_orders ON zen_orders.orders_id = zen_orders_total.orders_id
    where zen_orders_total.class = "ot_tax" and left(date_purchased,10) = '2012-12-10'
    GROUP BY LEFT(date_purchased,10)
    order by date_purchased desc
    limit 1) as ot_tax,

    (select SUM(zen_orders_total.value)
    FROM
    zen_orders_total
    INNER JOIN zen_orders ON zen_orders.orders_id = zen_orders_total.orders_id
    where zen_orders_total.class = "ot_gv" and left(date_purchased,10) = '2012-12-10'
    GROUP BY LEFT(date_purchased,10)
    order by date_purchased desc
    limit 1) as ot_gv,


    (select SUM(zen_orders_total.value)
    FROM
    zen_orders_total
    INNER JOIN zen_orders ON zen_orders.orders_id = zen_orders_total.orders_id
    where zen_orders_total.class = "ot_total" and left(date_purchased,10) = '2012-12-10'
    GROUP BY LEFT(date_purchased,10)
    order by date_purchased desc
    limit 1) as ot_total



    FROM
    zen_orders
    INNER JOIN zen_orders_total ON zen_orders_total.orders_id = zen_orders.orders_id
    where left(date_purchased,10) = '2012-12-10'

    order by date_purchased desc
    limit 1


    Returns the following:
    left(date_purchased,10) ot_subtotal ot_coupons ot_shipping ot_tax ot_gv ot_total
    12/14/12 xx.00 xx.00 xx.00 xx.00 xx.00 xx.00



    I would love to have it return a bunch of days (maybe 7 at a time)

    Not including the limit 1 and such returns a mess in the array or an error of operand should include one column or subquery has too many rows.

    Please advise so I can keep my hair. :)

  2. #2
    Join Date
    Jan 2004
    Posts
    66,443
    Plugin Contributions
    279

    Default Re: Query for Daily Sales [using mysql]

    Why not just use the Sales Report plugin?
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  3. #3
    Join Date
    Jan 2004
    Posts
    482
    Plugin Contributions
    0

    Default Re: Query for Daily Sales [using mysql]

    it's 2 basic, it doesn't include these items I listed

  4. #4
    Join Date
    Jan 2004
    Posts
    482
    Plugin Contributions
    0

    Default Re: Query for Daily Sales [using mysql]

    LOL... Why yes, there is another plugin (had the one with graphs)... Thank you for the hint... the Sales Report plug in has exactly what I need! Thank you!

  5. #5
    Join Date
    Jan 2004
    Posts
    482
    Plugin Contributions
    0

    Default Re: Query for Daily Sales [using mysql]

    Super Super Plugin!! Thank you for the heads up! Someone obviously built a great mousetrap!! :)

 

 

Similar Threads

  1. Point of Sale for in store sales using Mysql
    By mandeepmavi in forum General Questions
    Replies: 1
    Last Post: 12 Dec 2010, 02:04 AM
  2. Advice needed for daily product import (Easy Populate, PHP + MySQL or ??)
    By yourguide in forum Setting Up Categories, Products, Attributes
    Replies: 1
    Last Post: 19 Aug 2010, 01:22 AM
  3. looking for a daily sales add on
    By therealex in forum All Other Contributions/Addons
    Replies: 2
    Last Post: 9 Apr 2010, 07:05 PM
  4. MySQL Query to include sales/specials
    By LissaE in forum General Questions
    Replies: 5
    Last Post: 16 Jan 2010, 09:00 PM
  5. Looking for a Daily Sales Report
    By milobloom in forum General Questions
    Replies: 2
    Last Post: 12 Sep 2007, 03:58 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg