Track Your Usage and Gather Data Over Time
The application must:
The application should have:
Habits Table:
habit_id
(Primary Key Auto-Increment)habit_name
(e.g., "smoking a half-bowl of weed", "riding a bike for 30 minutes")habit_description
(optional description of the habit)HabitEntries Table:
entry_id
(Primary Key Auto-Increment)habit_id
(Foreign Key referencing Habits table)entry_timestamp
(Timestamp of when the entry was recorded, down to the second)Count the number of times a habit has been used in the past day
SELECT COUNT(*) AS hit_count
FROM HabitEntries
WHERE habit_id = (
SELECT habit_id
FROM Habits
WHERE habit_name = 'Smoke a Bowl'
) AND entry_timestamp BETWEEN '2023-05-07 00:00:00' AND '2023-05-07 23:59:59';
Retrieve all habit entries, including timestamps
SELECT he.entry_id, h.habit_name, he.entry_timestamp
FROM habit_entries he
INNER JOIN habits h ON he.habit_id = h.habit_id
ORDER BY he.entry_timestamp DESC;
Word | Definition |
---|---|
Habit | A behavior to be recorded. |
Use | A timestamped action. An instance of using something. A partaking. |
Event | A row in the database table representing a 'Use.' |