gpt4 book ai didi

mysql - 我想结合两个 nodejs 程序以获得一个结果 : specific CSV data filtered by type - how do I combine the code properly?

转载 作者:行者123 更新时间:2023-12-04 07:39:25 27 4
gpt4 key购买 nike

我的 CSV 数据中有三种类型的客户,我只想显示 Type1...
我已经编写了两个单独的代码,但我想将它们合二为一:
这是过滤特定列:

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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com