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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:49:31+00:00 2026-06-09T17:49:31+00:00

I have the following two tables (SQL scripts with data): CREATE TABLE [dbo].[Item_Master]( [Item_Name]

  • 0

I have the following two tables (SQL scripts with data):

CREATE TABLE [dbo].[Item_Master](  
[Item_Name] [varcha`enter code here`r](20) NOT NULL,  
[Item_Cost] [int] NULL,  
 CONSTRAINT [PK_Item_Master] PRIMARY KEY CLUSTERED   
(  
    [Item_Name] ASC  
)  
)  

GO  

CREATE TABLE [dbo].[ItemAnalysis]  
(  
Item_Name nvarchar(20) NOT NULL,  
Analysis_Type nvarchar(20) NOT NULL,  
Item_Quantity int NOT NULL,  
Analysis_Date date NOT NULL  
)  

GO  

insert Item_Master (Item_Name, Item_Cost)   
values ('item1', 2)     
insert Item_Master (Item_Name, Item_Cost)  
values ('item2', 3)  

insert ItemAnalysis (Item_Name, Analysis_Type, Item_Quantity, Analysis_Date)   
values ('item1', 'A', 10, '2012-01-14')  
insert ItemAnalysis (Item_Name, Analysis_Type, Item_Quantity, Analysis_Date)   
values ('item1', 'B', 12, '2012-01-14')  
insert ItemAnalysis (Item_Name, Analysis_Type, Item_Quantity, Analysis_Date)   
values ('item2', 'A', 11, '2012-01-14')  
insert ItemAnalysis (Item_Name, Analysis_Type, Item_Quantity, Analysis_Date)   
values ('item2', 'B', 14, '2012-01-14')  
insert ItemAnalysis (Item_Name, Analysis_Type, Item_Quantity, Analysis_Date)   
values ('item1', 'A', 9, '2012-02-11')  
insert ItemAnalysis (Item_Name, Analysis_Type, Item_Quantity, Analysis_Date)     
values ('item1', 'B', 11, '2012-02-11')  
insert ItemAnalysis (Item_Name, Analysis_Type, Item_Quantity, Analysis_Date)  
values ('item2', 'A', 20, '2012-02-11')  
insert ItemAnalysis (Item_Name, Analysis_Type, Item_Quantity, Analysis_Date)   
values ('item2', 'B', 7, '2012-02-11')  

I need the output like this:

Item_Name| Item_Cost| Analysis_Date| Type_A_Quantity| Type_B_Quantity  
----------------------------------------------------------------------  
item1|2|2012-01-14|10|12  
item2|3|2012-01-14|11|14  
item1|2|2012-02-11|9|11  
item2|3|2012-02-11|20|7  

There is no regularity on when the analysis would be done (e.g. it cal be done weekly or monthly etc) but whenever the analysis is done it is done for all the items on a single day.

  • 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-09T17:49:32+00:00Added an answer on June 9, 2026 at 5:49 pm

    SQL Fiddle

    SELECT
        m.Item_Name,
        m.Item_Cost,
        a.Analysis_Date,
        SUM(CASE WHEN Analysis_Type = 'A' THEN Item_Quantity ELSE 0 END) as Type_A_Quantity,
        SUM(CASE WHEN Analysis_Type = 'B' THEN Item_Quantity ELSE 0 END) as Type_B_Quantity
    FROM Item_Master m
    JOIN ItemAnalysis a
        ON m.Item_Name = a.Item_Name
    GROUP BY m.Item_Name, m.Item_Cost, a.Analysis_Date
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following two sql tables: The GlassesID Column in Glasses table is
I have the following two tables: CREATE TABLE `table1` ( `ID` int(11) NOT NULL
I am using VB.NET with LINQ to MS SQL. I have two following tables.
I have the following two tables in my mysql database. Table Name: groups id
I have the following two tables, affiliates and referrers. affiliates Table id loginid 3
1I have the following two tables (sample data) and need to be able to
So imagine you have the following two tables: CREATE movies ( id int, name
I've two tables which have following columns: Now I want have a SQL query
I have the following two SQL tables for storing movie titles, and the dates
I have the following SQL statement (SQLite 3.0) which is joining two tables, the

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.