0

this is my view :

CREATE VIEW  Statistic as
SELECT
  (SELECT
     COUNT(0)
   FROM users) AS `tot_user`,
  (SELECT
     COUNT(0)
   FROM demands) AS `tot_demand`,
  (SELECT
     COUNT(0)
   FROM reports) AS `tot_report`,
  (SELECT
     COUNT(0)
   FROM users
   WHERE users.mobile_verified_at IS NULL) AS `user_inactive`,
  (SELECT
     COUNT(0)
   FROM reports
   WHERE reports.state =0) AS `report_inactive`,
  (SELECT
     COUNT(0)
   FROM demands
   WHERE demands.state = 1) AS `demand_inactive`,
  (SELECT COUNT(*) FROM replies LEFT JOIN demands ON demands.id=replies.id) AS `demand_replied`

i wanna fetch data where created_at( column ) between date1 and date2

this is my tables structure :

demand table

user table

**And so are the other tables

for example : i want fetch records that created between 2019-12-01 and 2020- 01-01

request(data1 and date 2 from the server) -> send ->database | Database => Return this view

4
  • 'wanna fetch data where created_at( column ) between date1 and date2' - thats pretty much the syntax so what problem are you having? Commented May 6, 2020 at 8:51
  • for example : i want fetch records that created between 2019-12-01 and 2020- 01-01 Commented May 6, 2020 at 8:58
  • Add proper WHERE to each separate subquery. Commented May 6, 2020 at 8:59
  • "TSQL" and MySQL refer to different databases. I'm confused by the title. The code suggests MySQL. Commented May 6, 2020 at 11:24

1 Answer 1

1

You want to compare a timestamp to a date so use date function

where date(created_at) between '2019-12-01' and '2020-01-01'

and do review mysql date functions. https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.