Jump to content

Getting Statistical Informations From A Table


ulisses

Recommended Posts

hi guys! i'm a begginner on sql and php, i have to do something and i don't know how. i have a table, with:- a personal number that identifies each subscriber- the class of service to which the person subscribes- the date of the subscriptionnow i'm planing to create another table containing statistical informations, such as:- the number of subscriptions for a day- how many clients subscribed to each class of service, etc.i think of using sql count() function, but don't know how to implement it. i don't know if i've made u understand my problem, but i'd appreciate any kind of help. thank u

Link to comment
Share on other sites

I'm also new to (My)SQL, so if someone with more experience answers, take theirs above mine, but the easiest way is to make a SELECT query and then count the num_rows - for example:$query = "SELECT * FROM table_name WHERE date_subscribed = 'whatever'";$query_res = mysqli_query($mysqli_connection, $query);$count = mysqli_num_rows($query_res);Just swap date_subscribed for any other field you like.

Link to comment
Share on other sites

You can use COUNT like this:SELECT COUNT(*) AS num FROM tableThe field in the result will be called "num" and will contain the number of rows in the table. You can add a WHERE clause to that if you want. You can also use the other functions like SUM the same way:SELECT SUM(field) AS num FROM tableFunctions like COUNT and SUM are called aggregate functions. You can use GROUP BY with an aggregate function to get other statistics. If you have a table called subscriptions that contains a field called service, you can use this to get the number of subscriptions for each service:SELECT service, COUNT(service) AS num FROM subscriptions GROUP BY serviceThat will return one record for each service, where each record contains a service field that lists the service, and a num field that lists the number of subscriptions.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...