0
votes
1answer
16 views

SELECT several columns based on one condition

Is there a way to generate more then one column based on one condition? My perception is like: SELECT CASE WHEN condition_column = 'condition true' and (condition_column2 = 'condition true' or ...
5
votes
1answer
2k views

Make a range in postgres

How can I make a range in a select in PostgreSQL? I'd like to have this result: num --- 1 2 3 4 5 6 From a query like: SELECT range(1,6) AS num;
0
votes
3answers
28 views

Postgres: Distinct but only for one column

I have a table on pgsql with names (having more than 1 mio. rows), but I have also many duplicates. I select 3 fields: id, name, metadata. I want to select them randomly with ORDER BY RANDOM() and ...
0
votes
5answers
53 views

Relational algebra: select only last try

consider this database table : table: score(player_name,player_lastname,try,score) primary key: (player_name,player_lastname,try) (dont discuss the table schema, its just an example) this table hold ...
0
votes
1answer
41 views

more than one row returned by a subquery used as an expression postgresql

postgresql, I have a table my_table 4 table that has columns stxstxid, stxuserid sumamountstx, userid, amountcredit, amountsrc My goal is to merge different rows that have the same stxstxid, ...
2
votes
4answers
74 views

Joining tables if the reference exists

I got a PostgreSQL database with 4 tables: Table A --------------------------- | ID | B_ID | C_ID | D_ID | --------------------------- | 1 | 1 | NULL | NULL | --------------------------- | 2 | ...
0
votes
5answers
29 views

Operations on selected items

I want to have query like this: SELECT sum(data_parts.size) as size_sum, (size_sum/2.) as half_of_size_sum FROM data_parts WHERE data_parts.some_id='1'; Of course it won't work, because ...
0
votes
1answer
27 views

postgreSQL max select depending on groups

I am facing a particularly difficult (for my skill level) select query. I have some data in a database which are as such: 4 columns (maleName/femaleName/size/id). The column data are more or less ...
0
votes
4answers
49 views

postgresql: how to SELECT entries that satisfy a condition

I am trying to select the entries that have the same text in the "email" column of my postgreSQL table. I am completly new to database and this is the first database I ever created, so sorry if it's a ...
2
votes
3answers
139 views

How to re-use result for SELECT, WHERE and ORDER BY clauses?

The following query returns the venues near us (lat: 62.0, lon: 25.0) inside whose radius we fall in ordered by distance: SELECT *, earth_distance(ll_to_earth(62.0, 25.0), ...
1
vote
2answers
39 views

Divide records into groups - quick solution

I need to divide with UPDATE command rows (selected from subselect) in PostgreSQL table into groups, these groups will be identified with integer value in one of its columns. These groups should be ...
1
vote
2answers
1k views

Postgresql SELECT random with unique value

I am not able to make one clean SELECT I have postgresql table with fields id , providerid, deal_name I want to make random select with unique providerid SELECT * FROM deals ORDER BY random() ...
4
votes
5answers
84 views

Select unique count of rows referenced

High level: I have checklists and checklists have checklist items. I want get the count of checklists that been completed. Specifically, checklists that have checklist items but that are all ...
0
votes
3answers
59 views

finding the latest entry in Postgres

The following (Postgres) query always returns a result, because the performance.query_plan table has several entries, with different ts (Timestamp) values. select * from performance.query q, ...
0
votes
1answer
70 views

Update table using data from other tables (normalization)

I have doubt to mount a query to update and / or add data in a table. I have a table1 that will be supplied with the following rules: The table1 have the same fields of table2 + status field to show ...

1 2 3 4 5 12
15 30 50 per page