Posted 鐚崄涓夎鎶€鏈?/a>

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了相关的知识,希望对你有一定的参考价值。

馃崁瀛愭煡璇㈣〃杈惧紡鏈夊洓绉嶇被鍨嬶紝鍒嗗埆涓鸿〃鏍煎瓙鏌ヨ(tabular)銆佹煴褰㈠瓙鏌ヨ(columnar)銆佽瀛愭煡璇?row)銆佸拰鏍囬噺瀛愭煡璇?scalar)銆傚叾涓瘮杈冨父鐢ㄧ殑鏄〃鏍笺€佹煴褰㈠拰鏍囬噺銆傝〃鏍煎父鍑虹幇鍦‵ROM瀛愬彞涓€傝€屾煴褰㈠父鍑虹幇鍦↖N鎴栬€匒NY绛夎皳璇嶅悗銆傛爣閲忎綔涓鸿繑鍥炵殑涓€涓崟琛屽崟鍒楃殑鍊煎嚑涔庡彲浠ュ嚭鐜板湪SQL璇彞鐨勪换浣曞湴鏂广€俒鈥


馃崈 1. 瀛愭煡璇?/strong>琛ㄨ揪寮忔湁鍥涚绫诲瀷锛屽垎鍒负琛ㄦ牸(tabular)銆?code class="mq-5">鏌卞舰(columnar)銆?code class="mq-6">琛?/code>(row)銆佸拰鏍囬噺(scalar)銆?/p>

馃崈  2.  琛ㄦ牸瀛愭煡璇?/strong>锛氬瓙鏌ヨ杩斿洖涓€寮犺〃锛岃瀛愭煡璇㈠繀椤诲嚭鐜板湪SQL-92涓瀹氱殑浣跨敤浣嶇疆锛屽嵆鍑虹幇鍦?code class="mq-9">FROM瀛愬彞涓€?/p>

馃崈  3.  鏌辩姸瀛愭煡璇?/strong>锛氬瓙鏌ヨ杩斿洖涓€寮犱粎鍖呭惈涓€鍒楃殑琛紝杩欐槸鍘烻QL-86鍜孲QL-89涓殑涓€绉嶉噸瑕佺被鍨嬶紝鍥犱负IN銆?code class="mq-12"><姣旇緝鎿嶄綔绗?gt;ALL鍜?code class="mq-13"><姣旇緝鎿嶄綔绗?gt;{ANY|SOME}璋撹瘝锛屽皢鍗曚釜鍒楄浆鎹㈡垚涓€鍒楃敱AND鎴栬€匫R杩炴帴鐨勬瘮杈冭繍绠楃殑璇█鑳藉姏銆?/p>

馃崈  4.  琛屽瓙鏌ヨ锛氳瀛愭煡璇㈣繑鍥炲崟琛屻€傚湪浣跨敤琛岀殑鍦版柟閮藉彲浠ヤ娇鐢ㄦ绫诲瓙鏌ヨ銆傝繖绉嶅瓙鏌ヨ鏄祵鍏ュ紡SQL涓娇鐢ㄧ殑鍗曚緥SELECT璇彞鐨勫熀纭€銆傝繖绫诲瓙鏌ヨ鐜板湪鐢ㄧ殑骞朵笉澶氥€?/p>

馃崈 5.   鏍囬噺瀛愭煡璇?/strong>锛氭爣閲忓瓙鏌ヨ杩斿洖鍗曚釜鏍囬噺鍊笺€傚畠鍙互鐢ㄥ湪浠讳綍鍙娇鐢ㄦ爣閲忓€肩殑鍦版柟锛屽嵆鍙敤浜嶴ELECT鎴朩HERER瀛愬彞涓€傚鏋滄爣閲忓瓙鏌ヨ杩斿洖绌虹粨鏋滐紝鍒欒浆鎹负NULL銆傚鏋滄爣閲忓瓙鏌ヨ杩斿洖澶氳锛屽皢杩斿洖鍩烘暟杩濊閿欒銆?/p>

1. 琛ㄦ牸瀛愭煡璇?/h1>

