开发者

Using variable with query

I have a field name authorisation having length 150 chars.

I want query to check authorisation at particular digit.

SELECT e.staffid, COUNT(e.staffid) FROM enrll e INNER JOIN staff s on e.staffid=s.staffid 
                        WHERE s.auth = '1' and NOT EXISTS (SELECT staffid FROM shdl h where s.staffid=h.staffid and h.shdldt='$unixdt')
                        GROUP BY e.staffid ORDER BY COUNT(e.staffid) DESC";

THough I have used a "1" for testing purpose but now I want to check auth at particular digit like. for that I took variable with 150 digit. I need to check at 150th position that if at last pos开发者_StackOverflow社区ition it is 1 it will fetch record.


... WHERE SUBSTRING(s.auth,150,1) = '1' ...

SUBSTRING(str, pos, len) can be used for this, but all your index on s.auth is useless then.


May be you can try

substr(s.auth,-1) = '1'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