⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 queryhql.html

📁 关于hibernate的中文文档 关于hibernate的中文文档 关于hibernate的中文文档 关于hibernate的中文文档
💻 HTML
📖 第 1 页 / 共 5 页
字号:
            &#22914;&#26524;&#20320;&#36824;&#19981;&#33021;&#23545;&#25152;&#26377;&#30340;&#36825;&#20123;&#28145;&#20449;&#19981;&#30097;&#65292;&#24819;&#24819;&#19979;&#38754;&#30340;&#26597;&#35810;&#12290;&#22914;&#26524;&#20351;&#29992;SQL&#65292;&#35821;&#21477;&#38271;&#24230;&#20250;&#22686;&#38271;&#22810;&#23569;&#65292;&#21487;&#35835;&#24615;&#20250;&#19979;&#38477;&#22810;&#23569;&#65306;        </p><pre class="programlisting">select custfrom Product prod,    Store store    inner join store.customers custwhere prod.name = 'widget'    and store.location.name in ( 'Melbourne', 'Sydney' )    and prod = all elements(cust.currentOrder.lineItems)</pre><p>            <span class="emphasis"><em>&#25552;&#31034;:</em></span> &#20250;&#20687;&#22914;&#19979;&#30340;&#35821;&#21477;        </p><pre class="programlisting">SELECT cust.name, cust.address, cust.phone, cust.id, cust.current_orderFROM customers cust,    stores store,    locations loc,    store_customers sc,    product prodWHERE prod.name = 'widget'    AND store.loc_id = loc.id    AND loc.name IN ( 'Melbourne', 'Sydney' )    AND sc.store_id = store.id    AND sc.cust_id = cust.id    AND prod.id = ALL(        SELECT item.prod_id        FROM line_items item, orders o        WHERE item.order_id = o.id            AND cust.current_order = o.id    )</pre></div><div class="sect1" lang="zh-cn"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="queryhql-ordering"></a>14.10.&nbsp;order by&#23376;&#21477;</h2></div></div><div></div></div><p>            &#26597;&#35810;&#36820;&#22238;&#30340;&#21015;&#34920;(list)&#21487;&#20197;&#25353;&#29031;&#19968;&#20010;&#36820;&#22238;&#30340;&#31867;&#25110;&#32452;&#20214;&#65288;components)&#20013;&#30340;&#20219;&#20309;&#23646;&#24615;&#65288;property&#65289;&#36827;&#34892;&#25490;&#24207;&#65306;        </p><pre class="programlisting">from DomesticCat catorder by cat.name asc, cat.weight desc, cat.birthdate</pre><p>            &#21487;&#36873;&#30340;<tt class="literal">asc</tt>&#25110;<tt class="literal">desc</tt>&#20851;&#38190;&#23383;&#25351;&#26126;&#20102;&#25353;&#29031;&#21319;&#24207;&#25110;&#38477;&#24207;&#36827;&#34892;&#25490;&#24207;.        </p></div><div class="sect1" lang="zh-cn"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="queryhql-grouping"></a>14.11.&nbsp;group by&#23376;&#21477;</h2></div></div><div></div></div><p>            &#19968;&#20010;&#36820;&#22238;&#32858;&#38598;&#20540;(aggregate values)&#30340;&#26597;&#35810;&#21487;&#20197;&#25353;&#29031;&#19968;&#20010;&#36820;&#22238;&#30340;&#31867;&#25110;&#32452;&#20214;&#65288;components)&#20013;&#30340;&#20219;&#20309;&#23646;&#24615;&#65288;property&#65289;&#36827;&#34892;&#20998;&#32452;&#65306;        </p><pre class="programlisting">select cat.color, sum(cat.weight), count(cat) from Cat catgroup by cat.color</pre><pre class="programlisting">select foo.id, avg(name), max(name) from Foo foo join foo.names namegroup by foo.id</pre><p>            <tt class="literal">having</tt>&#23376;&#21477;&#22312;&#36825;&#37324;&#20063;&#20801;&#35768;&#20351;&#29992;.        </p><pre class="programlisting">select cat.color, sum(cat.weight), count(cat) from Cat catgroup by cat.color having cat.color in (eg.Color.TABBY, eg.Color.BLACK)</pre><p>            &#22914;&#26524;&#24213;&#23618;&#30340;&#25968;&#25454;&#24211;&#25903;&#25345;&#30340;&#35805;(&#20363;&#22914;&#19981;&#33021;&#22312;MySQL&#20013;&#20351;&#29992;)&#65292;SQL&#30340;&#19968;&#33324;&#20989;&#25968;&#19982;&#32858;&#38598;&#20989;&#25968;&#20063;&#21487;&#20197;&#20986;&#29616;            &#22312;<tt class="literal">having</tt>&#19982;<tt class="literal">order by</tt> &#23376;&#21477;&#20013;&#12290;            </p><pre class="programlisting">select catfrom Cat cat    join cat.kittens kittengroup by cathaving avg(kitten.weight) &gt; 100order by count(kitten) asc, sum(kitten.weight) desc</pre><p>            &#27880;&#24847;<tt class="literal">group by</tt>&#23376;&#21477;&#19982;            <tt class="literal">order by</tt>&#23376;&#21477;&#20013;&#37117;&#19981;&#33021;&#21253;&#21547;&#31639;&#26415;&#34920;&#36798;&#24335;&#65288;arithmetic expressions&#65289;.        </p></div><div class="sect1" lang="zh-cn"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="queryhql-subqueries"></a>14.12.&nbsp;&#23376;&#26597;&#35810;</h2></div></div><div></div></div><p>            &#23545;&#20110;&#25903;&#25345;&#23376;&#26597;&#35810;&#30340;&#25968;&#25454;&#24211;&#65292;Hibernate&#25903;&#25345;&#22312;&#26597;&#35810;&#20013;&#20351;&#29992;&#23376;&#26597;&#35810;&#12290;&#19968;&#20010;&#23376;&#26597;&#35810;&#24517;&#39035;&#34987;&#22278;&#25324;&#21495;&#21253;&#22260;&#36215;&#26469;&#65288;&#32463;&#24120;&#26159;SQL&#32858;&#38598;&#20989;&#25968;&#30340;&#22278;&#25324;&#21495;&#65289;&#12290;            &#29978;&#33267;&#30456;&#20114;&#20851;&#32852;&#30340;&#23376;&#26597;&#35810;&#65288;&#24341;&#29992;&#21040;&#22806;&#37096;&#26597;&#35810;&#20013;&#30340;&#21035;&#21517;&#30340;&#23376;&#26597;&#35810;&#65289;&#20063;&#26159;&#20801;&#35768;&#30340;&#12290;        </p><pre class="programlisting">from Cat as fatcat where fatcat.weight &gt; (     select avg(cat.weight) from DomesticCat cat )</pre><pre class="programlisting">from DomesticCat as cat where cat.name = some (     select name.nickName from Name as name )</pre><pre class="programlisting">from Cat as cat where not exists (     from Cat as mate where mate.mate = cat )</pre><pre class="programlisting">from DomesticCat as cat where cat.name not in (     select name.nickName from Name as name )</pre><pre class="programlisting">select cat.id, (select max(kit.weight) from cat.kitten kit) from Cat as cat</pre><p>            &#27880;&#24847;&#65292;HQL&#33258;&#26597;&#35810;&#21482;&#21487;&#20197;&#22312;select&#25110;&#32773;where&#23376;&#21477;&#20013;&#20986;&#29616;&#12290;        </p><p>            &#22312;select&#21015;&#34920;&#20013;&#21253;&#21547;&#19968;&#20010;&#34920;&#36798;&#24335;&#20197;&#19978;&#30340;&#23376;&#26597;&#35810;&#65292;&#20320;&#21487;&#20197;&#20351;&#29992;&#19968;&#20010;&#20803;&#32452;&#26500;&#36896;&#31526;&#65288;tuple constructors&#65289;&#65306;         </p><pre class="programlisting">from Cat as cat where not ( cat.name, cat.color ) in (     select cat.name, cat.color from DomesticCat cat )</pre><p>            &#27880;&#24847;&#22312;&#26576;&#20123;&#25968;&#25454;&#24211;&#20013;&#65288;&#19981;&#21253;&#25324;Oracle&#19982;HSQL&#65289;&#65292;&#20320;&#20063;&#21487;&#20197;&#22312;&#20854;&#20182;&#35821;&#22659;&#20013;&#20351;&#29992;&#20803;&#32452;&#26500;&#36896;&#31526;&#65292;            &#27604;&#22914;&#26597;&#35810;&#29992;&#25143;&#31867;&#22411;&#30340;&#32452;&#20214;&#19982;&#32452;&#21512;&#65306;        </p><pre class="programlisting">from Person where name = ('Gavin', 'A', 'King')</pre><p>            &#35813;&#26597;&#35810;&#31561;&#20215;&#20110;&#26356;&#22797;&#26434;&#30340;&#65306;        </p><pre class="programlisting">from Person where name.first = 'Gavin' and name.initial = 'A' and name.last = 'King')</pre><p>            &#26377;&#20004;&#20010;&#24456;&#22909;&#30340;&#29702;&#30001;&#20351;&#20320;&#19981;&#24212;&#24403;&#20316;&#36825;&#26679;&#30340;&#20107;&#24773;&#65306;&#39318;&#20808;&#65292;&#23427;&#19981;&#23436;&#20840;&#36866;&#29992;&#20110;&#21508;&#20010;&#25968;&#25454;&#24211;&#24179;&#21488;&#65307;&#20854;&#27425;&#65292;&#26597;&#35810;&#29616;&#22312;&#20381;&#36182;&#20110;&#26144;&#23556;&#25991;&#20214;&#20013;&#23646;&#24615;&#30340;&#39034;&#24207;&#12290;        </p></div><div class="sect1" lang="zh-cn"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="queryhql-examples"></a>14.13.&nbsp;HQL&#31034;&#20363;</h2></div></div><div></div></div><p>            Hibernate&#26597;&#35810;&#21487;&#20197;&#38750;&#24120;&#30340;&#24378;&#22823;&#19982;&#22797;&#26434;&#12290;&#23454;&#38469;&#19978;&#65292;Hibernate&#30340;&#19968;&#20010;&#20027;&#35201;&#21334;&#28857;&#23601;&#26159;&#26597;&#35810;&#35821;&#21477;&#30340;&#23041;&#21147;&#12290;&#36825;&#37324;&#26377;&#19968;&#20123;&#20363;&#23376;&#65292;&#23427;&#20204;&#19982;&#25105;&#22312;&#26368;&#36817;&#30340;            &#19968;&#20010;&#39033;&#30446;&#20013;&#20351;&#29992;&#30340;&#26597;&#35810;&#38750;&#24120;&#30456;&#20284;&#12290;&#27880;&#24847;&#20320;&#33021;&#29992;&#21040;&#30340;&#22823;&#22810;&#25968;&#26597;&#35810;&#27604;&#36825;&#20123;&#35201;&#31616;&#21333;&#30340;&#22810;&#65281;        </p><p>            &#19979;&#38754;&#30340;&#26597;&#35810;&#23545;&#20110;&#26576;&#20010;&#29305;&#23450;&#30340;&#23458;&#25143;&#30340;&#25152;&#26377;&#26410;&#25903;&#20184;&#30340;&#36134;&#21333;&#65292;&#22312;&#32473;&#23450;&#32473;&#26368;&#23567;&#24635;&#20215;&#20540;&#30340;&#24773;&#20917;&#19979;&#65292;&#36820;&#22238;&#35746;&#21333;&#30340;id&#65292;&#26465;&#30446;&#30340;&#25968;&#37327;&#21644;&#24635;&#20215;&#20540;&#65292;            &#36820;&#22238;&#20540;&#25353;&#29031;&#24635;&#20215;&#20540;&#30340;&#32467;&#26524;&#36827;&#34892;&#25490;&#24207;&#12290;&#20026;&#20102;&#20915;&#23450;&#20215;&#26684;&#65292;&#26597;&#35810;&#20351;&#29992;&#20102;&#24403;&#21069;&#30446;&#24405;&#12290;&#20316;&#20026;&#36716;&#25442;&#32467;&#26524;&#30340;SQL&#26597;&#35810;&#65292;&#20351;&#29992;&#20102;<tt class="literal">ORDER</tt>,             <tt class="literal">ORDER_LINE</tt>, <tt class="literal">PRODUCT</tt>, <tt class="literal">CATALOG</tt> &#21644;<tt class="literal">PRICE</tt>            &#24211;&#34920;&#12290;        </p><pre class="programlisting">select order.id, sum(price.amount), count(item)from Order as order    join order.lineItems as item    join item.product as product,    Catalog as catalog    join catalog.prices as pricewhere order.paid = false    and order.customer = :customer    and price.product = product    and catalog.effectiveDate &lt; sysdate    and catalog.effectiveDate &gt;= all (        select cat.effectiveDate         from Catalog as cat        where cat.effectiveDate &lt; sysdate    )group by order

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -