Skip to content

Tag: sql

count the 3 different values ​that a column can take

I’m trying to count the 3 different values ​​that a column in a table can take, in a single SELECT. What am I doing wrong? I am using a postgresql table where the column named “tipoprova” is an integer Answer You are looking for filtered aggregation: Your query is wrong, because you have the wrong syntax for the CASE expression.

How to filter record with specific condition?

I have a table called post which contains Wordpress posts that have this structure: each zoacres-property post have a meta stored inside the meta table: I’m trying to filter the zoacres-property post by price, and I successfully did this using this query: which returns: this result is correct but, I would like to display all the property which have a

Count one column by considering another column

This is my Audit table: I need to write 2 different queries and I have no idea how should I write them: How many invoices do have ONLY product 2 (+ Total price)? How many invoices do have diffrent products but product 2 as well (+ Total price)? the result I want looks like this: Answer If I understand correctly,

How to query multiple conditions for one column in SQL?

I have three tables, one is book, the other one is category and last one book_category which has relation between book and category. In my situation I have books and their categories. For example one book can have multiple categories. How can query the books have both categories. For example, one book have novel and story categories, and other book

How can I select one value from list

I would like to select one record if there are many status. example, if there is the same user and status A, B, C, select only record ‘A’. If there is the same user and status B, C, choose B, if there is only one status, bring that one. expected RESULT Could anyone help to suggest? Thank you Answer group