Postgres - Rozbijanie tablic

Odpowiedz Nowy wątek
2007-01-14 13:17

Rejestracja: 17 lat temu

Ostatnio: 4 lata temu

0

Mam następującą przykładową tabelę:

CREATE TABLE tab1(
 tab1id serial,
 array1 integer[],
)

I chodzi o to by zrobić z niej relację typu:

CREATE TABLE tab2(
 tab2id bigserial,
 tab1id integer,
 array1elem integer,
)

W taki sposób że w tab2 w poszczególnych krotkach są wszystkie elementy tablicy array1 i odpowiadające im klucze tab1id.

Tzn jak zrobić zapytanie select które to wykona??


<font color="darkblue"><font size="5">セボ</span>
Java PHP SQL
MatLab C# C++ Prolog SIOD</span>
<font size="1">Dziwne jest to, że na większość zadanych tu pytań sam sobię odpowiadam :]</span>

Pozostało 580 znaków

2007-01-15 07:00

Rejestracja: 17 lat temu

Ostatnio: 4 lata temu

0

Muszę się pochwalić, że poradziłem sobie z problemem metodą na Jana ;]
tzn:

select u.* from (
select
 invoice.number,
 invoice.item[1]as item,
 invoice.quantity[1] as quantity,
 invoice.issue_date,
 invoice.id as customerID,
 CASE
  WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'')OR(invoice.first<>'')OR(invoice.last<>'') THEN
   CASE
    WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'') THEN invoice.co_name1||' '||invoice.co_name2
    ELSE invoice.first||' '||invoice.last
   END
  ELSE 'Anonimowy'
 END as customerName,
 invoice.code as customerPost,
 invoice.city as customerCity,
 invoice.country as customerCountry,
 invoice.recipient,
 invoice.changed_by as employeeID,
 invoice.gross_value as gross,
 invoice.paid,
 invoice.unit[1] as unit,
 invoice.price[1] as price,
 invoice.vat[1] as vat,
 invoice.pkwiu[1] as pkwiu,
 invoice.precision[1] as precision,
 invoice.taric[1] as taric
from invoice where (invoice.item[1] is not null)
union all
select
 invoice.number,
 invoice.item[2]as item,
 invoice.quantity[2] as quantity,
 invoice.issue_date,
 invoice.id as customerID,
 CASE
  WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'')OR(invoice.first<>'')OR(invoice.last<>'') THEN
   CASE
    WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'') THEN invoice.co_name1||' '||invoice.co_name2
    ELSE invoice.first||' '||invoice.last
   END
  ELSE 'Anonimowy'
 END as customerName,
 invoice.code as customerPost,
 invoice.city as customerCity,
 invoice.country as customerCountry,
 invoice.recipient,
 invoice.changed_by as employeeID,
 invoice.gross_value as gross,
 invoice.paid,
 invoice.unit[2] as unit,
 invoice.price[2] as price,
 invoice.vat[2] as vat,
 invoice.pkwiu[2] as pkwiu,
 invoice.precision[2] as precision,
 invoice.taric[2] as taric
from invoice where (invoice.item[2] is not null)
union all
select
 invoice.number,
 invoice.item[3]as item,
 invoice.quantity[3] as quantity,
 invoice.issue_date,
 invoice.id as customerID,
 CASE
  WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'')OR(invoice.first<>'')OR(invoice.last<>'') THEN
   CASE
    WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'') THEN invoice.co_name1||' '||invoice.co_name2
    ELSE invoice.first||' '||invoice.last
   END
  ELSE 'Anonimowy'
 END as customerName,
 invoice.code as customerPost,
 invoice.city as customerCity,
 invoice.country as customerCountry,
 invoice.recipient,
 invoice.changed_by as employeeID,
 invoice.gross_value as gross,
 invoice.paid,
 invoice.unit[3] as unit,
 invoice.price[3] as price,
 invoice.vat[3] as vat,
 invoice.pkwiu[3] as pkwiu,
 invoice.precision[3] as precision,
 invoice.taric[3] as taric
from invoice where (invoice.item[3] is not null)
union all
select
 invoice.number,
 invoice.item[4]as item,
 invoice.quantity[4] as quantity,
 invoice.issue_date,
 invoice.id as customerID,
 CASE
  WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'')OR(invoice.first<>'')OR(invoice.last<>'') THEN
   CASE
    WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'') THEN invoice.co_name1||' '||invoice.co_name2
    ELSE invoice.first||' '||invoice.last
   END
  ELSE 'Anonimowy'
 END as customerName,
 invoice.code as customerPost,
 invoice.city as customerCity,
 invoice.country as customerCountry,
 invoice.recipient,
 invoice.changed_by as employeeID,
 invoice.gross_value as gross,
 invoice.paid,
 invoice.unit[4] as unit,
 invoice.price[4] as price,
 invoice.vat[4] as vat,
 invoice.pkwiu[4] as pkwiu,
 invoice.precision[4] as precision,
 invoice.taric[4] as taric
from invoice where (invoice.item[4] is not null)
union all
select
 invoice.number,
 invoice.item[5]as item,
 invoice.quantity[5] as quantity,
 invoice.issue_date,
 invoice.id as customerID,
 CASE
  WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'')OR(invoice.first<>'')OR(invoice.last<>'') THEN
   CASE
    WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'') THEN invoice.co_name1||' '||invoice.co_name2
    ELSE invoice.first||' '||invoice.last
   END
  ELSE 'Anonimowy'
 END as customerName,
 invoice.code as customerPost,
 invoice.city as customerCity,
 invoice.country as customerCountry,
 invoice.recipient,
 invoice.changed_by as employeeID,
 invoice.gross_value as gross,
 invoice.paid,
 invoice.unit[5] as unit,
 invoice.price[5] as price,
 invoice.vat[5] as vat,
 invoice.pkwiu[5] as pkwiu,
 invoice.precision[5] as precision,
 invoice.taric[5] as taric
from invoice where (invoice.item[5] is not null)
union all
select
 invoice.number,
 invoice.item[6]as item,
 invoice.quantity[6] as quantity,
 invoice.issue_date,
 invoice.id as customerID,
 CASE
  WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'')OR(invoice.first<>'')OR(invoice.last<>'') THEN
   CASE
    WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'') THEN invoice.co_name1||' '||invoice.co_name2
    ELSE invoice.first||' '||invoice.last
   END
  ELSE 'Anonimowy'
 END as customerName,
 invoice.code as customerPost,
 invoice.city as customerCity,
 invoice.country as customerCountry,
 invoice.recipient,
 invoice.changed_by as employeeID,
 invoice.gross_value as gross,
 invoice.paid,
 invoice.unit[6] as unit,
 invoice.price[6] as price,
 invoice.vat[6] as vat,
 invoice.pkwiu[6] as pkwiu,
 invoice.precision[6] as precision,
 invoice.taric[6] as taric
from invoice where (invoice.item[6] is not null)
union all
select
 invoice.number,
 invoice.item[7]as item,
 invoice.quantity[7] as quantity,
 invoice.issue_date,
 invoice.id as customerID,
 CASE
  WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'')OR(invoice.first<>'')OR(invoice.last<>'') THEN
   CASE
    WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'') THEN invoice.co_name1||' '||invoice.co_name2
    ELSE invoice.first||' '||invoice.last
   END
  ELSE 'Anonimowy'
 END as customerName,
 invoice.code as customerPost,
 invoice.city as customerCity,
 invoice.country as customerCountry,
 invoice.recipient,
 invoice.changed_by as employeeID,
 invoice.gross_value as gross,
 invoice.paid,
 invoice.unit[7] as unit,
 invoice.price[7] as price,
 invoice.vat[7] as vat,
 invoice.pkwiu[7] as pkwiu,
 invoice.precision[7] as precision,
 invoice.taric[7] as taric
from invoice where (invoice.item[7] is not null)
union all
select
 invoice.number,
 invoice.item[8]as item,
 invoice.quantity[8] as quantity,
 invoice.issue_date,
 invoice.id as customerID,
 CASE
  WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'')OR(invoice.first<>'')OR(invoice.last<>'') THEN
   CASE
    WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'') THEN invoice.co_name1||' '||invoice.co_name2
    ELSE invoice.first||' '||invoice.last
   END
  ELSE 'Anonimowy'
 END as customerName,
 invoice.code as customerPost,
 invoice.city as customerCity,
 invoice.country as customerCountry,
 invoice.recipient,
 invoice.changed_by as employeeID,
 invoice.gross_value as gross,
 invoice.paid,
 invoice.unit[8] as unit,
 invoice.price[8] as price,
 invoice.vat[8] as vat,
 invoice.pkwiu[8] as pkwiu,
 invoice.precision[8] as precision,
 invoice.taric[8] as taric
from invoice where (invoice.item[8] is not null)
union all
select
 invoice.number,
 invoice.item[9]as item,
 invoice.quantity[9] as quantity,
 invoice.issue_date,
 invoice.id as customerID,
 CASE
  WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'')OR(invoice.first<>'')OR(invoice.last<>'') THEN
   CASE
    WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'') THEN invoice.co_name1||' '||invoice.co_name2
    ELSE invoice.first||' '||invoice.last
   END
  ELSE 'Anonimowy'
 END as customerName,
 invoice.code as customerPost,
 invoice.city as customerCity,
 invoice.country as customerCountry,
 invoice.recipient,
 invoice.changed_by as employeeID,
 invoice.gross_value as gross,
 invoice.paid,
 invoice.unit[9] as unit,
 invoice.price[9] as price,
 invoice.vat[9] as vat,
 invoice.pkwiu[9] as pkwiu,
 invoice.precision[9] as precision,
 invoice.taric[9] as taric
from invoice where (invoice.item[9] is not null)
union all
select
 invoice.number,
 invoice.item[10]as item,
 invoice.quantity[10] as quantity,
 invoice.issue_date,
 invoice.id as customerID,
 CASE
  WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'')OR(invoice.first<>'')OR(invoice.last<>'') THEN
   CASE
    WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'') THEN invoice.co_name1||' '||invoice.co_name2
    ELSE invoice.first||' '||invoice.last
   END
  ELSE 'Anonimowy'
 END as customerName,
 invoice.code as customerPost,
 invoice.city as customerCity,
 invoice.country as customerCountry,
 invoice.recipient,
 invoice.changed_by as employeeID,
 invoice.gross_value as gross,
 invoice.paid,
 invoice.unit[10] as unit,
 invoice.price[10] as price,
 invoice.vat[10] as vat,
 invoice.pkwiu[10] as pkwiu,
 invoice.precision[10] as precision,
 invoice.taric[10] as taric
from invoice where (invoice.item[10] is not null)
union all
select
 invoice.number,
 invoice.item[11]as item,
 invoice.quantity[11] as quantity,
 invoice.issue_date,
 invoice.id as customerID,
 CASE
  WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'')OR(invoice.first<>'')OR(invoice.last<>'') THEN
   CASE
    WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'') THEN invoice.co_name1||' '||invoice.co_name2
    ELSE invoice.first||' '||invoice.last
   END
  ELSE 'Anonimowy'
 END as customerName,
 invoice.code as customerPost,
 invoice.city as customerCity,
 invoice.country as customerCountry,
 invoice.recipient,
 invoice.changed_by as employeeID,
 invoice.gross_value as gross,
 invoice.paid,
 invoice.unit[11] as unit,
 invoice.price[11] as price,
 invoice.vat[11] as vat,
 invoice.pkwiu[11] as pkwiu,
 invoice.precision[11] as precision,
 invoice.taric[11] as taric
