BigJobbies
BigJobbies

Reputation: 4045

Displaying group of results from SQL

I'm wondering if someone could help me out.

I'm trying to construct a SQL query.

I have a bunch of filenames, which i have put into an array like so

'filename1.jpg', 'filename2.jpg', 'filename3.jpg', 'filename4.jpg'

I also have a table with the following columns

date | filename | like | ipaddress

Everytime someone likes the filename a new row gets added to the table

What i need to do is count the likes for each filename and then print out the filename and like count for each of the files, im using classic ASP

Upvotes: 1

Views: 653

Answers (1)

Tom Studee
Tom Studee

Reputation: 10452

SELECT filename, sum(like) as likes FROM TABLE group by filename

to order by likes:

SELECT filename, sum(like) as likes FROM TABLE group by filename order by sum(like) desc

Upvotes: 3

Related Questions