简体   繁体   English

如何使用LoopBack REST API获取不同的列值

[英]How can I get distinct column values using LoopBack REST API

I have loopback REST API, which returns all the data from MySQL table in JSON format. 我有环回REST API,它以JSON格式返回MySQL表中的所有数据。 But, I want to query or apply filter where it returns only distinct values for a given column. 但是,我想查询或应用过滤器,它只返回给定列的不同值。 For eg in SQL we use this syntax :SELECT DISTINCT column1 FROM table_name; 例如,在SQL中,我们使用以下语法:SELECT DISTINCT column1 FROM table_name; How can I achieve this using LoopBack Rest API? 如何使用LoopBack Rest API实现此目的? Does LoopBack support something like above? LoopBack是否支持上述内容? Please suggest me any other solution. 请建议我任何其他解决方案。

To my knowledge there is no filter for DISTINCT. 据我所知,DISTINCT没有过滤器。

You can execute the sql command instead and receive the JSON object in return 您可以改为执行sql命令并接收JSON对象

var sql = "select DISTINCT name from user";
var ds = {YourModel}.app.datasources.{yourConnectionName};
ds.connector.execute(sql, [], function(err, data) {
// your code here
});

Refer http://loopback.io/doc/en/lb2/Executing-native-SQL.html for more details. 有关详细信息,请参阅http://loopback.io/doc/en/lb2/Executing-native-SQL.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何实现MySQL的DISTINCT关键字以使用线程并行获取不同的值 - How can I implement DISTINCT keyword of mysql to get distinct values parallely using threads 我可以获得 MySQL 中 json 列的唯一/不同值吗? - Can I get unique/distinct values of json column in MySQL? 如何使用环回 REST API 过滤器查询 MySQL JSON 字段值 - How to Query MySQL JSON Field Values with a Loopback REST API Filter SQL:如何获得列中不同值的总数? - SQL: How would I get a total count for distinct values in a column? 我如何通过计数不同值来获得值顺序 - How i can get values order by the count of distinct values 如何使用DISTINCT选择其余的行? - How can I select the rest of the row with DISTINCT? 数据库中的一列存储一个或多个复选框的值,如何从整个列中获得不同的值? - A column in database store one or more values of check boxes, How i get distinct values from whole column? MySQL:如何在一个列中获取AVG值,以便在另一列中共享不同值的条目? - MySQL: How do I get the AVG value in one column for entries sharing distinct values in another column? 如何通过列获得不同的行? - How do I get distinct rows by a column? Laravel查询在列上获取不同的值,但是在使用orderby获取最新的不同值之后 - Laravel Query to get distinct values on a column, but after using orderby to get latest distinct values
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM