If this is a DataTable in Thingworx, you can retrieve the records using the build in services like GetDataTableEntries
If this is in an External Database, then you will need the proper extension first to connect to it using the appropriate JDBC Driver and Connection string.
After that you can set up Services of type SQL Query and SQL Command to interact with that Data.
This would be similar to our MySQL tie in example from the training.
The SQL you write, is essentially the same SQL you would use within that particular database, not sure if there is a specific syntax piece you have a problem with.
After you have the Data retrieved, you can use the Aggregate service which has the ability to give you COUNT. We used this service when we went over InfoTable handling and did the Inventory for our Vending Machines.
The Wiki will have an entry on Aggregate as well in Section 5 and there is also an Example in the Examples section.
Hope that gets you the information you need.