Skip to content

Commit 2639eb7

Browse files
committed
new code
1 parent f01cbef commit 2639eb7

5 files changed

+54
-11
lines changed

Data-Modelling/Cloud_Share_DropBox_Service.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Fact_Files_Logs
7272
- owner_user_id
7373
- date_id
7474
- shared_user_id null
75-
- is_ownser_shared (true, false)
75+
- is_owner_shared (true, false)
7676
- share_date (date_id)
7777
- clicked_via (email, link, social_media) null
7878
- access_type (view, edit)

Data-Modelling/Online_Streaming.sql

+4-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ Dim_Date
1919
- date
2020
- day
2121
- month
22+
- week
23+
- quarter
2224
- year
23-
- day_of_week
24-
- week_of_year
2525

2626
Dim_user
2727
- user_id
@@ -53,7 +53,8 @@ Dim_Content
5353
- content_type (video, audio, image, document)
5454
- content_category
5555
- content_release_date (date_id)
56-
- Genre
56+
- content_run_length -- if video then add else 0
57+
- genre
5758

5859
Fact_Streaming
5960
- streaming_id

Data-Modelling/Taxi_Ride_Service.sql

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Dim_Date
3030
- day
3131
- week
3232
- month
33+
- quarter
3334
- year
3435

3536

datelist.sql

+47-6
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,56 @@ DO UPDATE SET activity_date_int = activity_date_int_table.activity_date_int | EX
108108
-- Way to check whether that day from current day active or not, while checking the bit is active or not (right bit wise)
109109
select userid, (activity_date_int >> 1) & 1 from activity_date_int_table
110110

111-
-- Testing....
111+
-- Testing zone....
112+
113+
-- Updating the user cummulative activity data with new data.
112114
UPDATE activity_date_int_table
113115
SET activity_date_int = activity_date_int | (1 << (CURRENT_DATE - '2024-07-22'::date))
114116
WHERE userid = 456;
115117

116-
with cte as (select generate_series(current_date - interval '7 day', current_date - interval '1 day', '1 day') rg)
118+
119+
-- Checking users last 7 day activity date wise
120+
121+
-- generate_series(current_date - interval '7 day', current_date - interval '1 day', '1 day')
122+
-- activity_date_int >> (CURRENT_DATE - rg::date)) & 1
123+
124+
with cte as (select generate_series(0, 6) rg)
117125
select
118-
userid, rg,
119-
(activity_date_int >> (CURRENT_DATE - rg::date)) & 1 as active
126+
userid,
127+
count(case when (activity_date_int >> (rg)) & 1 = 1 then 1 else 0 end) as week_active_lness
120128
from cte cross join activity_date_int_table
121-
group by 1,2
122-
order by rg desc
129+
group by 1
130+
131+
132+
133+
----------------------------------------------------------------------------------------------------------------------------------------------------------
134+
-- TODO
135+
136+
CREATE OR REPLACE FUNCTION bit_counts(num BIGINT) RETURNS INT AS $$
137+
DECLARE
138+
count INT := 0;
139+
BEGIN
140+
WHILE num > 0 LOOP
141+
count := count + (num & 1);
142+
num := num >> 1;
143+
END LOOP;
144+
RETURN count;
145+
END;
146+
$$ LANGUAGE plpgsql;
147+
148+
149+
SELECT
150+
userid,
151+
activity_date_int,
152+
t.last_7_days_mask,
153+
bit_counts(activity_date_int & t.last_7_days_mask) active_last_7_days
154+
FROM activity_date_int_table
155+
cross join (SELECT 1023 AS last_7_days_mask) t
156+
157+
158+
SELECT
159+
userid,
160+
activity_date_int,
161+
activity_date_int & cast(pow(2, 12) as int) - 1
162+
-- LENGTH(REPLACE(((activity_date_int & ((1 << 11) - 1)::bigint))::bit(10))::text, '0', '')) AS last_10_days_data
163+
FROM activity_date_int_table

to_char_extract_substring.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ SELECT
2020

2121
SELECT
2222
SUBSTR('example_string', 1, 3) AS first_three_chars,
23-
SUBSTR('example_string', -3) AS last_three_chars
23+
SUBSTR('example_string', 12, 3) AS last_three_chars
2424

2525
-- LEFT, RIGHT
2626

0 commit comments

Comments
 (0)