SQL - Getting a column from another table to join this query

后端 未结 2 1977
野趣味
野趣味 2021-01-16 20:23

I\'ve got the code below which displays the location_id and total number of antisocial crimes but I would like to get the location_name from a diff

2条回答
  •  广开言路
    2021-01-16 20:57

    You want to use join to lookup the location name. The query would probably look like this:

    SELECT ld.location_name, COUNT(cf.fk3_crime_id) as TOTAL_ANTISOCIAL_CRIMES
    from CRIME_FACT cf join
         LOCATION_DIM ld
         on cf.fk5_location_id = ld.location_id
    WHERE cf.fk1_time_id = 3 AND cf.fk3_crime_id = 1
    GROUP BY ld.location_name;
    

    You need to put in the right column names for ld.location_name and ld.location_id.

提交回复
热议问题