from invoice where (invoice.item[11] is not null)
union all
select
 invoice.number,
 invoice.item[12]as item,
 invoice.quantity[12] as quantity,
 invoice.issue_date,
 invoice.id as customerID,
 CASE
  WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'')OR(invoice.first<>'')OR(invoice.last<>'') THEN
   CASE
    WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'') THEN invoice.co_name1||' '||invoice.co_name2
    ELSE invoice.first||' '||invoice.last
   END
  ELSE 'Anonimowy'
 END as customerName,
 invoice.code as customerPost,
 invoice.city as customerCity,
 invoice.country as customerCountry,
 invoice.recipient,
 invoice.changed_by as employeeID,
 invoice.gross_value as gross,
 invoice.paid,
 invoice.unit[12] as unit,
 invoice.price[12] as price,
 invoice.vat[12] as vat,
 invoice.pkwiu[12] as pkwiu,
 invoice.precision[12] as precision,
 invoice.taric[12] as taric
from invoice where (invoice.item[12] is not null)
union all
select
 invoice.number,
 invoice.item[13]as item,
 invoice.quantity[13] as quantity,
 invoice.issue_date,
 invoice.id as customerID,
 CASE
  WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'')OR(invoice.first<>'')OR(invoice.last<>'') THEN
   CASE
    WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'') THEN invoice.co_name1||' '||invoice.co_name2
    ELSE invoice.first||' '||invoice.last
   END
  ELSE 'Anonimowy'
 END as customerName,
 invoice.code as customerPost,
 invoice.city as customerCity,
 invoice.country as customerCountry,
 invoice.recipient,
 invoice.changed_by as employeeID,
 invoice.gross_value as gross,
 invoice.paid,
 invoice.unit[13] as unit,
 invoice.price[13] as price,
 invoice.vat[13] as vat,
 invoice.pkwiu[13] as pkwiu,
 invoice.precision[13] as precision,
 invoice.taric[13] as taric
from invoice where (invoice.item[13] is not null)
union all
select
 invoice.number,
 invoice.item[14]as item,
 invoice.quantity[14] as quantity,
 invoice.issue_date,
 invoice.id as customerID,
 CASE
  WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'')OR(invoice.first<>'')OR(invoice.last<>'') THEN
   CASE
    WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'') THEN invoice.co_name1||' '||invoice.co_name2
    ELSE invoice.first||' '||invoice.last
   END
  ELSE 'Anonimowy'
 END as customerName,
 invoice.code as customerPost,
 invoice.city as customerCity,
 invoice.country as customerCountry,
 invoice.recipient,
 invoice.changed_by as employeeID,
 invoice.gross_value as gross,
 invoice.paid,
 invoice.unit[14] as unit,
 invoice.price[14] as price,
 invoice.vat[14] as vat,
 invoice.pkwiu[14] as pkwiu,
 invoice.precision[14] as precision,
 invoice.taric[14] as taric
from invoice where (invoice.item[14] is not null)
union all
select
 invoice.number,
 invoice.item[15]as item,
 invoice.quantity[15] as quantity,
 invoice.issue_date,
 invoice.id as customerID,
 CASE
  WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'')OR(invoice.first<>'')OR(invoice.last<>'') THEN
   CASE
    WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'') THEN invoice.co_name1||' '||invoice.co_name2
    ELSE invoice.first||' '||invoice.last
   END
  ELSE 'Anonimowy'
 END as customerName,
 invoice.code as customerPost,
 invoice.city as customerCity,
 invoice.country as customerCountry,
 invoice.recipient,
 invoice.changed_by as employeeID,
 invoice.gross_value as gross,
 invoice.paid,
 invoice.unit[15] as unit,
 invoice.price[15] as price,
 invoice.vat[15] as vat,
 invoice.pkwiu[15] as pkwiu,
 invoice.precision[15] as precision,
 invoice.taric[15] as taric
from invoice where (invoice.item[15] is not null)
union all
select
 invoice.number,
 invoice.item[16]as item,
 invoice.quantity[16] as quantity,
 invoice.issue_date,
 invoice.id as customerID,
 CASE
  WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'')OR(invoice.first<>'')OR(invoice.last<>'') THEN
   CASE
    WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'') THEN invoice.co_name1||' '||invoice.co_name2
    ELSE invoice.first||' '||invoice.last
   END
  ELSE 'Anonimowy'
 END as customerName,
 invoice.code as customerPost,
 invoice.city as customerCity,
 invoice.country as customerCountry,
 invoice.recipient,
 invoice.changed_by as employeeID,
 invoice.gross_value as gross,
 invoice.paid,
 invoice.unit[16] as unit,
 invoice.price[16] as price,
 invoice.vat[16] as vat,
 invoice.pkwiu[16] as pkwiu,
 invoice.precision[16] as precision,
 invoice.taric[16] as taric
from invoice where (invoice.item[16] is not null)
union all
select
 invoice.number,
 invoice.item[17]as item,
 invoice.quantity[17] as quantity,
 invoice.issue_date,
 invoice.id as customerID,
 CASE
  WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'')OR(invoice.first<>'')OR(invoice.last<>'') THEN
   CASE
    WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'') THEN invoice.co_name1||' '||invoice.co_name2
    ELSE invoice.first||' '||invoice.last
   END
  ELSE 'Anonimowy'
 END as customerName,
 invoice.code as customerPost,
 invoice.city as customerCity,
 invoice.country as customerCountry,
 invoice.recipient,
 invoice.changed_by as employeeID,
 invoice.gross_value as gross,
 invoice.paid,
 invoice.unit[17] as unit,
 invoice.price[17] as price,
 invoice.vat[17] as vat,
 invoice.pkwiu[17] as pkwiu,
 invoice.precision[17] as precision,
 invoice.taric[17] as taric
