『壹』 執行sql創建語句,如果執行成功resultset返回什麼東西
resultset 顧名思義。是結果集的意思。就是通過sql在數據中執行之後,可以看到的多行數據的集合。返回一個結果集之後,可以通過getString("欄位名") 或getString(欄位出現的順序數) 來獲得相應的數據。可以通過System.out.println(getString("欄位名")) 在後台列印出來或者顯示在頁面。
『貳』 有學生表tb,欄位name,subject,result ,怎樣寫sql語句
selectname,
sum(casewhensubject='語文'thenresultelse0end)as語文,
sum(casewhensubject='數學'thenresultelse0end)as數學,
sum(casewhensubject='物理'thenresultelse0end)as物理
fromtbgroupbyname
『叄』 sql 怎麼寫排名 ID RESULT 4 90 3 85 5 85 2 56 1 54 4 第 1 3,5 第2 2 第4 1 第1
select identity(int,1,1) as fid,*,cast('第' as char(10)) as mc into #temp1 from #temp order by result desc
declare @fnum int
declare @fsum int
declare @fflag int
declare @fresult int
declare @fnumstr char(2)
set @fnum=1
set @fsum=(select count(fid) from #temp1)
while @fnum<=@fsum
begin
if @fnum=1
begin
set @fresult=(select result from #temp1 where fid=@fnum)
set @fnumstr=(select cast(@fnum as char(2)))
update #temp1 set mc=ltrim(rtrim(mc))+@fnumstr where fid=@fnum
end
else
begin
set @fflag=(select count(fid) from #temp1 where result=@fresult)
if (@fflag=1 and @fresult>-1) or @fresult=-1
begin
set @fresult=(select result from #temp1 where fid=@fnum)
set @fnumstr=(select cast(@fnum as char(2)))
update #temp1 set mc=ltrim(rtrim(mc))+@fnumstr where fid=@fnum
end
else if @fflag>1
begin
update #temp1 set #temp1.mc=a.mc from (select result,mc from #temp1 where fid=@fnum-1) a where a.result=#temp1.result
set @fresult=-1
set @fnum=@fnum-2+@fflag
end
end
set @fnum=@fnum+1
end
select * from #temp1
drop table #temp1
--把這個數據寫入#temp這個表了,你可以根據自己的需要,填寫
『肆』 sql語句中first_result +1 units day - 1 units second是什麼意思呢正確寫法是怎麼寫的呢
first_result 你的欄位
1 units day一個單位時間
1 units second 一個單位描
不過這明顯不是sql語句。反正在那邊是無法運行。你從那邊找來的
『伍』 這個SQL語句哪裡不對了
SELECT o1.DATES,COUNT(o1.result) AS "勝",COUNT(o2.result) AS "負"
FROM test1 o1 JOIN test1 o2 ON o1.a = o2.a
WHERE o1.result = '勝' AND o2.result = '負'
GROUP BY o1.DATES
『陸』 SQL語句怎麼寫
select D.date,D.WIN as '勝',E.lose as '負'
from
(select date,win from(
SELECT date,
case when result = '勝' then count(result) else 0 end as 'win',
case when result = '負' then count(result) else 0 end as 'lose'
from T3
group by date,result
) C
where win > 0
group by date,C.win,C.lose) D,
(select date,lose from(
SELECT date,
case when result = '勝' then count(result) else 0 end as 'win',
case when result = '負' then count(result) else 0 end as 'lose'
from T3
group by date,result
) C
where lose > 0
group by date,C.win,C.lose) E
where E.date = D.date
-------------------------結果---------------
結果如下
date 勝 負
2007-07-01 00:00:00 2 2
2007-08-01 00:00:00 1 2
『柒』 問這個SQL語句該怎樣寫
/*轉化:把B、C列相同的給去掉*/
--建立臨時表
create table #result
(
seg_A seg_A_type null,
seg_B seg_B_type null,
seg_C seg_C_type null
)
--找出兩個及兩個以上相同的值
insert into #result(seg_B,seg_C)
select distinct B,C from table group by B,C having count(1) > 1
--賦值主鍵(不知道你要的主鍵是不是也有規律,比如最小的,或者最大的)
update #result set seg_A = b.A from #result a,table b where a.seg_B = b.B and a.seg_C = b.C
--刪除B、C列重值
delete table from #result a,table b where a.seg_B = b.B and a.seg_C = b.C
--補入
insert into table (A,B,C)
select seg_A,seg_B,seg_C from #result
--釋放臨時表
drop table #result
『捌』 資料庫emp,表中有id和Result兩個欄位。。。求寫SQL語句
selectid,count(Result)fromempwhereid='需要的ID'groupbyResult