我的 CSV 数据中有三种类型的客户,我只想显示类型 1... 我编写了两个单独的代码,但我想将它们合并为一个:
这个是过滤特定列:
var mysql = require('mysql');
var con = mysql.createConnection({
host: "localhost",
user: "root",
password: "private",
database: "private"
});
con.connect(function(err) {
if (err) throw err;
con.query("SELECT customernumber, type, gender, name, streetapt, city, state, zip, phone, discount, outstandingbalance FROM customers", function (err, result, fields) {
if (err) throw err;
console.log(result);
});
});
这个是按TYPE过滤的:
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : 'private',
database : 'private'
});
connection.connect();
connection.query('SELECT type, COUNT(type) FROM icedcoffee.customers group by type', function(err, rows, fields)
{
if (err) throw err;
console.log(rows[1]);
console.log(rows[0]);
console.log(rows[2]);
});
connection.end();
最佳答案
这将显示客户中每一行的计数类型
SELECT customernumber, c.type, gender, name, streetapt, city, state, zip, phone, discount, outstandingbalance, t1.ctype
FROM customers c INNER JOIN (SELECT type, COUNT(type) ctype FROM icedcoffee.customers group by type) t1 ON c.type = t1.type
WHERE c.type = 1
关于mysql - 我想结合两个nodejs程序以获得一个结果: specific CSV data filtered by type - how do I combine the code properly?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67572444/