Run Code
|
Code Wall
|
Users
|
Misc
|
Feedback
|
About
|
Login
|
Theme
|
Privacy
Query Optimization Required
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Editor:
CodeMirror
EditArea
Simple
Layout:
Vertical
Horizontal
--PostgreSQL 9.6 --'\\' is a delimiter drop table if exists Service cascade; create table Service (user_id int,service_id varchar,created_at timestamp); INSERT INTO Service ( user_id, service_id, created_at ) VALUES (201, 'rcygo', '2016-06-22 19:10:25-07'), (32, 'qkbhX', '2016-07-08 06:07:25-07'), (143, 'qmBr2', '2016-03-11 01:11:25-07'), (107, 'rcygo', '2017-11-29 21:09:19-07'), (32, 'sd4ifdca', '2017-03-22 19:10:25-07'), (143, 'rcygn', '2016-04-08 06:07:25-07'), (144, 'qbArm0', '2016-03-11 01:11:25-07'), (32, 'rbEkP', '2016-11-29 21:09:19-07'), (201, 'qkbhX', '2016-09-22 19:10:25-07'), (201, 'qkbhX', '2016-09-22 19:10:25-07'), (107, 'qmBr2', '2017-12-29 21:09:19-07'), (201, 'qmBr2', '2017-12-30 21:09:19-07'); ; SELECT CAST(count( distinct sr.user_id) as INT) as "Unique users Acquiring Entered Service",CAST(0 as TEXT) as "Other Services Acquired By These Unique Users",CAST(0 as INT) as "Total Unique Users of These Other Acquired Services" from public.Service sr where sr.service_id='rcygo' --So this would be user entered field but for now i have populated it with a value group by 2,3 UNION Select CAST(0 as INT) as "Unique users Acquiring Entered Service",CAST(B.Other_Services as TEXT) "Other Services Acquired By These Unique Users",CAST(count(distinct C.user) as INT) as "Total Unique Users of These Other Acquired Services" FROM ( SELECT sr.user_id as user from public.Service sr where sr.service_id='rcygo' --So this would be user entered field but for now i have populated it with a value ) As A JOIN ( SELECT sr.user_id as user,sr.service_id as Other_Services from public.Service sr where sr.service_id<>'rcygo' --So this would be user entered field but for now i have populated it with a value ) AS B on A.user=B.user JOIN ( SELECT sr.user_id as user,sr.service_id as Other_Services from public.Service sr ) AS C on B.Other_Services=C.Other_Services group by 1,2 order by 1 desc,3 desc LIMIT 8
absolute service time: 0,47 sec
edit mode
|
history
Unique users Acquiring Entered Service
Other Services Acquired By These Unique Users
Total Unique Users of These Other Acquired Services
1
2
0
0
2
0
qmBr2
3
3
0
qkbhX
2