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 7549373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:56:04+00:00 2026-05-30T09:56:04+00:00

I have a table names lcMovimientos and what I need is a query where

  • 0

I have a table names lcMovimientos and what I need is a query where I get as a result the sum of the quantity of cantidadMovimientos but I want each row to be by the day of the week and only to sum the days of the current week, so after researching I found the best way to do this was creating a new table with the days of the week, so I now have a table called diasSemana

SELECT * FROM diasSemana
+-----------+
| diaSemana |
+-----------+
|         0 |
|         1 |
|         2 |
|         3 |
|         4 |
|         5 |
|         6 |
+-----------+

and a table called lcMovimientos

mysql> DESCRIBE lcMovimientos;
+-----------------------+---------------+------+-----+---------+----------------+
| Field                 | Type          | Null | Key | Default | Extra          |
+-----------------------+---------------+------+-----+---------+----------------+
| idMovimiento          | int(11)       | NO   | PRI | NULL    | auto_increment |
| idUsuario             | int(11)       | YES  |     | NULL    |                |
| tipoMovimiento        | tinyint(4)    | YES  |     | NULL    |                |
| cantidadMovimiento    | decimal(20,2) | YES  |     | NULL    |                |
| idCategoria           | int(11)       | YES  |     | NULL    |                |
| fechaMovimiento       | date          | YES  |     | NULL    |                |
| idCuenta              | int(11)       | YES  |     | NULL    |                |
| descripcionMovimiento | varchar(255)  | YES  |     | NULL    |                |
| etiquetasMovimiento   | varchar(255)  | YES  |     | NULL    |                |
+-----------------------+---------------+------+-----+---------+----------------+

I can make a query where I do get the sum of the cantidadMovimiento but when I add the where clause so I only get results from the current week, I no longer get the rows by day fo the week, so here is my query:

mysql> SELECT SUM( cantidadMovimiento ) , diaSemana, fechaMovimiento                                                                                                    -> FROM diasSemana
    -> LEFT JOIN lcMovimientos ON diaSemana = WEEKDAY( fechaMovimiento ) 
    -> GROUP BY diaSemana;
+---------------------------+-----------+-----------------+
| SUM( cantidadMovimiento ) | diaSemana | fechaMovimiento |
+---------------------------+-----------+-----------------+
|                    280.00 |         0 | 2012-02-20      |
|                    800.00 |         1 | 2012-02-21      |
|                   7000.00 |         2 | 2012-02-29      |
|                      NULL |         3 | NULL            |
|                      NULL |         4 | NULL            |
|                  -3300.78 |         5 | 2012-02-18      |
|                    600.00 |         6 | 2012-02-26      |
+---------------------------+-----------+-----------------+

and when I use the WHERE clause:

mysql> SELECT SUM( cantidadMovimiento ) , diaSemana, fechaMovimiento
    -> FROM diasSemana
    -> LEFT JOIN lcMovimientos ON diaSemana = WEEKDAY( fechaMovimiento ) 
    -> WHERE WEEK( fechaMovimiento, 1 ) = WEEK( CURRENT_DATE, 1 ) 
    -> GROUP BY diaSemana;
+---------------------------+-----------+-----------------+
| SUM( cantidadMovimiento ) | diaSemana | fechaMovimiento |
+---------------------------+-----------+-----------------+
|                    265.00 |         0 | 2012-02-20      |
|                    800.00 |         1 | 2012-02-21      |
|                    600.00 |         6 | 2012-02-26      |
+---------------------------+-----------+-----------------+

So my question is how can i make a query where I will get the results by the day of the week using the where to only get dates of the current week??? thank you so much in advance!

  • 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-30T09:56:05+00:00Added an answer on May 30, 2026 at 9:56 am

    try this

    SELECT 
        COALESCE(SUM( cantidadMovimiento ),0) AS cantidadMovimiento,
        diaSemana,
        DATE_ADD(DATE(NOW()), INTERVAL diaSemana-WEEKDAY(NOW()) DAY) AS weekday
    FROM diasSemana
    LEFT JOIN lcMovimientos
        ON diaSemana = WEEKDAY( fechaMovimiento ) 
        AND WEEK(fechaMovimiento) = WEEK(NOW()) AND YEAR(fechaMovimiento) = YEAR(NOW())
    GROUP BY diaSemana;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an working application. Now I want to change the table names of
I have table one which looks like this. And I want to get data
My problem is, I have table of names. And when I touch on each
I have the below table which has 2 columns.I need to write a query
I have a table names 'emp'. Columns are: uid,emp_name,emp_dept,emp_sal. Now i want to find
I have a table called Names, it contains about 400 inputs. I want for
I have a table with names that correspond with their urls I want to
I have a table of names and ages that I want the user to
I have a table with server names and logins. I need to retrieve the
I have a table with names of movies, and I want to be able

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.