馃崅  琛ㄥ瓙鏌ヨ锛氳繑鍥炰竴寮犲琛屽鍒楃殑琛紝鍙互鐞嗚В鍏朵负涓€寮犱竴娆℃€х殑瑙嗗浘銆傛绉嶅瓙鏌ヨ鍑虹幇鍦?code class="mq-18">FROM瀛愬彞涓紝鎵ц鐨勬椂鍊?span>鍐呴儴瀛愭煡璇紭鍏堟墽琛?/code>銆?br>馃崅瀛愭煡璇㈡煡璇㈢粨鏋滃彲浠ヤ綔涓轰竴寮犺〃鍜屽埆琛ㄥ叧鑱旀煡璇€?/p>

鑼冧緥

  • 浜у搧锛坧roduct锛夎〃涓殑瀛楁鏈夛細

    product_id 浜у搧id ,product_name 浜у搧鍚嶇О ,product_type 浜у搧绫诲瀷 ,sale_price 鍞崠浠锋牸 ,purchase_price 閲囪喘浠锋牸 ,regist_date 娉ㄥ唽鏃ユ湡

  • 鍗曞眰瀛愭煡璇細

SELECT product_type, cnt_product FROM ( SELECT product_type, COUNT( * ) AS cnt_product FROM Product GROUP BY product_type ) AS ProductSum;
  • 瀛愭煡璇綔涓轰复鏃惰〃锛屽彲宓屽澶氬眰瀛愭煡璇細

SELECT product_type, cnt_product FROM ( SELECT * FROM ( SELECT product_type, COUNT( * ) AS cnt_product FROM Product GROUP BY product_type ) AS ProductSum WHERE cnt_product = 4 ) AS ProductSum2;

鍏堟墽琛屾渶鍐呭眰鐨勬煡璇紝浣跨敤鍟嗗搧绫诲瀷鍒嗙粍锛涘啀鎵ц澶栧眰瀛愭煡璇紝鎵惧嚭鍒嗙粍鍟嗗搧鏁伴噺涓?鐨勫晢鍝侊紱鏈€鍚庢墽琛屾渶澶栧眰鐨勫瓙鏌ヨ锛岃緭鍑鸿〃鏁版嵁銆?/p>

2. 鏌辩姸瀛愭煡璇?/h1>

馃崅 鏌辩姸瀛愭煡璇?/strong>锛氬瓙鏌ヨ杩斿洖涓€寮犱粎鍖呭惈涓€鍒楃殑琛紝鐢ㄤ簬IN銆?code class="mq-33"><姣旇緝鎿嶄綔绗?gt;ALL鍜?code class="mq-34"><姣旇緝鎿嶄綔绗?gt;{ANY|SOME}璋撹瘝

  • 鏂版坊鍔犱骇鍝佽鎯咃紙product_info锛夎〃涓殑瀛楁鏈夛細

    product_id 浜у搧id ,tags浜у搧鏍囩 ,desc 浜у搧鎻忚堪

  • 鏌ヨ鏈夋弿杩颁俊鎭殑浜у搧锛屼娇鐢ㄥ瓙鏌ヨ鐨?nbsp;in 璋撹瘝瀹炵幇:

SELECT * FROM product WHERE product_id IN ( SELECT product_id FROM product_info )
  • 鏌ヨ浜у搧浠锋牸澶т簬锛屼换浣曞瓙鏌ヨ鏌ヨ鍑虹殑浠锋牸涔嬩竴鏃㈢鍚堟潯浠讹紝浣跨敤瀛愭煡璇㈢殑 any 璋撹瘝瀹炵幇锛?/p>

SELECT * FROM product WHERE sale_price > ANY ( SELECT sale_price FROM product WHERE sale_price BETWEEN 500 AND 8000 )

3. 鏍囬噺瀛愭煡璇?/h1>

馃崅 鏍囬噺瀛愭煡璇?/strong>锛?/p>

杩斿洖涓€寮犱粎鏈夊崟琛屽崟鍒楃殑琛紝鍏惰繑鍥炵殑鏄崟涓€鐨勫€笺€?/p>


馃崅 浣嶇疆锛?/p>