from invoice where (invoice.item[17] is not null)
union all
select
 invoice.number,
 invoice.item[18]as item,
 invoice.quantity[18] as quantity,
 invoice.issue_date,
 invoice.id as customerID,
 CASE
  WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'')OR(invoice.first<>'')OR(invoice.last<>'') THEN
   CASE
    WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'') THEN invoice.co_name1||' '||invoice.co_name2
    ELSE invoice.first||' '||invoice.last
   END
  ELSE 'Anonimowy'
 END as customerName,
 invoice.code as customerPost,
 invoice.city as customerCity,
 invoice.country as customerCountry,
 invoice.recipient,
 invoice.changed_by as employeeID,
 invoice.gross_value as gross,
 invoice.paid,
 invoice.unit[18] as unit,
 invoice.price[18] as price,
 invoice.vat[18] as vat,
 invoice.pkwiu[18] as pkwiu,
 invoice.precision[18] as precision,
 invoice.taric[18] as taric
from invoice where (invoice.item[18] is not null)
union all
select
 invoice.number,
 invoice.item[19]as item,
 invoice.quantity[19] as quantity,
 invoice.issue_date,
 invoice.id as customerID,
 CASE
  WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'')OR(invoice.first<>'')OR(invoice.last<>'') THEN
   CASE
    WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'') THEN invoice.co_name1||' '||invoice.co_name2
    ELSE invoice.first||' '||invoice.last
   END
  ELSE 'Anonimowy'
 END as customerName,
 invoice.code as customerPost,
 invoice.city as customerCity,
 invoice.country as customerCountry,
 invoice.recipient,
 invoice.changed_by as employeeID,
 invoice.gross_value as gross,
 invoice.paid,
 invoice.unit[19] as unit,
 invoice.price[19] as price,
 invoice.vat[19] as vat,
 invoice.pkwiu[19] as pkwiu,
 invoice.precision[19] as precision,
 invoice.taric[19] as taric
from invoice where (invoice.item[19] is not null)
union all
select
 invoice.number,
 invoice.item[20]as item,
 invoice.quantity[20] as quantity,
 invoice.issue_date,
 invoice.id as customerID,
 CASE
  WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'')OR(invoice.first<>'')OR(invoice.last<>'') THEN
   CASE
    WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'') THEN invoice.co_name1||' '||invoice.co_name2
    ELSE invoice.first||' '||invoice.last
   END
  ELSE 'Anonimowy'
 END as customerName,
 invoice.code as customerPost,
 invoice.city as customerCity,
 invoice.country as customerCountry,
 invoice.recipient,
 invoice.changed_by as employeeID,
 invoice.gross_value as gross,
 invoice.paid,
 invoice.unit[20] as unit,
 invoice.price[20] as price,
 invoice.vat[20] as vat,
 invoice.pkwiu[20] as pkwiu,
 invoice.precision[20] as precision,
 invoice.taric[20] as taric
from invoice where (invoice.item[20] is not null)
union all
select
 invoice.number,
 invoice.item[21]as item,
 invoice.quantity[21] as quantity,
 invoice.issue_date,
 invoice.id as customerID,
 CASE
  WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'')OR(invoice.first<>'')OR(invoice.last<>'') THEN
   CASE
    WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'') THEN invoice.co_name1||' '||invoice.co_name2
    ELSE invoice.first||' '||invoice.last
   END
  ELSE 'Anonimowy'
 END as customerName,
 invoice.code as customerPost,
 invoice.city as customerCity,
 invoice.country as customerCountry,
 invoice.recipient,
 invoice.changed_by as employeeID,
 invoice.gross_value as gross,
 invoice.paid,
 invoice.unit[21] as unit,
 invoice.price[21] as price,
 invoice.vat[21] as vat,
 invoice.pkwiu[21] as pkwiu,
 invoice.precision[21] as precision,
 invoice.taric[21] as taric
from invoice where (invoice.item[21] is not null)
union all
select
 invoice.number,
 invoice.item[22]as item,
 invoice.quantity[22] as quantity,
 invoice.issue_date,
 invoice.id as customerID,
 CASE
  WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'')OR(invoice.first<>'')OR(invoice.last<>'') THEN
   CASE
    WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'') THEN invoice.co_name1||' '||invoice.co_name2
    ELSE invoice.first||' '||invoice.last
   END
  ELSE 'Anonimowy'
 END as customerName,
 invoice.code as customerPost,
 invoice.city as customerCity,
 invoice.country as customerCountry,
 invoice.recipient,
 invoice.changed_by as employeeID,
 invoice.gross_value as gross,
 invoice.paid,
 invoice.unit[22] as unit,
 invoice.price[22] as price,
 invoice.vat[22] as vat,
 invoice.pkwiu[22] as pkwiu,
 invoice.precision[22] as precision,
 invoice.taric[22] as taric
from invoice where (invoice.item[22] is not null)
union all
select
 invoice.number,
 invoice.item[23]as item,
 invoice.quantity[23] as quantity,
 invoice.issue_date,
 invoice.id as customerID,
 CASE
  WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'')OR(invoice.first<>'')OR(invoice.last<>'') THEN
   CASE
    WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'') THEN invoice.co_name1||' '||invoice.co_name2
    ELSE invoice.first||' '||invoice.last
   END
  ELSE 'Anonimowy'
 END as customerName,
 invoice.code as customerPost,
 invoice.city as customerCity,
 invoice.country as customerCountry,
 invoice.recipient,
 invoice.changed_by as employeeID,
 invoice.gross_value as gross,
 invoice.paid,
 invoice.unit[23] as unit,
 invoice.price[23] as price,
 invoice.vat[23] as vat,
 invoice.pkwiu[23] as pkwiu,
 invoice.precision[23] as precision,
 invoice.taric[23] as taric
from invoice where (invoice.item[23] is not null)
union all
select
 invoice.number,
 invoice.item[24]as item,
 invoice.quantity[24] as quantity,
 invoice.issue_date,
 invoice.id as customerID,
 CASE
  WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'')OR(invoice.first<>'')OR(invoice.last<>'') THEN
   CASE
    WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'') THEN invoice.co_name1||' '||invoice.co_name2
    ELSE invoice.first||' '||invoice.last
   END
  ELSE 'Anonimowy'
 END as customerName,
 invoice.code as customerPost,
 invoice.city as customerCity,
 invoice.country as customerCountry,
 invoice.recipient,
 invoice.changed_by as employeeID,
 invoice.gross_value as gross,
 invoice.paid,
 invoice.unit[24] as unit,
 invoice.price[24] as price,
 invoice.vat[24] as vat,
 invoice.pkwiu[24] as pkwiu,
 invoice.precision[24] as precision,
 invoice.taric[24] as taric
from invoice where (invoice.item[24] is not null)
union all
select
 invoice.number,
 invoice.item[25]as item,
 invoice.quantity[25] as quantity,
 invoice.issue_date,
 invoice.id as customerID,
 CASE
  WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'')OR(invoice.first<>'')OR(invoice.last<>'') THEN
   CASE
    WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'') THEN invoice.co_name1||' '||invoice.co_name2
    ELSE invoice.first||' '||invoice.last
   END
  ELSE 'Anonimowy'
 END as customerName,
 invoice.code as customerPost,
 invoice.city as customerCity,
 invoice.country as customerCountry,
 invoice.recipient,
 invoice.changed_by as employeeID,
 invoice.gross_value as gross,
 invoice.paid,
 invoice.unit[25] as unit,
 invoice.price[25] as price,
 invoice.vat[25] as vat,
 invoice.pkwiu[25] as pkwiu,
 invoice.precision[25] as precision,
 invoice.taric[25] as taric
from invoice where (invoice.item[25] is not null)
union all
select
 invoice.number,
 invoice.item[26]as item,
 invoice.quantity[26] as quantity,
 invoice.issue_date,
 invoice.id as customerID,
 CASE
  WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'')OR(invoice.first<>'')OR(invoice.last<>'') THEN
   CASE
    WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'') THEN invoice.co_name1||' '||invoice.co_name2
    ELSE invoice.first||' '||invoice.last
   END
  ELSE 'Anonimowy'
 END as customerName,
 invoice.code as customerPost,
 invoice.city as customerCity,
 invoice.country as customerCountry,
 invoice.recipient,
 invoice.changed_by as employeeID,
 invoice.gross_value as gross,
 invoice.paid,
 invoice.unit[26] as unit,
 invoice.price[26] as price,
 invoice.vat[26] as vat,
 invoice.pkwiu[26] as pkwiu,
 invoice.precision[26] as precision,
 invoice.taric[26] as taric
from invoice where (invoice.item[26] is not null)
union all
select
 invoice.number,
 invoice.item[27]as item,
 invoice.quantity[27] as quantity,
 invoice.issue_date,
 invoice.id as customerID,
 CASE
  WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'')OR(invoice.first<>'')OR(invoice.last<>'') THEN
   CASE
    WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'') THEN invoice.co_name1||' '||invoice.co_name2
    ELSE invoice.first||' '||invoice.last
   END
  ELSE 'Anonimowy'
 END as customerName,
 invoice.code as customerPost,
 invoice.city as customerCity,
 invoice.country as customerCountry,
 invoice.recipient,
 invoice.changed_by as employeeID,
 invoice.gross_value as gross,
 invoice.paid,
 invoice.unit[27] as unit,
 invoice.price[27] as price,
 invoice.vat[27] as vat,
 invoice.pkwiu[27] as pkwiu,
 invoice.precision[27] as precision,
 invoice.taric[27] as taric
from invoice where (invoice.item[27] is not null)
union all
select
 invoice.number,
 invoice.item[28]as item,
 invoice.quantity[28] as quantity,
 invoice.issue_date,
 invoice.id as customerID,
 CASE
  WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'')OR(invoice.first<>'')OR(invoice.last<>'') THEN
   CASE
    WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'') THEN invoice.co_name1||' '||invoice.co_name2
    ELSE invoice.first||' '||invoice.last
   END
  ELSE 'Anonimowy'
 END as customerName,
 invoice.code as customerPost,
 invoice.city as customerCity,
 invoice.country as customerCountry,
 invoice.recipient,
 invoice.changed_by as employeeID,
 invoice.gross_value as gross,
 invoice.paid,
 invoice.unit[28] as unit,
 invoice.price[28] as price,
 invoice.vat[28] as vat,
 invoice.pkwiu[28] as pkwiu,
 invoice.precision[28] as precision,
 invoice.taric[28] as taric
from invoice where (invoice.item[28] is not null)
union all
select
 invoice.number,
 invoice.item[29]as item,
 invoice.quantity[29] as quantity,
 invoice.issue_date,
 invoice.id as customerID,
 CASE
  WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'')OR(invoice.first<>'')OR(invoice.last<>'') THEN
   CASE
    WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'') THEN invoice.co_name1||' '||invoice.co_name2
    ELSE invoice.first||' '||invoice.last
   END
  ELSE 'Anonimowy'
 END as customerName,
 invoice.code as customerPost,
 invoice.city as customerCity,
 invoice.country as customerCountry,
 invoice.recipient,
 invoice.changed_by as employeeID,
 invoice.gross_value as gross,
 invoice.paid,
 invoice.unit[29] as unit,
 invoice.price[29] as price,
 invoice.vat[29] as vat,
 invoice.pkwiu[29] as pkwiu,
 invoice.precision[29] as precision,
 invoice.taric[29] as taric
from invoice where (invoice.item[29] is not null)
union all
select
 invoice.number,
 invoice.item[30]as item,
 invoice.quantity[30] as quantity,
 invoice.issue_date,
 invoice.id as customerID,
 CASE
  WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'')OR(invoice.first<>'')OR(invoice.last<>'') THEN
   CASE
    WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'') THEN invoice.co_name1||' '||invoice.co_name2
    ELSE invoice.first||' '||invoice.last
   END
  ELSE 'Anonimowy'
 END as customerName,
 invoice.code as customerPost,
 invoice.city as customerCity,
 invoice.country as customerCountry,
 invoice.recipient,
 invoice.changed_by as employeeID,
 invoice.gross_value as gross,
 invoice.paid,
 invoice.unit[30] as unit,
 invoice.price[30] as price,
 invoice.vat[30] as vat,
 invoice.pkwiu[30] as pkwiu,
 invoice.precision[30] as precision,
 invoice.taric[30] as taric
