#1 2011-10-05 09:35:24

noobies
Member
Registered: 2011-09-13
Posts: 139

Count in query

use ADO i write for count all man:

query.SQL.Text := 'select count(id) as cnt from table where Sex = "M"';
query.Open;
ManCount := query.FieldByName('cnt').AsInteger;

or

query.SQL.Text := 'select id from table where Sex = "M"';
query.Open;
ManCount := query.RecordCount;

how use framework qiuck count Man?

Mans := Database.List([TSQLPatients], '*','Sex = "М"').RowCount; 

this code work, but is a good way??

what other way can count the number of people with the condition?

Last edited by noobies (2011-10-05 09:39:31)

Offline

#2 2011-10-05 09:41:04

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: Count in query

You can use Count(*) as field name if you want to.
This will be executed as plain SQL by mORMot. Even the In-Memory pure Delphi databases implements count(*).

If you only need to retrieve the row count, it will be faster than using the RowCount method, which will retrieve all data rows as JSON from server, so will be slower.

Offline

Board footer

Powered by FluxBB