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

Posted on 2011-02-15
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

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 =
                           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 = 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 =              -- Match on currency id
LVL 14

Accepted Solution

Kalpan earned 500 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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

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

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

932 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now