|
|
|
-
|
|||
|---|---|---|---|
|
#18+
Как получить произведение значений столбца, что-то типа select id, Произведение(value) from table group by id ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 07.06.2002, 19:50:55 |
|
||
|
-
|
|||
|---|---|---|---|
|
#18+
лобовое решение не претендую на оригинальность: речь идёт о SQL Server 2000 --создаю таблицу для теста if exists(select * from sysobjects where name='Tbl') drop table Tbl go create table Tbl( id int not null, value int not null) go -- тестовые данные insert into Tbl([id],[value]) values(9,8) insert into Tbl([id],[value]) values(9,3) insert into Tbl([id],[value]) values(8,3) insert into Tbl([id],[value]) values(9,6) insert into Tbl([id],[value]) values(9,3) insert into Tbl([id],[value]) values(5,9) insert into Tbl([id],[value]) values(5,3) insert into Tbl([id],[value]) values(4,8) insert into Tbl([id],[value]) values(3,3) insert into Tbl([id],[value]) values(3,9) insert into Tbl([id],[value]) values(7,7) insert into Tbl([id],[value]) values(6,5) insert into Tbl([id],[value]) values(6,7) insert into Tbl([id],[value]) values(6,9) insert into Tbl([id],[value]) values(8,6) insert into Tbl([id],[value]) values(6,7) insert into Tbl([id],[value]) values(2,4) insert into Tbl([id],[value]) values(7,7) insert into Tbl([id],[value]) values(7,3) go if exists(select * from sysobjects where name='Mul') drop function Mul go -- функция для получения произведения значений с заданным id create function Mul(@id int) returns int as begin declare @res int declare @id_fetch int select @res=1 declare tlb_cursor cursor FORWARD_ONLY READ_ONLY for select [value] from Tbl where id=@id open tlb_cursor fetch next from tlb_cursor into @id while @@FETCH_STATUS=0 begin select @res=@res*@id fetch next from tlb_cursor into @id end close tlb_cursor deallocate tlb_cursor return (@res) end go -- проверяем, вуаля :) select distinct [id], dbo.Mul([id]) from Tbl ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 08.06.2002, 21:51:51 |
|
||
|
-
|
|||
|---|---|---|---|
|
#18+
create table #t (col1 int identity, col2 decimal(18,4)) insert into #t(col2)values(13.26) insert into #t(col2)values(14.56) insert into #t(col2)values(15.22) insert into #t(col2)values(17.24) insert into #t(col2)values(13.33) SELECT POWER(10.0000,SUM(LOG10(col2))) as col3 FROM #t WHERE col1<=5 ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 10.06.2002, 00:28:10 |
|
||
|
-
|
|||
|---|---|---|---|
|
#18+
2Denis.R: USE tempdb GO CREATE TABLE DEMO (a int, b int) GO SET NOCOUNT ON declare @i int SET @i = 0 WHILE @i<10000 begin insert into DEMO VALUES (@i % 1000, 100*RAND()) SET @i = @i + 1 end GO SELECT a, POWER(10.0000, SUM(LOG10(B))) FROM DEMO GROUP BY a GO :( ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 10.06.2002, 07:45:40 |
|
||
|
|

start [/forum/topic.php?fid=46&msg=32032206&tid=1822423]: |
0ms |
get settings: |
11ms |
get forum list: |
13ms |
check forum access: |
2ms |
check topic access: |
2ms |
track hit: |
22ms |
get topic data: |
8ms |
get forum data: |
2ms |
get page messages: |
41ms |
get tp. blocked users: |
1ms |
| others: | 241ms |
| total: | 343ms |

| 0 / 0 |
