x

How to display only few columns of a table based on the data

Consider the table below

 Name partno.  sch_date    WO#   owed panels  
  aa   1234     08/22/2017  121   22    26  
  aa   1234     08/22/2017  222   22    27  
  aa   1234     08/22/2017  242   22    27  
  aa   1234     08/29/2017  152   20    24  
  aa   1234     08/29/2017  167   20    24  
  aa   1234     08/29/2017  202   20    26  

 

Is it possible to display the data in such way that when i read through the data if the first partno. in the table has the number of panels greater than owed, then i don't won't to dispaly the other partno. schedule on the same date(sch_date).

Expected Result

  Name partno.  sch_date    WO#   owed panels  
    aa   1234     08/22/2017  121   22    26  
    aa   1234     08/29/2017  152   20    24
more ▼

asked Aug 11 at 07:28 AM in Default

avatar image

Saaharjit
1

@Saaharjit To answer your question literally: yes, it is possible. The question appears to be a homework question, and if so then please show what you have tried so far. Also, the question definition is ambiguous as it is not clear exactly which records needs to be shown. For example, for partno / sch_date combination of 1234 / 08/22/2017 there are 3 records where panels > owed. In this case, which one of the 3 records should be included in the result? The answer that the first record should be included is not sufficient as there is no way of knowing (from question definition) which one of the record is considered first. Please clarify.

Aug 11 at 12:40 PM Oleg
(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first

You can always write a view on top of your table. but need to define the business logic first, how are you defining the first row, how grouping is done. based on these logic either create a view or stored procedure.

more ▼

answered Aug 21 at 07:45 PM

avatar image

Avi1
0

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x2175

asked: Aug 11 at 07:28 AM

Seen: 26 times

Last Updated: Aug 21 at 07:45 PM

Copyright 2017 Redgate Software. Privacy Policy