Help please I have table with two key fields varUser and varProperty - I am trying to count varProperty within a distinct varUser query to count varPropeerty only once for each user. SQL not my strongpoint and I can get a distinct or a count but not both.
your question is unclear but here is a a query that will return you a list of users subcategorised by a list of their varProperties and a count of each. so if user 1 has recorded 3 properties one of which is red and the other two is blue, you'd get
SELECT varUser,
varProperty,
count(varProperty) AS 'Num Instances'
FROM tablename
GROUP BY varUser ASC,
varProperty ASC
if you don't want the count, just omit the third line and suppress the trailing comma.
if you just want the count of the properties, omit the second line.
if you want something else, it's always helpful to provide a sample.
Hi and thank you so much but it is not quite what I am trying to do - I am trying to count how many users viewed ech property ignoring multiple viewings by a user. So for example
if user1 has viewed property1 x 2 property2 x 3 property3 x 4 and
user3 has viewed property1 x2 only the results of my querty should read
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.