亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫(kù)
最近訪問(wèn)板塊 發(fā)新帖
查看: 2862 | 回復(fù): 4
打印 上一主題 下一主題

[數(shù)據(jù)庫(kù)] 好玩的SQL [復(fù)制鏈接]

論壇徽章:
1
數(shù)據(jù)庫(kù)技術(shù)版塊每日發(fā)帖之星
日期:2015-06-12 22:20:00
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2015-06-11 09:48 |只看該作者 |倒序?yàn)g覽
1. 做一個(gè)3*3的加法表
  1. SQL> select a||'+'||b||'='||(a+b) from (select rownum a from all_objects where rownum<4), (select rownum b from all_objects where rownum<4);

  2. A||'+'||B||'='||(A+B)
  3. ------------------------------------------------------------------------------------------------------------------------
  4. 1+1=2
  5. 1+2=3
  6. 1+3=4
  7. 2+1=3
  8. 2+2=4
  9. 2+3=5
  10. 3+1=4
  11. 3+2=5
  12. 3+3=6

  13. 9 rows selected.
復(fù)制代碼
2. 做一個(gè)5*5的乘法表
  1. with multiplier as (select rownum n from dual connect by rownum<6)
  2. select a.n||'*'||b.n||'='||(a.n*b.n) from multiplier a, multiplier b
復(fù)制代碼
3. 不用connect by,只用dual表,構(gòu)造出1到128
  1. with a as (select 1 from dual union all select 1 from dual)
  2. select rownum from a,a,a,a,a,a,a
復(fù)制代碼
4. 池塘邊上有牛和鵝若干,小華總共看到15個(gè)頭42條腿,請(qǐng)問(wèn)牛和鵝各有多少?
  1. with a as (select 1 from dual union all select 1 from dual),
  2. b as (select rownum n from a,a,a,a)
  3. select x.n num_of_bull, y.n num_of_goose from b x, b y where x.n*4+y.n*2=42 and x.n+y.n=15
復(fù)制代碼
5. 百錢(qián)買(mǎi)雞兔:老母雞3塊1只,小母雞4塊5只,大白兔2塊1只,小白兔3塊4只,要求買(mǎi)回來(lái)的動(dòng)物總共100只,并且腳不少于240條不多于320條;100塊錢(qián)來(lái)買(mǎi)這些動(dòng)物,要求每種動(dòng)物都至少要購(gòu)買(mǎi)一只且錢(qián)正好花完,輸出所有的可能情況。
  1. with t as (select 1 from dual union all select 1 from dual),
  2. t1 as (select rownum n from t,t,t,t,t)
  3. select a.n lmj,5*b.n xmj,c.n dbt,4*d.n xbt from t1 a,t1 b,t1 c,t1 d where 3*a.n+b.n*4+c.n*2+d.n*3=100 and a.n+5*b.n+c.n+4*d.n=100 and (2*a.n+10*b.n+4*c.n+16*d.n between 240 and 320) and a.n<>0 and b.n<>0 and c.n<>0 and d.n<>0;
復(fù)制代碼
6. 每個(gè)雇員的薪水(SAL)都對(duì)應(yīng)到一個(gè)薪水級(jí)別(SALGRADE表中的GRADE字段),哪個(gè)薪水級(jí)別上的雇員數(shù)量最多?輸出該薪水級(jí)別信息。本題需要用三種不同的寫(xiě)法作答。

第一種寫(xiě)法:
  1. select * from salgrade where grade=(select grade from (select s.grade,count(*) from emp e,salgrade s where e.sal between s.losal and s.hisal group by s.grade order by 2 desc) where rownum=1);
復(fù)制代碼
第二種寫(xiě)法:
  1. with t as (select s.grade,count(*) num from emp e,salgrade s where e.sal between s.losal and s.hisal group by s.grade),
  2. t1 as (select max(num) maxnum from t)
  3. select s.* from salgrade s,t,t1 where s.grade=t.grade and t.num=t1.maxnum;
復(fù)制代碼
第三種寫(xiě)法:
  1. select * from salgrade where exists (select 1 from (select grade from (select s.grade,count(*) from emp e,salgrade s where e.sal between s.losal and s.hisal group by s.grade order by 2 desc) where rownum=1) s where s.grade=salgrade.grade);