from invoice where (invoice.item[30] is not null)
union all
select
 invoice.number,
 invoice.item[31]as item,
 invoice.quantity[31] as quantity,
 invoice.issue_date,
 invoice.id as customerID,
 CASE
  WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'')OR(invoice.first<>'')OR(invoice.last<>'') THEN
   CASE
    WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'') THEN invoice.co_name1||' '||invoice.co_name2
    ELSE invoice.first||' '||invoice.last
   END
  ELSE 'Anonimowy'
 END as customerName,
 invoice.code as customerPost,
 invoice.city as customerCity,
 invoice.country as customerCountry,
 invoice.recipient,
 invoice.changed_by as employeeID,
 invoice.gross_value as gross,
 invoice.paid,
 invoice.unit[31] as unit,
 invoice.price[31] as price,
 invoice.vat[31] as vat,
 invoice.pkwiu[31] as pkwiu,
 invoice.precision[31] as precision,
 invoice.taric[31] as taric
from invoice where (invoice.item[31] is not null)
union all
select
 invoice.number,
 invoice.item[32]as item,
 invoice.quantity[32] as quantity,
 invoice.issue_date,
 invoice.id as customerID,
 CASE
  WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'')OR(invoice.first<>'')OR(invoice.last<>'') THEN
   CASE
    WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'') THEN invoice.co_name1||' '||invoice.co_name2
    ELSE invoice.first||' '||invoice.last
   END
  ELSE 'Anonimowy'
 END as customerName,
 invoice.code as customerPost,
 invoice.city as customerCity,
 invoice.country as customerCountry,
 invoice.recipient,
 invoice.changed_by as employeeID,
 invoice.gross_value as gross,
 invoice.paid,
 invoice.unit[32] as unit,
 invoice.price[32] as price,
 invoice.vat[32] as vat,
 invoice.pkwiu[32] as pkwiu,
 invoice.precision[32] as precision,
 invoice.taric[32] as taric
from invoice where (invoice.item[32] is not null)
union all
select
 invoice.number,
 invoice.item[33]as item,
 invoice.quantity[33] as quantity,
 invoice.issue_date,
 invoice.id as customerID,
 CASE
  WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'')OR(invoice.first<>'')OR(invoice.last<>'') THEN
   CASE
    WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'') THEN invoice.co_name1||' '||invoice.co_name2
    ELSE invoice.first||' '||invoice.last
   END
  ELSE 'Anonimowy'
 END as customerName,
 invoice.code as customerPost,
 invoice.city as customerCity,
 invoice.country as customerCountry,
 invoice.recipient,
 invoice.changed_by as employeeID,
 invoice.gross_value as gross,
 invoice.paid,
 invoice.unit[33] as unit,
 invoice.price[33] as price,
 invoice.vat[33] as vat,
 invoice.pkwiu[33] as pkwiu,
 invoice.precision[33] as precision,
 invoice.taric[33] as taric
from invoice where (invoice.item[33] is not null)
union all
select
 invoice.number,
 invoice.item[34]as item,
 invoice.quantity[34] as quantity,
 invoice.issue_date,
 invoice.id as customerID,
 CASE
  WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'')OR(invoice.first<>'')OR(invoice.last<>'') THEN
   CASE
    WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'') THEN invoice.co_name1||' '||invoice.co_name2
    ELSE invoice.first||' '||invoice.last
   END
  ELSE 'Anonimowy'
 END as customerName,
 invoice.code as customerPost,
 invoice.city as customerCity,
 invoice.country as customerCountry,
 invoice.recipient,
 invoice.changed_by as employeeID,
 invoice.gross_value as gross,
 invoice.paid,
 invoice.unit[34] as unit,
 invoice.price[34] as price,
 invoice.vat[34] as vat,
 invoice.pkwiu[34] as pkwiu,
 invoice.precision[34] as precision,
 invoice.taric[34] as taric
from invoice where (invoice.item[34] is not null)
union all
select
 invoice.number,
 invoice.item[35]as item,
 invoice.quantity[35] as quantity,
 invoice.issue_date,
 invoice.id as customerID,
 CASE
  WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'')OR(invoice.first<>'')OR(invoice.last<>'') THEN
   CASE
    WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'') THEN invoice.co_name1||' '||invoice.co_name2
    ELSE invoice.first||' '||invoice.last
   END
  ELSE 'Anonimowy'
 END as customerName,
 invoice.code as customerPost,
 invoice.city as customerCity,
 invoice.country as customerCountry,
 invoice.recipient,
 invoice.changed_by as employeeID,
 invoice.gross_value as gross,
 invoice.paid,
 invoice.unit[35] as unit,
 invoice.price[35] as price,
 invoice.vat[35] as vat,
 invoice.pkwiu[35] as pkwiu,
 invoice.precision[35] as precision,
 invoice.taric[35] as taric
from invoice where (invoice.item[35] is not null)
union all
select
 invoice.number,
 invoice.item[36]as item,
 invoice.quantity[36] as quantity,
 invoice.issue_date,
 invoice.id as customerID,
 CASE
  WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'')OR(invoice.first<>'')OR(invoice.last<>'') THEN
   CASE
    WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'') THEN invoice.co_name1||' '||invoice.co_name2
    ELSE invoice.first||' '||invoice.last
   END
  ELSE 'Anonimowy'
 END as customerName,
 invoice.code as customerPost,
 invoice.city as customerCity,
 invoice.country as customerCountry,
 invoice.recipient,
 invoice.changed_by as employeeID,
 invoice.gross_value as gross,
 invoice.paid,
 invoice.unit[36] as unit,
 invoice.price[36] as price,
 invoice.vat[36] as vat,
 invoice.pkwiu[36] as pkwiu,
 invoice.precision[36] as precision,
 invoice.taric[36] as taric
from invoice where (invoice.item[36] is not null)
union all
select
 invoice.number,
 invoice.item[37]as item,
 invoice.quantity[37] as quantity,
 invoice.issue_date,
 invoice.id as customerID,
 CASE
  WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'')OR(invoice.first<>'')OR(invoice.last<>'') THEN
   CASE
    WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'') THEN invoice.co_name1||' '||invoice.co_name2
    ELSE invoice.first||' '||invoice.last
   END
  ELSE 'Anonimowy'
 END as customerName,
 invoice.code as customerPost,
 invoice.city as customerCity,
 invoice.country as customerCountry,
 invoice.recipient,
 invoice.changed_by as employeeID,
 invoice.gross_value as gross,
 invoice.paid,
 invoice.unit[37] as unit,
 invoice.price[37] as price,
 invoice.vat[37] as vat,
 invoice.pkwiu[37] as pkwiu,
 invoice.precision[37] as precision,
 invoice.taric[37] as taric
from invoice where (invoice.item[37] is not null)
union all
select
 invoice.number,
 invoice.item[38]as item,
 invoice.quantity[38] as quantity,
 invoice.issue_date,
 invoice.id as customerID,
 CASE
  WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'')OR(invoice.first<>'')OR(invoice.last<>'') THEN
   CASE
    WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'') THEN invoice.co_name1||' '||invoice.co_name2
    ELSE invoice.first||' '||invoice.last
   END
  ELSE 'Anonimowy'
 END as customerName,
 invoice.code as customerPost,
 invoice.city as customerCity,
 invoice.country as customerCountry,
 invoice.recipient,
 invoice.changed_by as employeeID,
 invoice.gross_value as gross,
 invoice.paid,
 invoice.unit[38] as unit,
 invoice.price[38] as price,
 invoice.vat[38] as vat,
 invoice.pkwiu[38] as pkwiu,
 invoice.precision[38] as precision,
 invoice.taric[38] as taric
from invoice where (invoice.item[38] is not null)
union all
select
 invoice.number,
 invoice.item[39]as item,
 invoice.quantity[39] as quantity,
 invoice.issue_date,
 invoice.id as customerID,
 CASE
  WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'')OR(invoice.first<>'')OR(invoice.last<>'') THEN
   CASE
    WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'') THEN invoice.co_name1||' '||invoice.co_name2
    ELSE invoice.first||' '||invoice.last
   END
  ELSE 'Anonimowy'
 END as customerName,
 invoice.code as customerPost,
 invoice.city as customerCity,
 invoice.country as customerCountry,
 invoice.recipient,
 invoice.changed_by as employeeID,
 invoice.gross_value as gross,
 invoice.paid,
 invoice.unit[39] as unit,
 invoice.price[39] as price,
 invoice.vat[39] as vat,
 invoice.pkwiu[39] as pkwiu,
 invoice.precision[39] as precision,
 invoice.taric[39] as taric
from invoice where (invoice.item[39] is not null)
union all
select
 invoice.number,
 invoice.item[40]as item,
 invoice.quantity[40] as quantity,
 invoice.issue_date,
 invoice.id as customerID,
 CASE
  WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'')OR(invoice.first<>'')OR(invoice.last<>'') THEN
   CASE
    WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'') THEN invoice.co_name1||' '||invoice.co_name2
    ELSE invoice.first||' '||invoice.last
   END
  ELSE 'Anonimowy'
 END as customerName,
 invoice.code as customerPost,
 invoice.city as customerCity,
 invoice.country as customerCountry,
 invoice.recipient,
 invoice.changed_by as employeeID,
 invoice.gross_value as gross,
 invoice.paid,
 invoice.unit[40] as unit,
 invoice.price[40] as price,
 invoice.vat[40] as vat,
 invoice.pkwiu[40] as pkwiu,
 invoice.precision[40] as precision,
 invoice.taric[40] as taric
from invoice where (invoice.item[40] is not null)
union all
select
 invoice.number,
 invoice.item[41]as item,
 invoice.quantity[41] as quantity,
 invoice.issue_date,
 invoice.id as customerID,
 CASE
  WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'')OR(invoice.first<>'')OR(invoice.last<>'') THEN
   CASE
    WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'') THEN invoice.co_name1||' '||invoice.co_name2
    ELSE invoice.first||' '||invoice.last
   END
  ELSE 'Anonimowy'
 END as customerName,
 invoice.code as customerPost,
 invoice.city as customerCity,
 invoice.country as customerCountry,
 invoice.recipient,
 invoice.changed_by as employeeID,
 invoice.gross_value as gross,
 invoice.paid,
 invoice.unit[41] as unit,
 invoice.price[41] as price,
 invoice.vat[41] as vat,
 invoice.pkwiu[41] as pkwiu,
 invoice.precision[41] as precision,
 invoice.taric[41] as taric
from invoice where (invoice.item[41] is not null)
union all
select
 invoice.number,
 invoice.item[42]as item,
 invoice.quantity[42] as quantity,
 invoice.issue_date,
 invoice.id as customerID,
 CASE
  WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'')OR(invoice.first<>'')OR(invoice.last<>'') THEN
   CASE
    WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'') THEN invoice.co_name1||' '||invoice.co_name2
    ELSE invoice.first||' '||invoice.last
   END
  ELSE 'Anonimowy'
 END as customerName,
 invoice.code as customerPost,
 invoice.city as customerCity,
 invoice.country as customerCountry,
 invoice.recipient,
 invoice.changed_by as employeeID,
 invoice.gross_value as gross,
 invoice.paid,
 invoice.unit[42] as unit,
 invoice.price[42] as price,
 invoice.vat[42] as vat,
 invoice.pkwiu[42] as pkwiu,
 invoice.precision[42] as precision,
 invoice.taric[42] as taric
