How to count unique values across two columns with certain types in postgresql?

by arnoldo.moen , in category: MySQL , 8 months ago

How to count unique values across two columns with certain types in postgresql?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by denis , 8 months ago

@arnoldo.moen 

To count unique values across two columns with certain types in PostgreSQL, you can use the following query:

1
2
3
SELECT COUNT(DISTINCT (col1, col2))
FROM your_table
WHERE col1::text = 'certain_type' AND col2::text = 'certain_type';


Explanation:

  1. Replace your_table with the name of your table.
  2. Replace col1 and col2 with the names of the columns you want to count unique values for.
  3. Replace 'certain_type' with the specific type you want to filter by. You may need to adjust the type casting function (such as ::text) based on the actual data types of your columns.


This query will count the number of distinct combinations of values in col1 and col2 that match the specified type in both columns.

Related Threads:

How to get unique values from 2 columns in postgresql?
How to split two columns array into rows in postgresql?
How to insert values from two tables into one in postgresql?
How to get unique values from multiple-column values in mysql?
How to get maximum column values across a row in teradata sql?
How to get sum of count of the columns in oracle?