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

  • Home
  • SEARCH
  • 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 8747427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:21:15+00:00 2026-06-13T12:21:15+00:00

I have this table: This selection is is duplicated many times for different var_lines

  • 0

I have this table:

table

This selection is is duplicated many times for different var_lines (which pretty much work as one row of data, or respondent for a survey) and set_codes (different survey codes).

With this query:

SELECT
    *, COUNT(*) AS total
FROM
    `data`
WHERE
    `var_name` = 'GND.NEWS.INT'
AND(
    `set_code` = 'BAN11A-GND'
    OR `set_code` = 'BAN09A-GND'
    OR `set_code` = 'ALG11A-GND'
)
AND `country_id` = '5'
GROUP BY
    `data_content`,
    `set_code`
ORDER BY
    `set_code`,
    `data_content`

The query basically counts the number of answers for a specific question. Then groups them survey (set_code).

What I need is for each of the grouped data_content answers for GND.NEWS.INT to also show the SUM of all the corresponding GND_WT with the same var_line.

For example if I had this:

data_id    data_content    var_name    var_line
1          2               GND.NEW.INT 1
2          1.4             GND_WT      1
3          2               GND.NEW.INT 2
4          1.6             GND_WT      2
5          3               GND.NEW.INT 3
6          0.6             GND_WT      3

I would get something like this:

data_id    data_content    var_name      var_line   total   weight
1          2               GND.NEW.INT   1          2       3
5          3               GND.NEW.INT   3          1       0.6

Thanks for any help.

  • 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-13T12:21:16+00:00Added an answer on June 13, 2026 at 12:21 pm

    Your requirements are not exactly clear, but I think the following gives you what you want:

    select d1.data_id,
      d1.data_content,
      d1.var_name,
      d1.var_line,
      t.total,
      w.weight
    from data d1
    inner join
    (
      select data_content,
        count(data_content) Total
      from data
      group by data_content
    ) t
      on d1.data_content = t.data_content
    inner join
    (
      select var_line,
        sum(case when var_name = 'GND_WT' then data_content end) weight
      from data
      group by var_line
    ) w
      on d1.var_line = w.var_line
    where d1.var_name = 'GND.NEW.INT'
    

    See SQL Fiddle with Demo

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this table, which can be seen as a basic custom gantt chart:
I have two processes that work with data in the same table. One process
I have this selector: $(table.details tbody tr:not(.details)) But I'm wondering why this inner table
I have this table Test as Id, SomeValue, SomeText contains about a mill records,
I have this table: UNIQUE_ID | WINNER_ID | FINALIST_ID ________1 | ________1 | __________2
I have this table structure on a SQL Server 2008 R2 database: CREATE TABLE
I have this table [Table 1] cid | arrived | date_arrived The [arrived field
I have this table And my goals is to have a table looking like
I have this table ---------------- | X | Y | ---------------- | a |
I have this table CREATE TABLE [dbo].[friend_blocked_list]( [subdomain] [varchar](50) NOT NULL, [un] [nvarchar](50) 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.