I need to find the distribution of days active within a week and Create a table to show how many members are active for each day

user6384832

For table Members:

+----------+------------+------+-----+---------+-------+ 
| Field    | Type       | Null | Key | Default | Extra |
+----------+------------+------+-----+---------+-------+ 
| S_Date   | date       | YES  |     | NULL    |       | 
| memberID | varchar(5) | YES  |     | NULL    |       | 
+----------+------------+------+-----+---------+-------+

I need to find the distribution of days active within a week and Create a table to show how many members are active for 1 day, 2days, 3days,…7days during 3/1-3/7.

#Days Active    Count
1   
2   
3   
4   
5   

I have tried bitwise operations and count operations but nothing works

D-Shih

if you want to count Days Active you can use DATEDIFF function to calculate the date diff days.then use COUNT and group by to get members are active.

I guess you can follow this query.

SET @StartDate := '2017-03-01';
SET @EndDate := '2017-03-07';

SELECT DATEDIFF(S_Date,@StartDate) + 1 'Days Active',
       COUNT(1) 'Count' 
FROM Members 
WHERE S_Date BETWEEN @StartDate AND @EndDate 
GROUP BY S_Date

sqlfiddle:http://sqlfiddle.com/#!9/aa6ea3/1

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Select the last entry recorded in a table for each day, within a duration of days

分類Dev

SQL - How can I count distinct IDs for each day within the last 7 days?

分類Dev

After migrating to Azure, how can I query my organization Active Directory from within the application now hosted in Azure?

分類Dev

I need specific table data for each users

分類Dev

Concentration of potentially active microfacets in a Normal Distribution Function

分類Dev

How can I create a view where each row in one table is treated as a child of each row in another table?

分類Dev

How to find data in for every day of week in mongoose node js

分類Dev

How to find the products expiring within the weekend of the current week?

分類Dev

SQL query to find How many employees joined in one week

分類Dev

SQL query to find How many employees joined in one week

分類Dev

Horizontal paging: How to find which page that's currently active?

分類Dev

How can I calculate how many working days are to a determined date?

分類Dev

How do I make the active button in my tab have the "active" class?

分類Dev

How can I turn a date into the day of the week (as an integer)?

分類Dev

How can I change the first day of week in Swift

分類Dev

Find active winform in solution explorer

分類Dev

Create multiple active records with variables

分類Dev

Table Join in Rails Active Record

分類Dev

How to check for the active Application?

分類Dev

How to sum time intervals by days: How many intervals include a given day?

分類Dev

How can I have multiple active Windows sessions simultaneously?

分類Dev

How can I change body background color depending on active slide?

分類Dev

How do I style an active route that has query params?

分類Dev

How do I stop the hiding of a node when it is active?

分類Dev

How can I keep the selection active state of a button?

分類Dev

How to close all active tabs, when I opens one tab?

分類Dev

how do I hide form.errors until its active

分類Dev

How Can I change color of the container when it is active or inactive in a ListView

分類Dev

Firebase reporting too many Active Users

Related 関連記事

  1. 1

    Select the last entry recorded in a table for each day, within a duration of days

  2. 2

    SQL - How can I count distinct IDs for each day within the last 7 days?

  3. 3

    After migrating to Azure, how can I query my organization Active Directory from within the application now hosted in Azure?

  4. 4

    I need specific table data for each users

  5. 5

    Concentration of potentially active microfacets in a Normal Distribution Function

  6. 6

    How can I create a view where each row in one table is treated as a child of each row in another table?

  7. 7

    How to find data in for every day of week in mongoose node js

  8. 8

    How to find the products expiring within the weekend of the current week?

  9. 9

    SQL query to find How many employees joined in one week

  10. 10

    SQL query to find How many employees joined in one week

  11. 11

    Horizontal paging: How to find which page that's currently active?

  12. 12

    How can I calculate how many working days are to a determined date?

  13. 13

    How do I make the active button in my tab have the "active" class?

  14. 14

    How can I turn a date into the day of the week (as an integer)?

  15. 15

    How can I change the first day of week in Swift

  16. 16

    Find active winform in solution explorer

  17. 17

    Create multiple active records with variables

  18. 18

    Table Join in Rails Active Record

  19. 19

    How to check for the active Application?

  20. 20

    How to sum time intervals by days: How many intervals include a given day?

  21. 21

    How can I have multiple active Windows sessions simultaneously?

  22. 22

    How can I change body background color depending on active slide?

  23. 23

    How do I style an active route that has query params?

  24. 24

    How do I stop the hiding of a node when it is active?

  25. 25

    How can I keep the selection active state of a button?

  26. 26

    How to close all active tabs, when I opens one tab?

  27. 27

    how do I hide form.errors until its active

  28. 28

    How Can I change color of the container when it is active or inactive in a ListView

  29. 29

    Firebase reporting too many Active Users

ホットタグ

アーカイブ