在表列中获取最大值

时间:2018-10-15 02:37:04

标签: yii2

我正在尝试在控制器中用这些行回显最大值

$taskid = (new Query())->select('MAX(id)')->from('member');

echo $taskid;

不幸的是我收到了以下文字

O:12:"yii\db\Query":20:{s:6:"select";a:1:{i:0;s:7:"MAX(id)";}s:12:"selectOption";N;s:8:"distinct";N;s:4:"from";a:1:{i:0;s:21:"member";}s:7:"groupBy";N;s:4:"join";N;s:6:"having";N;s:5:"union";N;s:6:"params";a:0:{}s:18:"queryCacheDuration";N;s:20:"queryCacheDependency";N;s:27:"yii\base\Component_events";a:0:{}s:35:"yii\base\Component_eventWildcards";a:0:{}s:30:"yii\base\Component_behaviors";N;s:5:"where";N;s:5:"limit";N;s:6:"offset";N;s:7:"orderBy";N;s:7:"indexBy";N;s:16:"emulateExecution";b:0;}

请帮帮我

2 个答案:

答案 0 :(得分:0)

会员模型的最大id值:

<dependency>
    <groupId>net.masterthought</groupId>
    <artifactId>cucumber-reporting</artifactId>
    <version>3.8.0</version>
    <scope>test</scope>
</dependency>

public static void generateReport(String karateOutputPath) {
    Collection<File> jsonFiles = FileUtils.listFiles(new File(karateOutputPath), new String[] {"json"}, true);
    List<String> jsonPaths = new ArrayList(jsonFiles.size());
    jsonFiles.forEach(file -> jsonPaths.add(file.getAbsolutePath()));
    Configuration config = new Configuration(new File("target"), "demo");
    ReportBuilder reportBuilder = new ReportBuilder(jsonPaths, config);
    reportBuilder.generateReports();        
}

答案 1 :(得分:-1)

我从麻烦中得到了解决方案,我想分享一下,这里是:

$taskid = Member::find()->select(" id, MAX('id') as numbers")->one();

echo $taskid['id'];