sql - Pervasive PSQL GROUP BY Clause -


i have following following sql call make on pervasive v11 database. i'm looking work 1 line each item id.

select      inventory_history.item_id 'itemid',      rtrim(inventory_items.item_name) 'description',      if(rtrim(trx_type) = 'p',sum(change_quantity),'') 'qtychangep',      if(rtrim(trx_type) = 'p',sum(history_cost_01+history_cost_02+history_cost_03+history_cost_04+history_cost_05+history_cost_06+history_cost_07+history_cost_08+history_cost_09+history_cost_10+history_cost_11+history_cost_12),'') 'costchangep',      if(rtrim(trx_type) = 's',sum(change_quantity),'') 'qtychanges',      if(rtrim(trx_type) = 's',sum(history_cost_01+history_cost_02+history_cost_03+history_cost_04+history_cost_05+history_cost_06+history_cost_07+history_cost_08+history_cost_09+history_cost_10+history_cost_11+history_cost_12),'') 'costchanges',      if(rtrim(trx_type) = 'a',sum(change_quantity),'') 'qtychangea',      if(rtrim(trx_type) = 'a',sum(history_cost_01+history_cost_02+history_cost_03+history_cost_04+history_cost_05+history_cost_06+history_cost_07+history_cost_08+history_cost_09+history_cost_10+history_cost_11+history_cost_12),'') 'costchangea',      if(rtrim(trx_type) = 't',sum(change_quantity),'') 'qtychanget',      if(rtrim(trx_type) = 't',sum(history_cost_01+history_cost_02+history_cost_03+history_cost_04+history_cost_05+history_cost_06+history_cost_07+history_cost_08+history_cost_09+history_cost_10+history_cost_11+history_cost_12),'') 'costchanget',      if(rtrim(inventory_categories.stocked_by_factor) = 'ft',inventory_items.unit_weight,'') 'wtperft'       inventory_history  inner join      inventory_items on inventory_history.item_id = inventory_items.item_id  inner join      inventory_categories on inventory_items.category_id = inventory_categories.category_id       trx_date>'20170731'  group      inventory_history.item_id, inventory_items.item_name, trx_type, stocked_by_factor, unit_weight; 

as now, receive error database if don't have trx_type, stocked_by_factor, or unit_weight listed in group clause.

removing fields results in error:

column invalid. must group column: trx_type in select list.

here sample results of complete sql call:

itemid                      description                                                                                                            qtychangep                                                                    costchangep                                                                     qtychanges                                                                    costchanges                                                                     qtychangea                                                                    costchangea                                                                     qtychanget                                                                    costchanget          wtperft =========================   ==================================================   ============================================================================   ============================================================================   ============================================================================   ============================================================================   ============================================================================   ============================================================================   ============================================================================   ============================================================================   ============== 1100sm19050t2c1             1100-h19 lami shim .050"  type 2, class 1                                                                                 58.2400                                                                         890.00                                                                         0.0000                                                                           0.00                                                                         0.0000                                                                           0.00                                                                         0.0000                                                                           0.00         0.000000 1100sm19050t2c1             1100-h19 lami shim .050"  type 2, class 1                                                                                  0.0000                                                                           0.00                                                                        58.2400                                                                         890.00                                                                         0.0000                                                                           0.00                                                                         0.0000                                                                           0.00         0.000000 1100sm19085t2c1             1100-h19 lami shim .085"  type 2, class 1                                                                                  0.0000                                                                           0.00                                                                         0.0000                                                                           0.00                                                                         0.0000                                                                           0.00                                                                         0.0000                                                                           0.00         0.000000 1100sm19085t2c1             1100-h19 lami shim .085"  type 2, class 1                                                                                 19.8080                                                                         208.00                                                                         0.0000                                                                           0.00                                                                         0.0000                                                                           0.00                                                                         0.0000                                                                           0.00         0.000000 1100sm19085t2c1             1100-h19 lami shim .085"  type 2, class 1                                                                                  0.0000                                                                           0.00                                                                        19.8080                                                                         208.00                                                                         0.0000                                                                           0.00                                                                         0.0000                                                                           0.00         0.000000 

any appreciated. thanks!!

the condition should argument sum():

sum(if(rtrim(trx_type) = 'p', change_quantity), 0) qtychangep,  

normally, written using case:

sum(case when rtrim(trx_type) = 'p' change_quantity else 0 end) qtychangep,  

Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -