I have the following data: Then i do the following query: The result is correct: Then i add two column, name and value: That return: What i expect is: If i add group by on guid_count, cuid_count, and umdid_count: How to overcome this problem? Could you help point me where my mistake is? Thank you. Answer You …
Tag: postgresql
how to write select query in PostgreSQL to iterate over an array which is returned by a select query
SELECT b_items_p_id FROM public.box WHERE b_id =1 and this is what it returns: {1,3,5} Now on each of these value, i.e., 1, 3 and 5 I want to run another select query: select p_desc from public….
How to restore postgres 12 generated sql file into postgres 9.6 database
I am trying to restore the database. The database sql file is about 4.5 GB so I couldn’t edit it on editor. I dump the database using following command in postgres 12; But I need the same database in postgres 9.6. For this purpose, I write the following code to restore it It shows the error like this (E…
PostreSQL returning only specific value
I’ve got below structure: sample_table code | delivery | end_date | type —————+—————-+————–+—— C086000-T10001 | OK | 2014-11-12 | …
PostgresSQL custom sequence
I have a problem with nextval function, I have a custom sequence in my DB called InternalCodes and when i want to make a insert like this: insert into “Membership” (“Name”, “…
SQL Select from multiple tables and count third
I want to count number of rows in table that is referenced by two fields of other tables. I’ve the following structure Result that I want to achieve The statement that I’ve tried, but getting error at right join What I’m missing? Answer You are quite close. Main problems with your query: you…
How to create SQL query with multiple JSON parameters in golang application?
As you can see in my Golang application I have an array called layers. I want to insert data of that array to the table of the PostgreSQL database. My question is how to create such SQL query in the application? QUERY: Answer Because I cannot comment, I assume that: You’re using golang’s database/…
How to select from a column with a list of ids in postgresql
I’ve got mytable1 with row_number integer and list_of_ids int[] column mytable2 with id integer and company text columns Example entry for mytable1 Example entry for mytable2 I need to feed back values from mytable2 into mytable1. This way the expected output would be Answer You need to unnest the lists…
Select with IF statement on postgresql
I have a code like that: select tbl.person ,COUNT(distinct tbl.project) ,if (tbl.stage like ‘%SIGNED%’) then sum(tbl.value) else ‘0’ end if as test from my_table tbl group by 1 And …
How to query the count of two fields by two different clauses at the same time?
I want to query for a count of a WHERE clause 1 and another count of WHERE clause 2. I have a simplified query result for my booking app: I want to 3 columns in total, first being a field called Token, second the count of Pending grouped by renter, and finally the count Overdue field grouped also by renter.