View Full Version : Sum of a column in QSqlTableModel
giusepped
7th November 2008, 03:33
Is it possible to put a query like
SELECT SUM(column) FROM mytable
inside a QSqlTableModel?
I woud get the sum of table without re-querying the database, because I already have the model...
wysota
7th November 2008, 10:51
Do you want it as a separate row or a separate column or how? I think the best way would be to use a proxy model.
SunnySan
7th November 2008, 15:56
This example may help
QSqlQuery query;
query.exec("SELECT MAX(id) FROM mytable");
if (query.next()) {
myStringResult = query.value(0).toString();
}
query.finish();
off course you need to replace the SQL code inside the .exec(_)
giusepped
8th November 2008, 04:24
Ok, but I would use some Qt model.
If I used a model to connect to the database, I would not to make an sql query.
There is a way to put compicated query inside the model?
G
jacek
10th November 2008, 23:38
You can use QSqlQueryModel.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.