javascript - 将列表的每次出现限制为 1

标签 javascript mysql node.js express

我有以下打印出数字列表的查询。我想将每个唯一数字限制为 1。

比如数据库中有3个18,则打印出18、18、18,如果是5的两次出现,则打印出5,5。我只显示 18,在这种情况下为 5。

let sqlSelectBoxInformation = "SELECT longestDimension from box ";

connectionBoxInformation.query(sqlSelectBoxInformation, function(err, rows, fields) {
    if (!err) {
        // Check to see if the user entered hashtag is found in the database
        // Create a variable to track if the item was found
        var data = {
            rows: rows,
            userHashtag: databaseHashtag
        }
        res.render('delivery/chooseBox', data);
    }
});

最佳答案

你可以使用DISTINCT:

SELECT DISTINCT longestDimension from box

分组依据

SELECT longestDimension from box GROUP BY longestDimension

关于javascript - 将列表的每次出现限制为 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42741736/

相关文章:

javascript - 我怎样才能让一盏灯关闭然后打开,然后另一盏灯亮起

javascript - 简单的 JavaScript/Bootstrap 下拉问题

php - Doctrine 查询错误未知列

mysql - sql选择现在之前的最大日期

MYSQL:从表中选择匹配组合和相反组合的所有行

mysql - 如何使用express在nodejs中进行mysql "ladder"查询

node.js - Sails的afterCreate(obj) : object is not updated

javascript - 我可以根据点击 li className 在一个 php 页面中显示单独的数据表吗?

javascript - 使用强制初始化方法将 'fake' 单例包装器添加到 Node 类

javascript - 来自 javascript 函数的 Coldfusion Cookie