Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4067078
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T16:12:18+00:00 2026-05-20T16:12:18+00:00

I hope someone could show me the light. I’m trying since a long time

  • 0

I hope someone could show me the light.

I’m trying since a long time to get the result o some sales by week, day and year in one query with no chance.

I have found a syntax that can help me but dont work in mysql.

    TRANSFORM 
   Sum(Cantidad) AS Ventas 
SELECT 
   Producto, Cantidad 
FROM 
   Pedidos 
WHERE 
   Fecha Between #01-01-1998# And #12-31-1998# 
GROUP BY 
   Producto 
ORDER BY 
   Producto 
PIVOT 
   DatePart("m", Fecha) 

My real query is this one:

select sum(orders.final_price) AS total
     , orders.id_comercial
     , vendedores.nombre
from orders
   , vendedores
WHERE orders.id_comercial = vendedores.id
  AND DATE(orders.date_purchased) = DATE(NOW())
GROUP BY orders.id_comercial

I really will appreciate some ideas, it’s maybe to late in teh night here in spain 😉

The result of my query is this one:

total         id_comercial         nombre
740.83        24        AITOR ANGULO
2069.37       29        FERNANDO I
482.05        32        JOSE ANDRES
961.32        33        ALBERTO FERNANDEZ -CANTABRIA-
908.66        34        GONZALO
49.54         38        LUIS LOPEZ
4082.42       39        JULEN DEL CURA
1512.87       43        ALBERTO POBLACION
1268.91       44        MASSIMO
3269.08       45        JOSE RAMON BURGA
56.49         47        EMPRESA
2791.65       48        MARCO MORILLO
1445.57       61        TINO
869.73        63        SONIA
1052.02       381       DAVID ARIAS

Really thnx to all.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T16:12:19+00:00Added an answer on May 20, 2026 at 4:12 pm

    For example, this will give you the day, 7-day and year-to-date totals

    select sum(case when DATE(orders.date_purchased) = DATE(NOW()) then orders.final_price end) AS TotalToday
         , sum(case when DATE(orders.date_purchased) >= DATE(NOW() -7) then orders.final_price end) AS TotalLast7Days
         , sum(case when YEAR(orders.date_purchased) = YEAR(NOW()) then orders.final_price end) AS TotalYearToDate
         , orders.id_comercial
         , vendedores.nombre
    from orders
       , vendedores
    WHERE orders.id_comercial = vendedores.id
      AND orders.date_purchased >= date(concat(year(now()),'-01-01'))
    GROUP BY orders.id_comercial, vendedores.nombre
    

    FYI date(concat(year(now()),'-01-01')) gives you the first day of the current year

    But if you want a pivot table, then

    select sum(case when MONTH(orders.date_purchased) = 1 then orders.final_price end) AS Jan
         , sum(case when MONTH(orders.date_purchased) = 2 then orders.final_price end) AS Feb
          ....
         , sum(case when MONTH(orders.date_purchased) = 12 then orders.final_price end) AS Dec
         , orders.id_comercial
         , vendedores.nombre
    from orders
       , vendedores
    WHERE orders.id_comercial = vendedores.id
      AND orders.date_purchased >= date(concat(year(now()),'-01-01'))
    GROUP BY orders.id_comercial, vendedores.nombre
    

    There is no MySQL (or any other decent RDBMS for that matter) equivalent of the Access operator TRANSFORM, which automatically produces a dynamic number of columns from the data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having some trouble comparing two variables, hope someone could help. Basically what
I hope someone out there can shed some light on the topic of creating
Struggling with one aspect of my code that I hope someone could shed some
Hope someone could help me with this: I would like to have a column
hope someone can answer this. Here is some sample code. namespace std { #ifdef
Hope someone can help i cant seem to get my head around this, i
I have the following problem and hope someone could help. I have a SQL
hope someone could help me to understand how to solve my question. I have
I hope someone could help me out. My original task: I want to write
I am not too familiar with regex and hope someone could help. example: This

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.