简体   繁体   English

带计数条件的 SQL 查询

[英]SQL Query with count conditions

I'm new working with databases and i have the following question.我是新的数据库工作,我有以下问题。

I have a table with the columns: input, output and type.我有一个包含以下列的表:输入、输出和类型。
The column input and output are products ids and the column type only have 3 values 'techno','bio' or 'production'.列输入和输出是产品 ID,列类型只有 3 个值“techno”、“bio”或“production”。 I have 1000's of records.我有 1000 条记录。
Is it possible to do a query to find the inputs that have more than one record with 'production' type?是否可以进行查询以查找具有多个“生产”类型记录的输入?

I work with SQLite3 on python.我在 python 上使用 SQLite3。 Thanks!谢谢! :) :)

From what I understand, input column in your database table has product id and can be the same across several rows.据我了解,您的数据库表中的输入列具有产品 ID,并且可以在多行中相同。 If that's the case, then the query you're looking at should be something like this:如果是这种情况,那么您正在查看的查询应该是这样的:

select input, count(type) from table_name where type = 'production' group by input having count(type) > 1

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM