sql - PostgreSQL Using COUNT to form statistical results -


I have some tables that create a media catalog of live / studio music, where zero-multiple shows in each media item There are dates, CDs and vinyls associated with it. At this time the statistics in my query are available which are available in the tabular set of data for all media items. I'm having trouble now that the query is being expanded to include better sprouted figures on each associated table.

Schema:

  Media (ID, title) The query is far off like this:  

Select CD, MID, MTT, (inherent CDID), COUNT (separate v.id) as Vinyl, gid as gig.id, gig. date from gdate as media i nis Involvement Add CD to MDI m.id = c.media Leave midid vinyl v at m.id = v.media LEFT JOIN media_gigs on m.id = G.media LEFT JOIN GIG GIG on g.gig = gig MID, gig.id by id GROUP;

Which produces:

  id | Title | CD | Vinil | GID | Gdate --- + --------- + ----- + ------- + --------------------- ----- + ------------ 1 | Title 1 5 | 1 | May-11-1989-Kawasaki | 1989-05-11 1 title 1 | 5 | 1 | May-13-1989-Tokyo. 1989-05-13 2 heading 2 | 6 | 0 | Apr-29 -1998-Nagongya | 1998-04-29 2. Heading 2 | 6 | 0 | May-6-1998-Tokyo. 1995-05-06 2 heading 2 | 6 | 0 | May-7-1998-Tokyo 1998-05-07 3 title 3 | 6 | 2 | This -1-186-new-York-city. 1986-12-01 3 | Title 3 6 | 2 | December-5-19 86-Quebec City 1986-12-05 3 Title 3 | 6 | 2 | Nav-19-1986-Tokyo 1986-11-19 3. Title 3 6 | 2 | Nav-20-1986-Tokyo. 1986-11-20   

cd.type is an enum type of [silver, cdr, pro-cdr] Because I want to add to the results, the final goal is to create 3 extra columns, which is the type of CD associated with each media item. I did not get the correct syntax using the COUNT or otherwise to collect the CD on the basis of this type, so the push in the right direction seems to be for SQL I am quite new, which I have so far can be a bit naive.

Using PG 9.3

You determine the type of CD type as a result and to a sum, the case Function can be used:

  Select m.id, m.title, COUNT (DISTINCT c.id) CD, COUNT (DISTINCT v.id) as vinyl, gid Forms gig.id, gdate as gig.date, sum (case cd.type silver, then 1 and 0 end) silver, (when 'cd.type' cd.type then 1 and 0th end) Yoga CDR, SUM (case cd.type when 'pro CDR' then 1 and 0 end) left media meter with pro_cdr Join at .id = cd c cmedia.m.id = v.media on the left Left vinyl vi join m.id = g.media left g.gig = gig.id Join gig gig m.id on group, Join on gig.id by media_gigs;         / Html>

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -