Skip to content

Instantly share code, notes, and snippets.

SELECT
Operations.date,
COUNT(distinct Operations.OrderID) as "nombre d'opérations",
SUM(CASE WHEN Operations.type = 'buy' THEN Operations.amount ELSE 0 END) as 'Sous total achat',
SUM(CASE WHEN Operations.type = 'sell' THEN Operations.amount ELSE 0 END) as 'Sous total vente',
SUM(CASE WHEN Payments.method = 'card' THEN Payments.amount ELSE 0 END) as 'Sous total card',
SUM(CASE WHEN Payments.method = 'sepa' THEN Payments.amount ELSE 0 END) as 'Sous total sepa',
SUM(CASE WHEN Payments.method = 'cash' THEN Payments.amount ELSE 0 END) as 'Sous total cash'
SUM(Operations.amount) as 'Total Amount',
SUM(Operations.commission) as 'Commission',
SELECT
EXTRACT(year from Operations.date) as 'Année',
EXTRACT(MONTH from Operations.date) as 'Mois'
COUNT(distinct Operations.OrderID) as "nombre d'opérations",
SUM(CASE WHEN Operations.type = 'buy' THEN Operations.amount ELSE 0 END) as 'Sous total achat',
SUM(CASE WHEN Operations.type = 'sell' THEN Operations.amount ELSE 0 END) as 'Sous total vente',
SUM(CASE WHEN Payments.method = 'card' THEN Payments.amount ELSE 0 END) as 'Sous total card',
SUM(CASE WHEN Payments.method = 'sepa' THEN Payments.amount ELSE 0 END) as 'Sous total sepa',
SUM(CASE WHEN Payments.method = 'cash' THEN Payments.amount ELSE 0 END) as 'Sous total cash'
SUM(Payments.amount) as 'Total Amount',
@borenstejn
borenstejn / gist:18752099acc6162fc0c1
Created March 30, 2015 15:15
PG::ConnectionBad: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/tmp/.s.PGSQL.5432"? from /usr/local/var/rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/activerecord-4.1.8/lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `initialize'
rm /usr/local/var/postgres/postmaster.pid
sudo launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
sudo launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist