Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQL Query

Posted on 2013-01-09
3
Medium Priority
?
295 Views
Last Modified: 2013-01-09
Hello,

I am in need of some assistance. I have an SQL DB that I need to run this query - however I do not know how to write the query beyond what is below.

SELECT [OrderNumber]
      ,[Date]
      ,[Branch]
      ,[InvoiceNumber]
      ,[Sku]
      ,[AccountNumber]
      ,[QtySold]
  FROM [SRIRRA50ED8483SQL].[dbo].[Sku]

Basically, I need to look at each InvoiceNumber and check to see if it contains any item [QtySold] => 12. If true than display all InvoiceNumbers that do not contain [Sku] = "QUIK".

Let me know if this is unclear or if you require further information.

Thank you very much for any assistance you can offer.

Ryan
0
Comment
Question by:Ryan Rood
  • 2
3 Comments
 
LVL 41

Expert Comment

by:ralmada
ID: 38759413
try

SELECT [OrderNumber]
      ,[Date]
      ,[Branch]
      ,[InvoiceNumber]
      ,[Sku]
      ,[AccountNumber]
      ,[QtySold]
  FROM [SRIRRA50ED8483SQL].[dbo].[Sku] a
  where exists(select 1 from [Sku] b where a.InvoiceNumber = b.InvoiceNumber and QtySold >= 12)
      and a.SKU <> 'QUIK'
0
 
LVL 9

Expert Comment

by:sognoct
ID: 38759415
SELECT [OrderNumber]
      ,[Date]
      ,[Branch]
      ,[InvoiceNumber]
      ,[Sku]
      ,[AccountNumber]
      ,[QtySold]
  FROM [SRIRRA50ED8483SQL].[dbo].[Sku]
 WHERE QtySold >= 12 AND NOT InvoiceNumber LIKE '%QUIK%'

Open in new window

0
 
LVL 41

Accepted Solution

by:
ralmada earned 2000 total points
ID: 38759426
oops

SELECT [OrderNumber]
      ,[Date]
      ,[Branch]
      ,[InvoiceNumber]
      ,[Sku]
      ,[AccountNumber]
      ,[QtySold]
  FROM [SRIRRA50ED8483SQL].[dbo].[Sku] a
  where exists(select 1 from [SRIRRA50ED8483SQL].[dbo].[Sku] b where a.InvoiceNumber = b.InvoiceNumber and QtySold >= 12)
      and not exists(select 1 from [SRIRRA50ED8483SQL].[dbo].[Sku] b where a.InvoiceNumber = b.InvoiceNumber and b.SKU = 'QUIK')
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question