Postres SQL select with GROUP BY and COUNT

i have this SQL select SELECT t.debtor_account, COUNT(t.debtor_account) FROM transaction t GROUP BY t.debtor_account HAVING COUNT(t.debtor_account) > 2; which work, but i need select all from …

How to hide rows where aggregate functions are used

let’s imagine here is my report: select 1 from dual union all select 2 from dual union all select 3 from dual union all select 4 from dual Output: 1 2 3 4 If e.g. i want to hide part of the report …

AVG in SQL Server

I am learning SQL Server, and I have a sample database which I got from my co-worker. I created a stored procedure previously which works fine. Now I am trying to show average of the column which I am …

Get the Defect Type with the maximum Total Defect Qty

I have the following query which gets the sum of defect quantity per Defect Type : SELECT [Defect Type] ,YEAR([Date]) AS YearOfDefect ,SUM([Total Defect Qty]) AS [Sum] FROM SupplierQuality GROUP BY […

Limited By Value Postgresql query

I have a couple of rows where values in one column are repeating and I need to get a couple of rows where every value is limited by const. For example, i have this rows (1, ‘a’) (2, ‘b’) (3, ‘a’) (4,’…

how to get the count of data based on status id in sql

i have following table id statusid 100 1 100 2 100 3 101 1 101 3 i am getting the result like following id data1 data2 data3 100 1 1 1 101 …

Order by with formatted dates, doing it right?

I wanted a mere sanity check because I have a slight feeling I am doing it all wrong. I stripped down the use case to a very simple sample. When formatting a date I need to cast the data in the order …

Group data by foreign key and date with total by date

I need help to select daily payments made and group by the organization and date. Group by date, then the total number of payments and the sum total amount of payments for each day Tables are as …

How to get the average from computed columns in Postgresql?

I have a query: SELECT sum(column_1), sum(…) as sum_1, sum(…) as sum_2, sum(…) as sum_3 FROM table_1 How to get an average data from sum_1, sum_2, sum_3? If I write a query in the next …

How do you populate boolean columns based on a table of properties?

I have a table called Product that contains a product identification number and an id associated with the product identification number. pin id 11 10 12 11 13 12 I also have a property table with the …