question

sathwikreddy987 avatar image
sathwikreddy987 asked

SQL Server Question

Hello all, This is possibly a rather simple Q, but nevertheless a challenge for me: On a single table, I have information about Store_id and their items. Each item is located on its own column.![alt text][1] What I wish to do now, is to make a statement that returns the store_id’s if there is value 1 on either of three categories (Books_Under7, Books_Under13, Books_Under18) and is one of the many items in store. Result should be of store_id’s: 10000 10001 10002 10003 10005 What I wish to do now, is to make a statement that returns the store_id’s if there is value 1 on either of three categories (Books_Under7, Books_Under13, Books_Under18) and are alone. Result should be of store_id’s: 10001 10002 There are 50 more columns that defines the other items in store after the Bags_Under13 column name and their values may be 1 or 0. These are 2 scenarios I'm looking for: 1) I need to pull the store_id where the any of the books related columns that has value 1 in the table and these should be alone. 2) I need to separately pull the stores where it has the value as 1 in books related columns as well as the other columns may have value 1 I tried by using a self-join, but was unsuccessful (Possibly I have done something wrong) Any suggestions (preferably code examples) Thanks! [1]: /storage/temp/4434-capture.jpg
sql-server-2008
capture.jpg (27.9 KiB)
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

This sounds like homework? Can you post what you have tried thus far?
0 Likes 0 ·

1 Answer

·
sajikumar.vk avatar image
sajikumar.vk answered
the column Books_Under13, is missing ...... also please explain "these should be alone" in scenario 1
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.