Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8992373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:56:20+00:00 2026-06-15T22:56:20+00:00

I have a query which returns analytics style information about a job board and

  • 0

I have a query which returns analytics style information about a job board and where applicants are coming from in the following structure:

Data format for query

The query to access that is:

SELECT   g.name AS [Source]
        ,SUM(CASE WHEN v.cost = 0 THEN 1 ELSE 0 END) AS [Organic Clicks]
        ,SUM(CASE WHEN v.cost <> 0 THEN 1 ELSE 0 END) AS [Paid Clicks]
        ,COUNT(v.id) AS [Total Clicks]
        ,SUM(CASE WHEN a.applicant = 1 AND v.cost = 0 THEN 1 ELSE 0 END) AS [Organic Applicants]
        ,SUM(CASE WHEN a.applicant = 1 AND v.cost <> 0 THEN 1 ELSE 0 END) AS [Paid Applicants]
        ,SUM(CASE WHEN a.applicant = 1 THEN 1 ELSE 0 END) AS [Total Applicants]
        ,SUM(v.cost/100.0) AS [Spend]
FROM a_views v
LEFT OUTER JOIN a_views a
    ON v.viewerid = a.viewerid
    AND v.sessionsourceid = a.sessionsourceid
    AND a.applicant = 1
JOIN a_sources s
    ON v.sourceid = s.id
JOIN a_sourcegroups g ON s.fk_sourcegroup = g.id
--JOIN jobs j ON v.jobid = j.anal_id AND j.featured = 1
WHERE v.hostName = @jobboard
    AND v.viewed_at >= @start AND v.viewed_at <= @end
GROUP BY g.name

The only issue is that in the LEFT OUTER JOIN a_views block there may be multiple records returned. What I need to do is only have the record tracked once in the Click sums but each time it’s found for the Applicant sums.

I did find a similar question of this happening on this question, but the answerer didn’t actually give much information.

To resum what I need, each instance of the record in the right side of the join, but only 1 instance of the record on the left side.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T22:56:21+00:00Added an answer on June 15, 2026 at 10:56 pm

    One way you could do this without changing your query entirely is separate the Click sums and Applicant sums into two separate queries, UNION them together and then group/sum them again.

    Something like this (pseudo code):

    SELECT
            Source
            ,SUM([Organic Clicks])
            ,.....
    FROM
    (
    SELECT   g.name AS [Source]
            ,SUM(CASE WHEN v.cost = 0 THEN 1 ELSE 0 END) AS [Organic Clicks]
            ,SUM(CASE WHEN v.cost <> 0 THEN 1 ELSE 0 END) AS [Paid Clicks]
            ,COUNT(v.id) AS [Total Clicks]
            ,0 AS [Organic Applicants]
            ,0 AS [Paid Applicants]
            ,0 AS [Total Applicants]
            ,SUM(v.cost/100.0) AS [Spend]
    FROM
            ClickOnlyTables
    
    UNION ALL
    
    SELECT   g.name AS [Source]
            ,0 AS [Organic Clicks]
            ,0 AS [Paid Clicks]
            ,0 AS [Total Clicks]
            ,SUM(CASE WHEN a.applicant = 1 AND v.cost = 0 THEN 1 ELSE 0 END) AS [Organic Applicants]
            ,SUM(CASE WHEN a.applicant = 1 AND v.cost <> 0 THEN 1 ELSE 0 END) AS [Paid Applicants]
            ,SUM(CASE WHEN a.applicant = 1 THEN 1 ELSE 0 END) AS [Total Applicants]
            ,0 AS [Spend]
    FROM
            ApplicantTables
    )
    GROUP BY
            Source
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query which returns a series of cells of data from a
I have the following query which returns a list of questions and the possible
I have the following MQL query which successfully returns the record for William Shakespeare.
I have a query which returns a set of numbers: SELECT Sequence FROM Table1
I have the following query which returns the salary of all employees. This work
I have a following method, which retrieves top visited pages from Google Analytics: public
Possible Duplicate: Retrieve column names from java.sql.ResultSet I have query which returns the result
I have a query which returns amount from a table: select bus_price from mySchema.BusTable;
I have the following query which returns NULL for each field if there are
I have the following query which returns the following error: An aggregate may not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.