model->setData ("SELECT props.number, props.sample, props.top, props.bottom, AVG(ds.magn), MEDIAN(TO_NUMBER(ds.magn)) FROM ds JOIN props ON props.number = ds.number WHERE ds.cd BETWEEN props.top AND props.bottom GROUP BY props.number, props.cnumber, props.sample, props.top, props.bottom HAVING props.number = 11 ORDER BY TO_NUMBER(props.cnumber) desc, TO_NUMBER(props.sample) desc");
if (model->lastError().isValid())
qDebug() << model->lastError();
else qDebug() << "success!";
model
->setHeaderData
(0, Qt
::Horizontal,
QObject::tr("CNumber"));
model
->setHeaderData
(1, Qt
::Horizontal,
QObject::tr("Sample"));
model
->setHeaderData
(2, Qt
::Horizontal,
QObject::tr("Top"));
model
->setHeaderData
(3, Qt
::Horizontal,
QObject::tr("Bottom"));
model
->setHeaderData
(4, Qt
::Horizontal,
QObject::tr("Mean Magnectic"));
model
->setHeaderData
(5, Qt
::Horizontal,
QObject::tr("Median Magnectic"));
view->setModel(model);
view->show();
QSqlQueryModel *model = new QSqlQueryModel;
model->setData ("SELECT props.number, props.sample, props.top, props.bottom, AVG(ds.magn), MEDIAN(TO_NUMBER(ds.magn)) FROM ds JOIN props ON props.number = ds.number WHERE ds.cd BETWEEN props.top AND props.bottom GROUP BY props.number, props.cnumber, props.sample, props.top, props.bottom HAVING props.number = 11 ORDER BY TO_NUMBER(props.cnumber) desc, TO_NUMBER(props.sample) desc");
if (model->lastError().isValid())
qDebug() << model->lastError();
else qDebug() << "success!";
model->setHeaderData(0, Qt::Horizontal, QObject::tr("CNumber"));
model->setHeaderData(1, Qt::Horizontal, QObject::tr("Sample"));
model->setHeaderData(2, Qt::Horizontal, QObject::tr("Top"));
model->setHeaderData(3, Qt::Horizontal, QObject::tr("Bottom"));
model->setHeaderData(4, Qt::Horizontal, QObject::tr("Mean Magnectic"));
model->setHeaderData(5, Qt::Horizontal, QObject::tr("Median Magnectic"));
QTableView *view = new QTableView;
view->setModel(model);
view->show();
To copy to clipboard, switch view to plain text mode
Bookmarks