2016-09-20 1 views
0

Meine Suche ist:Anzahl der Daten als ouput

SELECT cat_name AS category_name, SUM(cat) AS catgory_count, SUM(total) AS category_sum, (
    SUM(total) *100/'10942263' 
) AS Percentage 
    FROM (

    SELECT a.category_name AS cat_name, COUNT(a.category_name) AS cat, SUM(b.position) AS total 
    FROM erom.category a, erom_kmch.nsdl b 
    WHERE a.bene_type_nsdl = b.bene_type 
    AND a.bene_stype_nsdl = b.bene_stype 
    AND b.date = '2016-07-22' 
    GROUP BY cat_name 
    UNION ALL SELECT a.category_name AS cat_name, COUNT(a.category_name) AS cat, SUM(b.shares) AS total 
    FROM erom.category a, erom_kmch.cdsl b 
    WHERE a.type_cdsl = b.type 
    AND a.bo_substat_cdsl = b.bo_substat 
    AND b.date = '2016-07-22' 
    GROUP BY cat_name 
    UNION ALL SELECT a.category_name AS cat_name, COUNT(a.category_name) AS cat, SUM(b.shares) AS total 
    FROM erom.category a, erom_kmch.member_member_master b 
    WHERE a.substatus_phy = b.substatus 
    AND b.date = '2016-07-22' 
    AND shares > '0' 
    GROUP BY cat_name 
)c 
GROUP BY cat_name 

    ----------------------- 

und ich bekomme die ouput als

---------------- 
     category_name   catgory_count    category_sum   Percentage 
    Bank-Nationalised   1       100   0.0009138877396750563 
    Clearing Member   13       2459    0.022472499518609634 
    Individual- Director  1       100    0.0009138877396750563 
Individual- Directors Relative 7       139969    1.2791595303457794 
    Individual- Promoters  1       30000    0.2741663219025169 
    Individual-Minor    1        1    0.000009138877396750563 
     ---------------------- 

aber brauchen die Ausgabe als count (Individual- Director, Individual- Directors Relative, Individual- Veranstalter) als oneIndividual und die Zählung 9

ich brauche eine Ausgabe wie

 category_name  catgory_count    category_sum  
     One-Individual  9      170069 

Ich brauche die Ausgabe nach der ersten Ausgabe erhalten, wenn jemand mir Addiert ohne viel Kontrolle von einer äußeren Schicht Wrapper

+0

Alle Kategorien Sie habe erwähnt, ist verschieden von anderen, So scheint Gruppe von wird nicht auf diese –

+0

nur nehmen, was Sie haben, und fügen Sie eine äußere Wrapper-Abfrage. Fragen sind wie Zwiebeln. Fügen Sie eine Ebene hinzu. – Drew

+0

Oder fügen Sie einfach eine 'Where' -Klausel vor Ihre letzte Zeile und Graben die 4. Spalte – Drew

Antwort

1

weiß helfen, ob alle Ihre erste Abfrage notwendig war:

Select 'One-Individual' as category_name, 
sum(category_count) as 'category_count', 
sum(category_sum) as 'category_sum' 
FROM 
(
    SELECT cat_name AS category_name, SUM(cat) AS category_count, SUM(total) AS category_sum, (
    SUM(total) *100/'10942263' 
) AS Percentage 
    FROM (

    SELECT a.category_name AS cat_name, COUNT(a.category_name) AS cat, SUM(b.position) AS total 
    FROM erom.category a, erom_kmch.nsdl b 
    WHERE a.bene_type_nsdl = b.bene_type 
    AND a.bene_stype_nsdl = b.bene_stype 
    AND b.date = '2016-07-22' 
    GROUP BY cat_name 
    UNION ALL SELECT a.category_name AS cat_name, COUNT(a.category_name) AS cat, SUM(b.shares) AS total 
    FROM erom.category a, erom_kmch.cdsl b 
    WHERE a.type_cdsl = b.type 
    AND a.bo_substat_cdsl = b.bo_substat 
    AND b.date = '2016-07-22' 
    GROUP BY cat_name 
    UNION ALL SELECT a.category_name AS cat_name, COUNT(a.category_name) AS cat, SUM(b.shares) AS total 
    FROM erom.category a, erom_kmch.member_member_master b 
    WHERE a.substatus_phy = b.substatus 
    AND b.date = '2016-07-22' 
    AND shares > '0' 
    GROUP BY cat_name 
) c 
GROUP BY cat_name 
) d 
WHERE category_name IN ('Individual- Director','Individual- Directors Relative','Individual- Promoters'); 
+0

Thk u Drew ..... bekam –

+0

froh, es zu hören :) – Drew

+0

Nun, wenn Sie die Antwort mit dem grünen Häkchen als nächstes markieren könnten zu den Pfeilen nach oben und nach unten (wenn es gelöst wurde), das wäre großartig – Drew

Verwandte Themen