復(fù)制代碼

論壇徽章:
17
天蝎座
日期:2014-03-10 14:35:04數(shù)據(jù)庫(kù)技術(shù)版塊每日發(fā)帖之星
日期:2015-12-13 06:20:00IT運(yùn)維版塊每日發(fā)帖之星
日期:2015-12-13 06:20:00數(shù)據(jù)庫(kù)技術(shù)版塊每日發(fā)帖之星
日期:2015-10-20 06:20:00數(shù)據(jù)庫(kù)技術(shù)版塊每日發(fā)帖之星
日期:2015-08-21 06:20:00數(shù)據(jù)庫(kù)技術(shù)版塊每日發(fā)帖之星
日期:2015-06-17 22:20:002015年迎新春徽章
日期:2015-03-04 09:57:092015年辭舊歲徽章
日期:2015-03-03 16:54:15技術(shù)圖書(shū)徽章
日期:2015-01-12 17:05:35亥豬
日期:2014-11-09 13:05:04金牛座
日期:2014-09-25 11:28:54處女座
日期:2014-09-15 19:58:36
2 [報(bào)告]
發(fā)表于 2015-06-16 15:51 |只看該作者
有趣味性~

論壇徽章:
1
數(shù)據(jù)庫(kù)技術(shù)版塊每日發(fā)帖之星
日期:2016-01-14 06:20:00
3 [報(bào)告]
發(fā)表于 2015-07-08 12:01 |只看該作者
不錯(cuò),挺好玩的,要多分享

論壇徽章:
7
亥豬
日期:2013-10-10 17:00:29辰龍
日期:2013-10-12 16:23:19卯兔
日期:2013-11-18 17:01:27金牛座
日期:2014-09-09 10:17:052015七夕節(jié)徽章
日期:2015-08-21 11:06:172015亞冠之柏太陽(yáng)神
日期:2015-09-25 13:56:42數(shù)據(jù)庫(kù)技術(shù)版塊每日發(fā)帖之星
日期:2016-08-06 06:20:00
4 [報(bào)告]
發(fā)表于 2015-07-13 15:10 |只看該作者
第一題;這樣寫(xiě)好看些
  1. WITH t AS
  2. (SELECT level lv FROM dual connect by level < 10)
  3. SELECT
  4. max(decode(an, 1, val)) col1,
  5. max(decode(an, 2, val)) col2,
  6. max(decode(an, 3, val)) col3,
  7. max(decode(an, 4, val)) col4,
  8. max(decode(an, 5, val)) col5,
  9. max(decode(an, 6, val)) col6,
  10. max(decode(an, 7, val)) col7,
  11. max(decode(an, 8, val)) col8,
  12. max(decode(an, 9, val)) col9
  13. FROM
  14. (
  15. SELECT a.lv an, b.lv bn, a.lv || '+' || b.lv || '=' || (a.lv + b.lv) val
  16. FROM t a, t b
  17. WHERE a.lv <= b.lv
  18. )
  19. group by bn
  20. order by  1
復(fù)制代碼

論壇徽章:
59
2015七夕節(jié)徽章
日期:2015-08-24 11:17:25ChinaUnix專(zhuān)家徽章
日期:2015-07-20 09:19:30每周論壇發(fā)貼之星
日期:2015-07-20 09:19:42ChinaUnix元老
日期:2015-07-20 11:04:38榮譽(yù)版主
日期:2015-07-20 11:05:19巳蛇
日期:2015-07-20 11:05:26CU十二周年紀(jì)念徽章
日期:2015-07-20 11:05:27IT運(yùn)維版塊每日發(fā)帖之星
日期:2015-07-20 11:05:34操作系統(tǒng)版塊每日發(fā)帖之星
日期:2015-07-20 11:05:36程序設(shè)計(jì)版塊每日發(fā)帖之星
日期:2015-07-20 11:05:40數(shù)據(jù)庫(kù)技術(shù)版塊每日發(fā)帖之星
日期:2015-07-20 11:05:432015年辭舊歲徽章
日期:2015-07-20 11:05:44
5 [報(bào)告]
發(fā)表于 2015-07-20 11:09 |只看該作者
太厲害 了。有想象力。
您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專(zhuān)區(qū)
中國(guó)互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過(guò)ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP