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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:12:27+00:00 2026-06-13T00:12:27+00:00

Pretty complicated… I have two tables, t1 which contains descriptive information regarding specific objects,

  • 0

Pretty complicated… I have two tables, t1 which contains descriptive information regarding specific objects, and the second table, t2, contains information used to decode the objects in t1.

I’ll try to provide a simple example:

----
t1 (Name, Type, Size, Color)
----
dog1 - mammal - big  -  brown

dog2 - mammal - big  -  black

cat1 - mammal - small - black

fish1 - fish - small - gold


---
t2 (Type, Size, Color, Value)
---
mammal - "" - blue - 1

mammal - big - brown - 0.5

mammal - big - black - 0.75

mammal - small - "" - 2

fish - big - "" - 5

fish - small - "" - 0.5

fish - small - gold - 0.5

"" - "" - black - 1

"" - big - "" - 0.75

---
result(name, value)
---
dog1 - 1.25 //receives a value of 1.25 (0.5+0.75) because it hits the row of being mammal/big/brown (0.5) and the extra hit of just being big (0.75)

dog2 - 2.5 // 0.75 + 1 + 0.75 for being mammal/big/black (0.75), for being black (1), and for being big (0.75)

cat1 - 2 //2 for being mammal/small

fish1 - 1 // 0.5 + 0.5 for being fish/small and fish/small/gold

---

This is my current query as it pertains to this example, but of course it doesn’t work for several reasons.

Select t1.Name, SUM(counter.Value) as Sums
 From
 (Select *
 From t1, t2
 where t1.Type = t2.Type and t1.Size = t2.Size and t1.Color = t2.Color)
  • 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-13T00:12:28+00:00Added an answer on June 13, 2026 at 12:12 am

    Try this (or replace the t2.XXX is null with t2.XXX = ” if you’re using blanks):

    declare @t1 table(name nvarchar(32), [type] nvarchar(32), size nvarchar(32), colour nvarchar(32))
    declare @t2 table([type] nvarchar(32), size nvarchar(32), colour nvarchar(32), value numeric(15,9))
    
    insert @t1
              select 'dog1','mammal','big','brown'
    union all select 'dog2','mammal','big','black'
    union all select 'cat1','mammal','small','black'
    union all select 'fish1','fish','small','gold'
    
    insert @t2
              select 'mammal',null,'blue',1
    union all select 'mammal','big','brown',0.5
    union all select 'mammal','big','black',0.75
    union all select 'mammal','small',null,2
    union all select 'fish','big',null,5
    union all select 'fish','small',null,0.5
    union all select 'fish','small','gold',0.5
    union all select null,null,'black',1
    union all select null,'big',null,0.75
    
    select t1.name, sum(t2.value) Value
    from @t1 t1
    inner join @t2 t2
    on (t1.type = t2.type or t2.type is null)
    and (t1.colour = t2.colour or t2.colour is null)
    and (t1.size = t2.size or t2.size is null)
    group by t1.name
    

    Results:

    name    Value
    cat1    3.000000000
    dog1    1.250000000
    dog2    2.500000000
    fish1   1.000000000
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a function which does something pretty complicated and it is
I have pretty complicated listview component organized as table. On every tr line I
I have a pretty complicated function which does a couple of AJAX posts on
I have a pretty complicated IIF expression in SSRS, in which I want to
i have a pretty complicated form. as you can see below: alt text http://img9.imageshack.us/img9/2465/test2xk.jpg
I have a pretty complicated index.php now, and I would like to only run
My use is pretty complicated. I have a bunch of objs and they are
I'm back with another (possibly) silly question. sorry. I have a pretty complicated query
I have a pretty complicated python program. Internally it has a logging system that
Within JSP files, I have some pretty complicated Javascript. On a production machine, we're

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.