Adding two count(*) results together

I have these two queries and I want to add them SELECT count(*) FROM table2 GROUP BY table1_id SELECT count(*) FROM table3 GROUP BY table1_id I tried something similar to the accepted answer in this question. The difference is that I have a group ...
more »

2017-03-13 20:03 (3) Answers

Rails .where() query not working

Thanks a lot for your help. I have a locations and ads table. Location has_many :ads I perform the following query on Location Model. @locations = Location.joins(:ads).where(@location_params.require(:location).permit(:id)).includes(:ads) Then I wa...
more »

2017-03-13 10:03 (1) Answers

Add read replicas for SilverStripe website

I've managed to get a stable load balanced front end servers that can scale horizontally quite well however the next bottle neck would be the db. There was a blog post discussing scaling dbs horizontally however very little detail on it. I'm currentl...
more »

2017-03-13 05:03 (1) Answers

could not connect to server:PostgreSQL -Heroku

I deployed a Django app in Heroku. Initially, it was run on SQLite3 database and later I upgraded to PostgreSQL. App is working perfect with local settings but, when I pushed the file to server it doesn't behave as expected. When I login to django ad...
more »

2017-03-12 07:03 (1) Answers

how to compare multiple rows in where clause

Given table: create table borrower ( customer_number char ( 1 0 ) , loan_number char ( 1 0 )); question: Find the customer number (i.e., ID) of every customer that shares all of the loans that customer “1234” has. If the customer whose custome...
more »

2017-03-01 03:03 (5) Answers

Postgresql - order by number of matches in array

I'm trying to get a list of the best matching items giving a list of tags. With the data below: DROP TABLE IF EXISTS testing_items; CREATE TEMP TABLE testing_items( id bigserial primary key, tags text[] ); CREATE INDEX ON testing_items using...
more »

2017-02-28 23:02 (4) Answers

SQL query percentage with 2 tables

I’m beginning with SQL and I’m having problems when I would like to run some queries. The database has these two tables: I would like to retrieve the name of the teams with “id_equip” 27 and 58 with the percentage of winning matches with ...
more »

2017-02-26 22:02 (3) Answers

Is it possible to get query faster?

I'm new to SQL and need help I have 4 tables: helmet arm +------+---------+-----+--------+ +------+---------+-----+--------+ | id | name | def | weight | | id | name | def | weight | +------+---...
more »

2017-02-18 09:02 (4) Answers

Django can't connect to Postgres in Docker setup

I'm setting up an application in Docker that uses Django and Postgres. I'm unable to connect to Postgres from the app. When I run either: docker-compose run web python manage.py runserver docker-compose run web python manage.py migrate I get the...
more »

2017-02-17 21:02 (1) Answers

SQL - PostgreSQL - Find gaps in booking calendar

I am currently setting up a web based system to allow users to find availabilities of boats in a calendar. I am using PostgreSQL 9.6 A user should be able to say I want to find a boat available for three hours in the next three months between 08h00...
more »

2017-02-12 14:02 (2) Answers