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'
精彩评论