selectu.id,u.nicename,u.imei,u.address,u.mobile,fromusersasu,(selectcount(imei)次數,imeifromrebackwhereconvert(varchar(10),[time],120)='2012-11-06'groupbyimei)vwherev.imei=u.imeiorderbyv.次數desc你寫的重複查詢的太多了,整體結構不好。
- 情感問答
- 答案列表
sql 一對多查詢:sql一對多關聯查詢[朗讀]
selectt1.id,t1.name,t2.typefromt1leftouterjoint2ont1.id=t2.idandt2.pid='1'要是只顯示t2中pid的奇數時selectt1.id,t1.name,t2.typefromt1leftouterjoint2ont1.id=t2.idandt2.pid%2=1這時可以得出你想要的結果.不知你想要的是不是這樣的編輯.希望能給你點幫助。
如果你的表有主鍵那就用selectcount(主鍵)from表名.這樣寫對數據的優化有好處。
select表a.typeid,表b.namefrom表a,表bwhere表a.typeid=表b.keyvalueand表b.id='typeid'。
intpagecount=15(每頁顯示的行數)inttotalcount=30(頁數*每頁顯示的行數),這裡是第二頁stringsearchstring=xxxxxx(搜索條件)selecttoppagecount*from表名whereidnotin(selecttoptotalcountidfrom表名wheresearchstring)wheresearchstringorderbytimedesc然後下個aspnetpage的分頁控制項就行了,以上是分頁的sql語句。