Solved

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

Posted on 2011-02-15
2
480 Views
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 |
+----+--------------+------+------+


0
Comment
Question by:John_2357
2 Comments
 
LVL 1

Author Comment

by:John_2357
Comment Utility
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
;
0
 
LVL 14

Accepted Solution

by:
Kalpan earned 500 total points
Comment Utility
please refer the below query

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

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

743 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

14 Experts available now in Live!

Get 1:1 Help Now