Note that there are some explanatory texts on larger screens.

plurals
  1. PO4 table join so that only 1 response is given for each company instead of a result for each campaign
    primarykey
    data
    text
    <p>Thanks for your help!</p> <p>I'd like to output all companyName entries that have uploads across any of their serverFiles as:</p> <p><strong>companies.companyName - count(files.fileID) - sum(serverFiles.uniqueUploads)</strong></p> <pre><code>Initech Ltd. - 11 - 24931 Epiphyte Inc. - 23 - 938821 </code></pre> <p>Here are the relavent parts of my table structure:</p> <p><strong>Table: companies</strong></p> <pre><code>companyID (INT) - companyName (TEXT) </code></pre> <p><strong>Table: campaigns</strong></p> <pre><code>campaignID(INT) - companyID (INT) </code></pre> <p><strong>Table: files</strong></p> <pre><code>fileID (INT) - campaignID (INT) </code></pre> <p><strong>Table: serverFiles</strong> serverFileID (INT) - fileID (INT) - uniqueUploads(INT)</p> <p>Each company can have multiple campaigns.</p> <p>Each campaign can have multiple files.</p> <p>Each file can have multiple serverFiles</p> <p>The query I tried to use is as follows:</p> <pre><code>SELECT companies.companyName, sum(serverFiles.uniqueUploads), count(files.fileID) FROM companies INNER JOIN campaigns on companies.companyID = campaigns.companyID INNER JOIN files on files.campaign = campaigns.campaignID LEFT OUTER JOIN serverFiles on serverfiles.fileID = files.fileID GROUP BY serverFiles.uniqueUploads, files.fileID ORDER BY sum(serverFiles.uniqueUploads) DESC; </code></pre> <p>However, this returns multiple entries for each company (as it creates multiple outputs for each company - one for each campaign under the company). </p> <p>eg:</p> <p><strong>companies.companyName - count(files.fileID) - sum(serverFiles.uniqueUploads)</strong></p> <pre><code>Initech Ltd. - 2 - 234234 (for initech campaign1) Initech Ltd. - 4 - 223323 (for initech campaign2) Epiphyte Inc. - 13 - 6434 (for epiphyte campaign1) Initech Ltd. - 1 - 554 (for initech campaign3) Epiphyte Inc. - 13 - 7544 (for epiphyte campaign2) Epiphyte Inc. - 11 - 74545 (for epiphyte campaign3) Epiphyte Inc. - 23 - 456544 (for epiphyte campaign4) </code></pre> <p>How do I change the query to only give me one response back for each company, summing up all of the campaigns under that company. </p> <p>Thanks so much for any assistance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload