Форум OlegON > Программы и оборудование для автоматизации торговли > Системы автоматизации торговли > Супермаг Плюс (Супермаг 2000)

Помогите с запросом к Супермажной базе : Супермаг Плюс (Супермаг 2000)

19.04.2024 3:50


22.05.2009 12:30
Mihon
 
Код:
select 
c.article, c.shortname, m.abbrev, 
round(g.quantity,2) goods, round(nvl(sl.salerate,0),2) ssreal
from 
supermag.smcard c, supermag.sameasurement m, 
supermag.smgoods g, supermag.smcardassort ca, 
supermag.sacardassort aca, supermag.SMSTOCKLEVELS sl
where
c.article=ca.article and c.idmeasurement=m.id and 
c.article=g.article and ca.idassort=aca.id and 
c.article=sl.article and g.storeloc=sl.storeloc and
aca.tree='дерево' and g.storeloc=ид_мх
order by c.shortname
Проблема в том что для некоторых товаров почему-то в SMSTOCKLEVELS нету вообще ничего. Видимо, недавно созданные карточки. Из-за этого общий запрос по этому товару тоже ничего не возвращает.

Как же сделать так, чтобы в этом случае запрос возвращал строчку о таком товаре?
Я что-то слышал про inner join, outer join, (+) и (-) и всякое такое, знаю что туда надо копать, но сколько ни пытался - не смог разобраться с этим... мозгов не хватает видать...
Знатоки SQL, подскажите, пожалуйста, как правильно оформить запросик...
22.05.2009 12:35
Mtirt
 
Так попробуй.
Код:
select 
c.article, c.shortname, m.abbrev, 
round(g.quantity,2) goods, round(nvl(sl.salerate,0),2) ssreal
from 
supermag.smcard c, supermag.sameasurement m, 
supermag.smgoods g, supermag.smcardassort ca, 
supermag.sacardassort aca, supermag.SMSTOCKLEVELS sl
where
c.article=ca.article and c.idmeasurement=m.id and 
c.article=g.article and ca.idassort=aca.id and 
g.article=sl.article(+) and g.storeloc=sl.storeloc(+) and
aca.tree='дерево' and g.storeloc=ид_мх
order by c.shortname
22.05.2009 12:40
Mihon
 
Цитата:
Mtirt Так попробуй.
Код:
select 
c.article, c.shortname, m.abbrev, 
round(g.quantity,2) goods, round(nvl(sl.salerate,0),2) ssreal
from 
supermag.smcard c, supermag.sameasurement m, 
supermag.smgoods g, supermag.smcardassort ca, 
supermag.sacardassort aca, supermag.SMSTOCKLEVELS sl
where
c.article=ca.article and c.idmeasurement=m.id and 
c.article=g.article and ca.idassort=aca.id and 
g.article=sl.article(+) and g.storeloc=sl.storeloc(+) and
aca.tree='дерево' and g.storeloc=ид_мх
order by c.shortname
Аааааааааа! Ура!
Спасибо огромное!
блин, что б я без Вас делал...
04.06.2009 15:03
Pall_V
 
А мне необходимо вытащить только одного самого последнего поставщика товара, сделал на основе SVLastArtSupply
Код:
select y.art art, z.suppl suppl, y.loc locate
  from (select z.art art, z.locationto loc, max(z.rd) ra
          from (select MAX(rownum) rd,
                       X.Supplier,
                       X.Art,
                       X.SupplDate,
                       X.DocID,
                       (select LocationTo
                          from SMDocuments D
                         where D.DocType = 'WI'
                           and D.ID = X.DocID) LocationTo
                  from (select Supplier,
                               Art,
                               substr(max_data, 9) DocID,
                               to_date(substr(max_data, 1, 8), 'YYYYMMDD') SupplDate
                          from (select D.ClientIndex as Supplier,
                                       S.Article as Art,
                                       max(to_char(D.Createdat, 'YYYYMMDD') || D.id) max_data
                                  from SMSpec S, SMDocuments D
                                 where D.DocType = S.DocType
                                   and S.DocID = D.ID
                                   and S.DocType = 'WI'
                                   and D.DocState = 3
                                   and D.OpCode = 0
                                 group by D.ClientIndex, S.Article)
                         order by substr(max_data, 9),
                                  to_date(substr(max_data, 1, 8), 'YYYYMMDD') desc) X,
                       SMSpec S
                 where S.DocType = 'WI'
                   and S.DocID = X.DocID
                   and S.Article = X.Art
                 group by X.Supplier, X.Art, X.SupplDate, X.DocID
                 order by X.Art, X.SupplDate) z
         group by z.art, z.locationto
         order by z.art, z.locationto, max(z.rd)) y,
       (select MAX(rownum) rd,
               X.Supplier suppl,
               X.Art,
               X.SupplDate,
               X.DocID DID
          from (select Supplier,
                       Art,
                       substr(max_data, 9) DocID,
                       to_date(substr(max_data, 1, 8), 'YYYYMMDD') SupplDate
                  from (select D.ClientIndex as Supplier,
                               S.Article as Art,
                               max(to_char(D.Createdat, 'YYYYMMDD') || D.id) max_data
                          from SMSpec S, SMDocuments D
                         where D.DocType = S.DocType
                           and S.DocID = D.ID
                           and S.DocType = 'WI'
                           and D.DocState = 3
                           and D.OpCode = 0
                         group by D.ClientIndex, S.Article)
                 order by substr(max_data, 9),
                          to_date(substr(max_data, 1, 8), 'YYYYMMDD') desc) X,
               SMSpec S
         where S.DocType = 'WI'
           and S.DocID = X.DocID
           and S.Article = X.Art
         group by X.Supplier, X.Art, X.SupplDate, X.DocID
         order by X.Art, X.SupplDate) z
 where y.ra = z.rd
Только он работает очень долго (17-20 мин), может кто подскажет как ускорить?
04.06.2009 16:11
MirProd
 
Цитата:
Pall_V А мне необходимо вытащить только одного самого последнего поставщика товара
Код:
select t.article, t.locationto, t.lcl, cl.name
from (select article, locationto, max(clientindex) keep (dense_rank last order by createdat) lcl
	from smspec, smdocuments
	where id=docid
	and opcode=0
	and docstate=3
	and trunc(createdat)>=sysdate-120
	group by article, locationto) t, smclientinfo cl
where t.lcl=cl.id
order by t.article
Для быстродействия за последние 120 дней.
05.06.2009 13:46
Pall_V
 
Цитата:
MirProd
Код:
select t.article, t.locationto, t.lcl, cl.name
from (select article, locationto, max(clientindex) keep (dense_rank last order by createdat) lcl
	from smspec, smdocuments
	where id=docid
	and opcode=0
	and docstate=3
	and trunc(createdat)>=sysdate-120
	group by article, locationto) t, smclientinfo cl
where t.lcl=cl.id
order by t.article
Для быстродействия за последние 120 дней.
Спасибо, получилось, про dense_rank last order by createdat я не знал, пошел читать литературу...*125
Часовой пояс GMT +3, время: 03:50.

Форум на базе vBulletin®
Copyright © Jelsoft Enterprises Ltd.
В случае заимствования информации гипертекстовая индексируемая ссылка на Форум обязательна.