简体   繁体   中英

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'. I have 1000's of records.
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. Thanks! :)

From what I understand, input column in your database table has product id and can be the same across several rows. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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