mysql數據庫添加用戶及分派權限詳細完成。本站提示廣大學習愛好者:(mysql數據庫添加用戶及分派權限詳細完成)文章只能為提供參考,不一定能成為您想要的結果。以下是mysql數據庫添加用戶及分派權限詳細完成正文
這兩天項目裡出了一個成績,LIMIT應用後報錯。
需求是如許的,我有3張表,infor信息表,mconfig物料設置裝備擺設表,maaply物料請求表,請求是讀出請求表中哪些人請求哪些物料
因而我先是如許寫的:
SELECT infor.name,infor.phone,infor.add,
mconfig.mname,mapply.acount,from_unixtime(mapply.atime,'%Y-%m-%d') as 'atime'
FROM mapply right JOIN infor ON mapply.uid = infor.uid inner JOIN mconfig ON mapply.mid = mconfig.mid
WHERE mapply.aid
IN (
SELECT aid
FROM `mapply` where state = $state
ORDER BY `atime` , `uid` DESC
LIMIT 0,10
)
成果報錯了
其時沒留意報的甚麼毛病,只是看到LIMIT甚麼的毛病,因而改了下代碼
SELECT infor.name,infor.phone,infor.add,
mconfig.mname,mapply.acount,from_unixtime(mapply.atime,'%Y-%m-%d') as 'atime'
FROM mapply right JOIN infor ON mapply.uid = infor.uid inner JOIN mconfig ON mapply.mid = mconfig.mid
WHERE mapply.aid
IN (
SELECT aid
FROM `mapply` where state = $state
ORDER BY `atime` , `uid` DESC
)
<pre name="code" class="sql">LIMIT 0,10</pre>
如許沒有報錯,莫離認為OK了,然則運轉後發明,數據有成績
和純真的讀出請求表的內容紛歧樣,才發明LIMIT的地位放錯了,因而又把LIMIT發在IN裡,成果報錯以下
This version of MySQL doesn't yet support ‘LIMIT & IN/ALL/ANY/SOME subquery'
細看才曉得,IN裡不支撐LIMIT。那怎樣辦呢?
因而度娘後得知,在IN裡再應用一張暫時表,把須要的內容先查出來,
修正子女碼以下:
SELECT infor.name,infor.phone,infor.add,
mconfig.mname,mapply.acount,from_unixtime(mapply.atime,'%Y-%m-%d') as 'atime'
FROM mapply right JOIN infor ON mapply.uid = infor.uid inner JOIN mconfig ON mapply.mid = mconfig.mid
WHERE mapply.aid
IN (
SELECT aid
FROM (SELECT `aid` FROM `mapply` where state = $state
ORDER BY `atime` , `uid` DESC
LIMIT 0,10)AS `tp`
)
運轉後,成績處理~~~