I’m creating a view where I pretty much replicate the data of the original user, but I also have an attribute in which I want to put the number of occurrences the user has in the downloads table.
CREATE VIEW customer_count_streams_vw(
sid_customer
systemuser_id
postcode
age
gender
num_streams)
AS
SELECT
user.sid_customer,
user.systemuser_id,
user.postcode,
user.age,
user.gender,
num_streams
FROM md_customer
INNER JOIN ods_streaming AS num_streams (
SELECT COUNT(ods_streaming.sid_customer)
WHERE ods_streaming.sid_customer = md_customer.sid_customer)
What I want is to place the result of the part:
SELECT COUNT(ods_streaming.sid_customer)
WHERE ods_streaming.sid_customer = md_customer.sid_customer
into the num_streams field.
Your query should be
Above query will return rows for customers with row in md_customer and also a row in ods_streaming. If you want all customers and their count (including 0) then your query should be