from invoice where (invoice.item[42] is not null)
union all
select
 invoice.number,
 invoice.item[43]as item,
 invoice.quantity[43] as quantity,
 invoice.issue_date,
 invoice.id as customerID,
 CASE
  WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'')OR(invoice.first<>'')OR(invoice.last<>'') THEN
   CASE
    WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'') THEN invoice.co_name1||' '||invoice.co_name2
    ELSE invoice.first||' '||invoice.last
   END
  ELSE 'Anonimowy'
 END as customerName,
 invoice.code as customerPost,
 invoice.city as customerCity,
 invoice.country as customerCountry,
 invoice.recipient,
 invoice.changed_by as employeeID,
 invoice.gross_value as gross,
 invoice.paid,
 invoice.unit[43] as unit,
 invoice.price[43] as price,
 invoice.vat[43] as vat,
 invoice.pkwiu[43] as pkwiu,
 invoice.precision[43] as precision,
 invoice.taric[43] as taric
from invoice where (invoice.item[43] is not null)
union all
select
 invoice.number,
 invoice.item[44]as item,
 invoice.quantity[44] as quantity,
 invoice.issue_date,
 invoice.id as customerID,
 CASE
  WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'')OR(invoice.first<>'')OR(invoice.last<>'') THEN
   CASE
    WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'') THEN invoice.co_name1||' '||invoice.co_name2
    ELSE invoice.first||' '||invoice.last
   END
  ELSE 'Anonimowy'
 END as customerName,
 invoice.code as customerPost,
 invoice.city as customerCity,
 invoice.country as customerCountry,
 invoice.recipient,
 invoice.changed_by as employeeID,
 invoice.gross_value as gross,
 invoice.paid,
 invoice.unit[44] as unit,
 invoice.price[44] as price,
 invoice.vat[44] as vat,
 invoice.pkwiu[44] as pkwiu,
 invoice.precision[44] as precision,
 invoice.taric[44] as taric
from invoice where (invoice.item[44] is not null)
union all
select
 invoice.number,
 invoice.item[45]as item,
 invoice.quantity[45] as quantity,
 invoice.issue_date,
 invoice.id as customerID,
 CASE
  WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'')OR(invoice.first<>'')OR(invoice.last<>'') THEN
   CASE
    WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'') THEN invoice.co_name1||' '||invoice.co_name2
    ELSE invoice.first||' '||invoice.last
   END
  ELSE 'Anonimowy'
 END as customerName,
 invoice.code as customerPost,
 invoice.city as customerCity,
 invoice.country as customerCountry,
 invoice.recipient,
 invoice.changed_by as employeeID,
 invoice.gross_value as gross,
 invoice.paid,
 invoice.unit[45] as unit,
 invoice.price[45] as price,
 invoice.vat[45] as vat,
 invoice.pkwiu[45] as pkwiu,
 invoice.precision[45] as precision,
 invoice.taric[45] as taric
from invoice where (invoice.item[45] is not null)
union all
select
 invoice.number,
 invoice.item[46]as item,
 invoice.quantity[46] as quantity,
 invoice.issue_date,
 invoice.id as customerID,
 CASE
  WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'')OR(invoice.first<>'')OR(invoice.last<>'') THEN
   CASE
    WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'') THEN invoice.co_name1||' '||invoice.co_name2
    ELSE invoice.first||' '||invoice.last
   END
  ELSE 'Anonimowy'
 END as customerName,
 invoice.code as customerPost,
 invoice.city as customerCity,
 invoice.country as customerCountry,
 invoice.recipient,
 invoice.changed_by as employeeID,
 invoice.gross_value as gross,
 invoice.paid,
 invoice.unit[46] as unit,
 invoice.price[46] as price,
 invoice.vat[46] as vat,
 invoice.pkwiu[46] as pkwiu,
 invoice.precision[46] as precision,
 invoice.taric[46] as taric
from invoice where (invoice.item[46] is not null)
union all
select
 invoice.number,
 invoice.item[47]as item,
 invoice.quantity[47] as quantity,
 invoice.issue_date,
 invoice.id as customerID,
 CASE
  WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'')OR(invoice.first<>'')OR(invoice.last<>'') THEN
   CASE
    WHEN (invoice.co_name1<>'')OR(invoice.co_name2<>'') THEN invoice.co_name1||' '||invoice.co_name2
    ELSE invoice.first||' '||invoice.last
   END
  ELSE 'Anonimowy'
 END as customerName,
 invoice.code as customerPost,
 invoice.city as customerCity,
 invoice.country as customerCountry,
 invoice.recipient,
 invoice.changed_by as employeeID,
 invoice.gross_value as gross,
 invoice.paid,
 invoice.unit[47] as unit,
 invoice.price[47] as price,
 invoice.vat[47] as vat,
 invoice.pkwiu[47] as pkwiu,
 invoice.precision[47] as precision,
 invoice.taric[47] as taric
from invoice where (invoice.item[47] is not null)
) as u order by u.number;

No ale chyba łatwo zauważyć, że to nie jest optymalne rozwiązanie [glowa]
Jakby ktoś wiedział jak to zwinąc w jakąś pętelkę lub coś takiego to niech da znać ;]


<font color="darkblue"><font size="5">セボ</span>
Java PHP SQL
MatLab C# C++ Prolog SIOD</span>
<font size="1">Dziwne jest to, że na większość zadanych tu pytań sam sobię odpowiadam :]</span>

Pozostało 580 znaków

2007-01-17 06:55

Rejestracja: 16 lat temu

Ostatnio: 7 lat temu

0

pomińmy milczeniem poprzedni post :)

napisz sobie stored proc

  1. robisz SELECT tab1id, array1 FROM tab1
  2. robisz pętle po wszystkich rekordach typu
    FOR i := array_lower(array1) TO array_upper(array1)
  3. i w tej pętli insert
    INSERT INTO tab2(tab1id, array1elem) VALUES(tab1id, array1[i])

no i poczytaj o tablicach http://www.postgresql.org/docs/8.0/interactive/arrays.html


- Ciemna druga strona jest.
- Nie marudź Yoda, tylko jedz tego tosta.
Google NIE GRYZIE!
Pomogłem - kliknij

Pozostało 580 znaków

Odpowiedz

1 użytkowników online, w tym zalogowanych: 0, gości: 1, botów: 0