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 8470865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:38:16+00:00 2026-06-10T16:38:16+00:00

I have the following data structure: Table 1(groups): ID | Group ============= 1 |

  • 0

I have the following data structure:

Table 1(groups):

ID  | Group
=============
1   | Sample
2   | Data

Table 2(items):

ID  | GroupID | Cost | Amount
==============================
 1  |       1 |   1  | 12
 2  |       1 |   7  | 15
 3  |       1 |   3  |  8
 4  |       2 |   2  | 12

And would like the following (query) results:

groups.ID | groups.Name | total
        1 | Sample      | 141
        2 | Data        |  24

total is the sum over the products of cost and amount of all items in the group i.e. for group 1: 1*12+7*15+3*8=141

Im guessing I have to something with

SELECT g.ID, g.Group, SUM(Products) 
FROM groups AS g, items AS i 
WHERE g.ID=i.GroupID 
GROUP BY i.GroupID

But don’t know what exactly.
Doing iit in clientsoftware with loops is no problem, but I am curious (and certain) that this can be done in (my)Sql

  • 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-10T16:38:17+00:00Added an answer on June 10, 2026 at 4:38 pm
    SELECT g.ID as ID, g.Group as Name, SUM(i.Cost * i.Amount) as total
    FROM groups g
    INNER JOIN items i ON i.GroupID = g.ID
    GROUP BY g.Group, g.ID
    

    Having a field named “Group” is quite a bad idea in SQL (reserved keyword)

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

Sidebar

Related Questions

I have a table emp with following structure and data: name dept salary -----
I have something like the following data structure: Category StartDateTime EndDateTime =============================================== 1 12/1/2009
I have the following data structure (it's an append only table for mapping content
I have a table in PostgreSQL with the following structure & data: Question |
Let's say I have the following hypothetical data structure: create table country ( country_id
I have the following data structure: TABLE requirements ID 1, AGE 1, GENDER 1,
I have the following data structure and data: CREATE TABLE `parent` ( `id` int(11)
I am using MySQL 5.0. I have table with following structure and data. CREATE
How to find data for the following query Original Source question 89 Table structure:
I have following table structure, with many tables like this: data_1: +-------+--------+-------+ | views

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.