Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


How Do I count multiple records for more than one date in MySQL?

Posted on 2011-02-15
Medium Priority
Last Modified: 2012-05-11
Below is my code, what I am trying to do is to get the total of two records 'buy_or_sell' and 'still_valid'. This works for ONE date '2011-02-14', but I need to see multiple dates, for example "dates.D1_date >= '2011-02-01' ". How would I accomplish this?

What I am getting now:
| TF   | Tdate          | curr | B_S |
|  1   | 2011-02-14 | USD  | 758 |

What I want to see:
| TF   | Tdate          | curr | B_S |
|  1   | 2011-02-14 | USD  | 758 |
|  1   | 2011-02-11 | USD  | 743 |
|  1   | 2011-02-10 | USD  | 744 |
|  1   | 2011-02-09 | USD  | 790 |

Question by:John_2357
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Author Comment

ID: 34895885
SELECT  base.timeframes_id AS TF,
             dates.D1_date AS Tdate,
             currencies.symbol AS curr,
             COUNT(ind.buy_or_sell) AS B_S
FROM dates
INNER JOIN baseid AS base  ON  base.Dates_id = dates.id
                           AND dates.D1_date = '2011-02-09'    -- Only match on dates more recent than 'n'.
                           AND base.timeframes_id = 1                                        -- daily (1), Weekly (4), Monthly (7)
INNER JOIN harleys AS ind   ON base.id = ind.fk_BaseId_id
                           AND ind.still_valid = 1           -- signal is valid
                           AND ind.buy_or_sell = 'S'
INNER JOIN currencies       ON currencies.symbol = 'USD'
                           AND base.currencies_id = currencies.id              -- Match on currency id
LVL 14

Accepted Solution

Kalpan earned 2000 total points
ID: 34895888
please refer the below query

select * from <yourtable> dates where dates.D1_date >= '2011-02-01' group by dates.D1_date

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question