SQL select multiple lines based on multiple values but one criteria -


this first question on forum takes long fix issue.

explanation:

in sample if cost code "c" in range other lines should included in list.

invoice|vehicle|job_date|costcode|total| 2017001|unit001|01012017|      |  100| - ok 2017001|unit001|01012017|   c    |  100| - ok 2017001|unit002|01012017|      |  100| - false 2017001|unit002|01012017|   b    |  100| - false 2017001|unit003|01012017|      |  100| - ok 2017001|unit003|01012017|   c    |  100| - ok 2017022|unit001|22012017|      |  100| - ok 2017022|unit001|22012017|   c    |  100| - ok 2017022|unit004|22012017|      |  100| - false 2017022|unit004|22012017|   b    |  100| - false  expected result: invoice|vehicle|job_date|costcode|total| 2017001|unit001|01012017|      |  100| 2017001|unit001|01012017|   c    |  100| 2017001|unit003|01012017|      |  100| 2017001|unit003|01012017|   c    |  100| 2017022|unit001|22012017|      |  100| 2017022|unit001|22012017|   c    |  100| 

the unique value combination between "invoice, vehicle, jobdate" if line has "invoice, vehicle, jobdate , costcode = "c"" should show lines "invoice, vehicle, jobdate" equal line including costcode "c"

i hope explanation little bit better previous.

table name is:

select invoice_key_fw,vehicle_id_fw,job_date_fw,costcode_fw,total_nett_fw, purchase_invoice_details_fw  

costs unit divided costs code , performed on day on unit (per invoice). receive bulk invoices unit can on invoice twice (but never on same day). if cost code (in case "c") on invoice invoice lines same jobdate , same vehicle id should included in expected result.

i have no sql editor me, should work.

select invoice_number, unitnumber, date, cost_code, costs  invoice_details unit_number in (select distinct unit_number                        invoice_details                       cost_code = 'c') 

i think there better way, should try before.


Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -