?
Solved

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

Posted on 2011-02-15
2
Medium Priority
?
486 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
[X]
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
2 Comments
 
LVL 1

Author Comment

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

Accepted Solution

by:
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
0

Featured Post

How To Install Bash on Windows 10

Windows’ budding partnership with Canonical has certainly led to some great improvements. One of them being the ability to use Bash on your Windows machine without third party applications! This might be one of the greatest things a cloud engineer in a Windows environment can do!

Question has a verified solution.

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

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
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

762 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