十年網(wǎng)站開發(fā)經(jīng)驗 + 多家企業(yè)客戶 + 靠譜的建站團隊
量身定制 + 運營維護+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
標準答案:

成武ssl適用于網(wǎng)站、小程序/APP、API接口等需要進行數(shù)據(jù)傳輸應用場景,ssl證書未來市場廣闊!成為創(chuàng)新互聯(lián)公司的ssl證書銷售渠道,可以享受市場價格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:18982081108(備注:SSL證書合作)期待與您的合作!
declare @ACount int
select @ACount=count(*) from 表 --計算總數(shù),避免放在大數(shù)據(jù)的select中影響效率
if @ACount0 --判斷是否有記錄,無記錄時@Acount為0,不能做除數(shù)
select 表.name,cast(count(*) as numeric(10,3))/cast(@ACount as numeric(10,3)) from 表 group by 表.name --做百分比時要避免直接用/,會整除的,就無法判斷%比例了。
else
select '表中無記錄,無法統(tǒng)計比例'
--小數(shù)點后保留三位,換算成%比,應該如12.5%的精確度,numeric(10,3)前面的10如果長度不夠可以根據(jù)需要修改
select 12/23 * 100 ||'%' from dual;
mysql 服務器支持 # 到該行結束、-- 到該行結束 以及 /* 行中間或多個行 */ 的注釋方格:
mysql SELECT 1+1; # 這個注釋直到該行結束
mysql SELECT 1+1; -- 這個注釋直到該行結束
mysql SELECT 1 /* 這是一個在行中間的注釋 */ + 1;
mysql SELECT 1+
/*
這是一個
多行注釋的形式
*/
1;
注意 -- (雙長劃) 注釋風格要求在兩個長劃后至少有一個空格!
盡管服務器理解剛才描述的注釋句法,但 MySQL 客戶端的語法分析在 /* ... */ 注釋方式上還有所限止:
單引號和雙引號被用來標志一個被引用字符串的開始,即使是在一個注釋中。如果注釋中的引號沒有另一個引號與之配對,那和語法分析程序就不會認為注釋結束。如果你以交互式運行 mysql,你會產(chǎn)生困惑,因為提示符從 mysql 變?yōu)?' 或 "。
一個分號被用于指出當前 SQL 語句的結束并且跟隨它的任何東西表示下一行的開始。
不論你是以交互式運行 mysql 還是將命令放在一個文件中,然后以 mysql some-file 告訴 mysql 讀取它的輸入,這個限制均存在。
select REALHANDLER, count(*) as 總數(shù), sum(case when status='RESOLVED' then 1 else 0 end)as 已解決,
sum(case when status!='RESOLVED' then 1 else 0 end)as 未解決,
sum(case when status='RESOLVED' then 1 else 0 end)+0.0001/count(*) as 完成率
from INCIDENT
group by REALHANDLER
)+0.0001試一下 因為返回的類型和sum(case when status='RESOLVED' then 1 else 0 end),count(*) 一樣
以A表為例子
先建立一個table0
create table_0
(n_date date,
sheng varchar2(20),
sale number
tongbi number);
create unique index table_0_U1 on table_0 (n_date,sheng);
create or replace package body pkg_b_tongji is
procedure sp_update_party_rating(p_sdate number, p_edate number) is
v_sdate date default to_date(p_sdate,'yyyymmdd');
v_edate date default to_date(p_edate,'yyyymmdd');
v_sqlUpd varchar2(3000);
v_sqlIns varchar2(3000);
begin
v_sqlIns := 'insert into table_0(n_date,sheng,sale)
values(:v1,:v2,:v3)';
v_sqlUpd := 'update table_0 t set sale = :v1
where n_date = :v2 and sheng = :v3';
for c1 in (select a.ndate,
a.sheng,
sum(sale) sale
from a
where ndate between v_sdate and v_edate
group by a.ndate,
a.sheng
)
loop
execute immediate v_sqlUpd using c1.sale;
if sql%rowcount=0 then --如果更新操作沒有執(zhí)行就執(zhí)行插入操作
execute immediate v_sqlIns using c1.n_date,c1.sheng,c1.sale;
end if;
end loop;
commit;
end sp_update_party_rating;
---更新同比
procedure sp_update_tongbi is
begin
for c2 in (
select n_date,
sheng,
sale,
nvl(sale,0) sale1
from table_0 a
left join
(select n_date,sheng,a.nvl(sale,0) sale
from table_0 a,
(select t.n_date,sheng
add_months(n_date,-1) n_date2
from table_0 t)
where a.sheng = b.sheng and a.n_date = b.n_date2)
)
loop
update table_0
set tongbi = sale/sale1
where n_date = c2.n_date and sheng = c2.sheng;
commit;
end loop;
end sp_update_tongbi;
end pkg_b_tongji;