I'm currently trying to populate my fact table and I'm having trouble populating the required time ID's. The time dimension is fully populated and complete. Basically in the time dimension each row is a 15 minute period. The fact table is populating details about calls. And in a staging call table I have the start and end time of the call.
I'm wanting to populate the fact table by joining the dimension On the staging table by the time start and when the time_Start in the dimension is between the start and end time in the staging.. I've ran the query below using the = operator but it does not seem to work and only pulls out 100 rows when i should be expecting more like 4000. Can i use BETWEEN instead of the = ?
INNER JOIN Time_Dim ON incoming_measure.StartTimeDate = Time_Start
WHERE Time_Start BETWEEN incoming_measure.StartTimeDate AND incoming_measure.EndTimeDate
Thanks for the help.
Ans: Joining two tables in SQL can be done in four major ways: Inner Join (returns rows with matching columns), Left Join (ALL records in the left table and matching records in the right table), Right Join (ALL records in the right table and matching records in the left table), and Union (removes duplicates).
Inner joins use a comparison operator to match rows from two tables based on the values in common columns from each table. For example, retrieving all rows where the student identification number is the same for both the students and courses tables.
Yes: You can use Inner Join to join on multiple columns. Save this answer.
We can perform the above activity using the CONCAT() function. CONCAT(): It takes column names as parameters and returns a column with value after concatenating all the values of the column passed parameters to the function.
Edit:
Your join is incorrect. The format of your join should be:
Select column from table A
INNER JOIN table b on
A.column = B.column
INNER JOIN table c on
B.column = c.column
Where B.column Between start_date AND end_date
You can use the <
and >
operators
Also, for sqlserver
it is important to use the yyyy-mm-dd
format
INNER JOIN Time_Dim ON incoming_measure.StartTimeDate = Time_Start
WHERE Time_Start > incoming_measure.StartTimeDate AND Time_Start < incoming_measure.EndTimeDate
You can also use Between
INNER JOIN Time_Dim ON incoming_measure.StartTimeDate = Time_Start
WHERE Time_Start Between incoming_measure.StartTimeDate AND incoming_measure.EndTimeDate
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With