當前位置:首頁 » 編程語言 » sql中數據條目合並自動運行
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

sql中數據條目合並自動運行

發布時間: 2022-06-26 13:40:36

『壹』 sql怎麼把多條數據合並成一條數據

把多條數據合並成一條數據的代碼:

select sum(case when wgrp_id='2' then quota end) w2, sum(case when wgrp_id='3' ;then quota end) w3, mm;
from table;
group by mm。

SQL語言,是結構化查詢語言(Structured Query Language)的簡稱。SQL語言是一種資料庫查詢和程序設計語言,用於存取數據以及查詢、更新和管理關系資料庫系統;同時也是資料庫腳本文件的擴展名。

SQL語言是高級的非過程化編程語言,允許用戶在高層數據結構上工作。它不要求用戶指定對數據的存放方法,也不需要用戶了解具體的數據存放方式,所以具有完全不同底層結構的不同資料庫系統可以使用相同的結構化查詢語言作為數據輸入與管理的介面。SQL語言語句可以嵌套,這使他具有極大的靈活性和強大的功能。

應用信息:

結構化查詢語言SQL(STRUCTURED QUERY LANGUAGE)是最重要的關系資料庫操作語言,並且它的影響已經超出資料庫領域,得到其他領域的重視和採用,如人工智慧領域的數據檢索,第四代軟體開發工具中嵌入SQL的語言等。

支持標准:

SQL 是1986年10 月由美國國家標准局(ANSI)通過的資料庫語言美國標准,接著,國際標准化組織(ISO)頒布了SQL正式國際標准。1989年4月,ISO提出了具有完整性特徵的SQL89標准,1992年11月又公布了SQL92標准,在此標准中,把資料庫分為三個級別:基本集、標准集和完全集。

『貳』 sql統計問題,如果將如下sql合並成一條執行

selectf_date,
count(distinctuser_ip)asdayMount
fromm_webservice
wheref_date>='20170208'
andf_date<'20170215'
groupbyf_date
unionall
select'總數',count(distinctuser_ip)asweekMount
fromm_webservice
wheref_date>='20170208'
andf_date<'20170215';

『叄』 SQL同一列同一行中的數據合並

----寫了個函數如下:
GO
CREATE FUNCTION funTest(@Value nvarchar(1000))
RETURNS nvarchar(1000)
AS
BEGIN
DECLARE @rtn nvarchar(1000)

DECLARE @temp table(a varchar(1000))
declare @i int, @StrSeprate nvarchar(10)
set @strSeprate =';'
set @Value=rtrim(ltrim(@Value))
set @i=charindex(@StrSeprate,@Value)
while @i>=1
begin
insert @temp values(left(@Value,@i-1))
set @Value=substring(@Value,@i+1,len(@Value)-@i)
set @i=charindex(@StrSeprate,@Value)
end
if @Value<>''
insert @temp values(@Value)

declare @cur cursor,@a nvarchar(1000)
set @cur = cursor for
select a from @temp group by a ;
set @rtn='';
open @cur;
fetch next from @cur into @a;
while @@FETCH_STATUS =0
begin
if LEN(@rtn)>0 set @rtn = @rtn +';'
set @rtn =@rtn+@a
fetch next from @cur into @a;
end

RETURN @rtn

END

GO
--使用方法如下:
declare @V nvarchar(1000)
set @V = '5000000009;5000000009;5000000010;5000000011'

select dbo.funTest(@V)
-----------
5000000009;5000000010;5000000011
你可以select db.funTest(你的欄位) as 輸出 from 你的表。

『肆』 SQL語句 表內數據合並

distinct 在 select 後
select distinct * from data;

『伍』 SQL中如何合並資料庫

我認為最好找軟體供應商來做此項目服務,畢竟裡面的表什麼的不一定只是簡單的數據合並就可以的,

『陸』 SQL中怎麼把多查詢結果合並成一條數據

oralce 10g 函數 wm_concat

select k_n1,k_n2,k_n3,k_n4,wm_concat(k_n5) from k_t where k_n1=1 and k_n2=1 and k_n3=1 and k_n4=1

運行結果如下:
1 1 1 1 5,4,3

『柒』 sql 表數據合並

我這里創建2個測試表 aa 與 bb, 還特地造了些其他的欄位,用於模擬 樓主的 「有很多欄位」

1> select * from aa;
2> select * from bb;
3> go
a b c
----------- ----------- -----------
1010 5 1
1011 6 2
1012 7 3

(3 行受影響)
a b c d
----------- ----------- ----------- -----------
1011 6 4 7
1012 9 5 8
1013 8 6 9

(3 行受影響)

1> SELECT
2> isnull(aa.a, bb.a) AS a,
3> isnull(aa.b, bb.b) AS b,
4> isnull(aa.c, bb.c) AS 其他數據C,
5> bb.d AS 其他數據D
6> FROM
7> aa full join bb on (aa.a = bb.a AND aa.b = bb.b)
8> go
a b 其他數據C 其他數據D
----------- ----------- ----------- -----------
1010 5 1 NULL
1011 6 2 7
1012 7 3 NULL
1012 9 5 8
1013 8 6 9

(5 行受影響)

『捌』 sql中數據條目合並,自動運行,求平均值,if語句

decalre @RecordCount interger
declare @Date99 smalldatetime
declare @avg1 numeric(18,3)
declare @avg2 numeric(18,3)

if day(getdate())=1

begin
select @recordcount=count(*) from table1

if @recordcount >200
begin
select @avg1=avg(col1),@avg2=avg(col2) from table where id in (select top 100 ID from table1)
select @date99=date1 from table1 where id in (select top 1 id from table1 where id not in (select top 98 id from table1 order by id) order by id)

end

end

--比較蛋疼的要求

『玖』 SQL中如何按照條件合並多行的數據

寫一個函數,運行sql調用函數,不知道你資料庫欄位名只是設前兩個欄位為id1,id2,這是我的思路 在我的資料庫測試過好用

create function pmerg(@id1 int ,@id2 int)
returns varchar(8000)
as
begin
declare @s varchar(8000)
set @s=''
select @s=@s+';'+name from y where id1=@id1 and id2=@id2
set @s=right(@s,len(@s)-1)
return(@s)
End

上面是建立的函數,下面是要運行的sql
select distinct id1, id2, dbo.pmerg(id1,id2) from y