求助,這樣查詢的hql語句應該怎么寫?我想通過UId查詢PCre 愛問知
top語法HQL不支持 變通的方法是 String HQL = "from Photo p where *='"+id+"' order by PCredit desc"; Query query = *Query(HQL); //設定起始位置 *stResult(0); //設定個數 *Results(2); //返回值是一個list,里面就是排序的前兩個對象 List resList = *(); 謝謝!。
求寫一條hibernate的hql語句
再套一層,select * from Tbobject where order_id in (。.你的一列數據)
HQL這樣寫
select * from TbOrder where *d in (select distinct *d from TbOrder t where *no=1)
-------------------------貌似不對奧----------
這樣,我以前SQL語句這樣寫過,
select distinct *d ,max(列1),max(列2),max(列3) from TbOrder t where *no=1
HQL語句 distinct 的用法
1、distinct這個關鍵字用來過濾掉多余的重復記錄只保留一條,但往往只用它來返回不重復記錄的條數,而不是用它來返回不重記錄的所有值。其原因是distinct只有用二重循環查詢來解決,而這樣對于一個數據量非常大的站來說,無疑是會直接影響到效率的。
2、distinct的只顯示一次重復出更的值。 不過這個值出現多少次只顯示一次。 select distinct 字段名1,字段名2 from 表格 order by 字段名1 distinct 字段名1 意思是只顯示一次字段名1顯示的是第一次出現的。 最好和order by 結合使用。
3、表中包含有若干列數據,現在想用某一列進行distinct操作,但是還想在結果中輸出所有的列,只要對該列distinct就可以,比如是列test1,表是table,select * from table where test1 in(select distinct(test1) from table)。
求寫一條hibernate的hql語句
再套一層,select * from Tbobject where order_id in (。
.你的一列數據)HQL這樣寫select * from TbOrder where *d in (select distinct *d from TbOrder t where *no=1)-------------------------貌似不對奧----------這樣,我以前SQL語句這樣寫過,select distinct *d ,max(列1),max(列2),max(列3) from TbOrder t where *no=1。