鑳藉浣跨敤甯告暟鎴栬€呭垪鍚嶇殑鍦版柟锛屾棤璁烘槸 SELECT 瀛愬彞銆?GROUP BY 瀛愬彞銆?HAVING 瀛愬彞锛岃繕鏄疧RDER BY 瀛愬彞锛屽嚑涔庢墍鏈夌殑鍦版柟閮藉彲浠ヤ娇鐢ㄣ€?/p>

鑼冧緥涓€
  • 鍒涘缓鏁欏笀琛紝瀛︾敓琛細

    鏁欏笀琛?/strong>涓殑瀛楁鏈?nbsp;teacher_name(鏁欏笀鍚嶇О) , birth_date(鐢熸棩)

    瀛︾敓琛?/strong>涓殑瀛楁鏈?nbsp;student_name(瀛︾敓鍚嶇О), birth_date(鐢熸棩)

  • WHERE鍚庝腑浣跨敤鐨勬爣閲忓瓙鏌ヨ锛屾煡璇㈡瘮鏈€澶у鐢熷勾榫勫ぇ5宀佺殑鎵€鏈夋暀甯?/p>

SELECT t1.teacher_name FROM teachers t1 WHERE t1.birth_date < ( SELECT MIN( s1.birth_date ) - INTERVAL 5 YEAR FROM students s1 )

鑼冧緥浜?/h6>
  • 鍒涘缓渚涘簲鍟嗗拰杩愯緭閲忕殑琛?/p>

    渚涘簲鍟嗚〃(suppliers)涓瓧娈垫湁: sup_nbr(渚涘簲鍟嗙紪鍙? , sup_name(渚涘簲鍟嗗悕绉?/span>)

    杩愯緭閲?span class="mq-62">琛?shipments)涓瓧娈垫湁: sup_nbr(渚涘簲鍟?/span>缂栧彿), onhand_qty(渚涘簲鍟嗕緵璐ч噺)

  • 鍏宠仈瀛愭煡璇?/code>浣跨敤鏍囬噺瀛愭煡璇紝鏌ヨ鍝簺渚涘簲鍟嗙粰鎴戜滑鎻愪緵浜嗕笉鍒?00鐨勮揣鐗?/p>

SELECT sup_nbr, sup_name FROM suppliers WHERE 100 > ( SELECT SUM( onhand_qty ) FROM shipments WHERE shipments.sup_nbr = suppliers.sup_nbr )
鑼冧緥涓?/h6>
  • 鏌ユ壘鍝簺浜у搧缁忕悊璐熻矗鐨勮揣鐗╋紝鍦ㄤ粨搴撲腑鐨勫簱瀛樺ぇ浜庡晢搴楄揣鏋?/p>


SELECT manager_name, product_nbr FROM stores AS s1WHERE ( SELECT SUM( onhand_qty ) FROM warehouses AS w1 WHERE s1.product_nbr = w1.product_nbr ) < ( SELECT SUM( shelf_qty ) FROM retailstores AS r1 WHERE s1.product_nbr = r1.product_nbr );
鑼冧緥鍥?/h6>
  • 杩斿洖鍒?/code>涓娇鐢ㄥ瓙鏌ヨ锛屾煡璇㈡瘡涓緵搴斿晢鐨勮鍗曟暟閲?/p>

SELECT sup_id, sup_name, ( SELECT COUNT( * ) FROM orders WHERE suppliers.sup_id = orders.sup_id ) AS order_countFROM suppliers;
  • 涓婅堪鏌ヨ锛屽彲浠ュ彇浠e涓嬬殑鑱旀煡


SELECT sup_id, sup_name, COUNT( * ) FROM suppliers LEFT JOIN orders ON suppliers.sup_id = orders.sup_idGROUP BY suppliers.sup_id;

以上是关于的主要内容,如果未能解决你的问题,请参考以下文章

谷歌浏览器调试jsp 引入代码片段,如何调试代码片段中的js

片段和活动之间的核心区别是啥?哪些代码可以写成片段?

VSCode自定义代码片段——.vue文件的模板

VSCode自定义代码片段6——CSS选择器

VSCode自定义代码片段——声明函数

VSCode自定义代码片段8——声明函数

(c)2006-2024 SYSTEM All Rights Reserved IT常识