• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 488
  • Last Modified:

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

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
John_2357
Asked:
John_2357
1 Solution
 
John_2357Author Commented:
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
 
KalpanCommented:
please refer the below query

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

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now