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

标签 mysql node.js database csv

我的 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/

相关文章:

java - JPA MySQL找不到创建的表

mysql - rake 数据库 :create gives NoMethodError: undefined method `init' for Rails:Module

node.js - React-native 启动

mysql - 根据子查询获取 COUNT 值

mysql - 获取剩余的行

node.js - 使用 lambda 函数以 JSON 形式获取数据库

javascript - 如何用 Knex.js 查询多对多关系?

database - 将整个数据库从 postgresql 传输到 Greenplum 服务器

java - 使用 Hibernate 与托管提供商创建 MySQL 数据库模式、优缺点、实践。

java - 在 Spring Boot 中通过 JPA 正确利用纪元秒