有两个表:
一个会员表:huiyuan
一个会员积分表:jifen
================会员表结构如下:================
userid username point
1 真水无香 455
2 真爱无敌 658
3 真的爱你 587
4 真的后悔 698
...
--------------------------------------------
userid字段:是会员ID
username字段:是会员昵称
point字段:是会员当前总积分
================================================
=============会员积分表结构如下:===============
id grade actor min max
-------------------------------------------
1 一级 见习 0 100
2 二级 助理 101 500
3 三级 主任 501 1000
4 四级 经理 1001 2500
5 五级 总裁 2501 5000
...
-------------------------------------------min字段 和 max字段 是积分字段 这2个字段是互动的。min字段是积分计算起始, max字段是数字积分结束。
例: 0分 - 100分 范围内的 是属一级
101分 - 500分 范围内的 是属二级
501分 - 1000分 范围内的 是属三级
1001分 - 2500分 范围内的 是属四级
2501分 - 5000分 范围内的 是属五级
类推...
================================================要求mysql输出结果:你的昵称:真水无香 您的等级:二级 您的职位:助理 您的积分:455分
非常感谢!!!
一个会员表:huiyuan
一个会员积分表:jifen
================会员表结构如下:================
userid username point
1 真水无香 455
2 真爱无敌 658
3 真的爱你 587
4 真的后悔 698
...
--------------------------------------------
userid字段:是会员ID
username字段:是会员昵称
point字段:是会员当前总积分
================================================
=============会员积分表结构如下:===============
id grade actor min max
-------------------------------------------
1 一级 见习 0 100
2 二级 助理 101 500
3 三级 主任 501 1000
4 四级 经理 1001 2500
5 五级 总裁 2501 5000
...
-------------------------------------------min字段 和 max字段 是积分字段 这2个字段是互动的。min字段是积分计算起始, max字段是数字积分结束。
例: 0分 - 100分 范围内的 是属一级
101分 - 500分 范围内的 是属二级
501分 - 1000分 范围内的 是属三级
1001分 - 2500分 范围内的 是属四级
2501分 - 5000分 范围内的 是属五级
类推...
================================================要求mysql输出结果:你的昵称:真水无香 您的等级:二级 您的职位:助理 您的积分:455分
非常感谢!!!
FROM `huiyuan` a
INNER JOIN jifen b ON ( a.point >= b.min
AND a.point <= b.max )
left join `jifen` j on h.`point`>=j.`min` and h.`point`<=j.`max`
where h.`username`='真水无香';
错误
SQL 查询: SELECT a.userid, a.username, a.point, b.grade, b.actor
FROM huiyuan a, jifen b
WHERE a.userid = b.id
WHERE a.username = "真水无香"
LIMIT 0 , 30 MySQL 返回: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where a.username = "刘é
SELECT huiyuan.*,jifen.grade,jifen.actor
FROM huiyuan
LEFT JOIN jifen
ON (huiyuan.point >= jifen.min AND huiyuan.point <= jifen.max)
WHERE huiyuan.username='真水无香';
不好意思,多了一个where
原来我在提问的时候
把会员积分表的一个字段给忘记了
各位大侠 真的不好意思啊 太不好意思了
还有这个是字段没有写进去:typeid 真是郁闷
typeid字段的功能是 让会员自己选择自己喜欢的风格
总共有5种风格各位大侠 在麻烦你们一下 感激 谢谢哈 id typeid grade actor min max
1 0 一级 试用期 0 100
2 0 二级 助理 101 500
3 0 三级 助理 501 1000
4 0 四级 经理 1001 2500
5 0 五级 经理 2501 5000
6 1 一级 魔法学徒 0 100
7 1 二级 见习魔法师 101 500
8 1 三级 见习魔法师 501 1000
9 1 四级 魔法师 1001 2500
10 1 五级 魔法师 2501 5000
11 2 一级 童生 0 100
12 2 二级 秀才 101 500
13 2 三级 秀才 501 1000
14 2 四级 举人 1001 2500
15 2 五级 举人 2501 5000
16 3 一级 兵卒 0 100
17 3 二级 门吏 101 500
18 3 三级 门吏 501 1000
19 3 四级 千总 1001 2500
20 3 五级 千总 2501 5000
21 4 一级 初学弟子 0 100
22 4 二级 初入江湖 101 500
23 4 三级 初入江湖 501 1000
24 4 四级 江湖新秀 1001 2500
25 4 五级 江湖新秀 2501 5000
select h.*,j.`grade`,j.`actor` from `huiyuan` h
left join `jifen` j on h.`point`>=j.`min` and h.`point`<=j.`max`
where j.`typeid`='0' and h.`username`='真水无香';
大侠好
请问j.`typeid`='0' 怎么是0了呢?
0的话 是限制读第一个的哦
我想输出用户所选择的typeid哦
谢谢哈
select a.*,b.grade,b.actor,c.grade,c.actor,d.grade,d.actor,e.grade,e.actor,f.grade,f.actor,
from huiyuan a
join jifen b on a.point>=b.min and a.point<=b.max and b.typeid='0'
join jifen c on a.point>=c.min and a.point<=c.max and c.typeid='1'
join jifen d on a.point>=d.min and a.point<=d.max and d.typeid='2'
join jifen e on a.point>=e.min and a.point<=e.max and e.typeid='3'
join jifen f on a.point>=f.min and a.point<=f.max and f.typeid='4'
where a.username='真水无香';
试试,没测试过!原理是匹配每种风格以不同的别名显示
select a.*,b.grade,b.actor,c.grade,c.actor,d.grade,d.actor,e.grade,e.actor,f.grade,f.actor,
from huiyuan a
left join jifen b on a.point>=b.min and a.point<=b.max and b.typeid='0'
left join jifen c on a.point>=c.min and a.point<=c.max and c.typeid='1'
left join jifen d on a.point>=d.min and a.point<=d.max and d.typeid='2'
left join jifen e on a.point>=e.min and a.point<=e.max and e.typeid='3'
left join jifen f on a.point>=f.min and a.point<=f.max and f.typeid='4'
where a.username='真水无香';额 应该是这样~没测试
执行结果如下: 错误
SQL 查询: SELECT a. * , b.grade, b.actor, c.grade, c.actor, d.grade, d.actor, e.grade, e.actor, f.grade, f.actor,
FROM huiyuan a
JOIN jifen b ON a.point >= b.min
AND a.point <= b.max
AND b.typeid = '0'
JOIN jifen c ON a.point >= c.min
AND a.point <= c.max
AND c.typeid = '1'
JOIN jifen d ON a.point >= d.min
AND a.point <= d.max
AND d.typeid = '2'
JOIN jifen e ON a.point >= e.min
AND a.point <= e.max
AND e.typeid = '3'
JOIN jifen f ON a.point >= f.min
AND a.point <= f.max
AND f.typeid = '4'
WHERE a.username = 'fulin'
LIMIT 0 , 30 MySQL 返回: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from huiyuan a join jifen b on a.point >= b.min and a.point <=' at line 1
from huiyuan a
left join jifen b on a.point>=b.min and a.point<=b.max and b.typeid=0
left join jifen c on a.point>=c.min and a.point<=c.max and c.typeid=1
left join jifen d on a.point>=d.min and a.point<=d.max and d.typeid=2
left join jifen e on a.point>=e.min and a.point<=e.max and e.typeid=3
left join jifen f on a.point>=f.min and a.point<=f.max and f.typeid=4
where a.username='真水无香';
select a.*,b.grade,b.actor
from huiyuan a
jifen b on a.point>=b.min and a.point<=b.max and b.typeid=0
where a.username='真水无香';
union select a.*,b.grade,b.actor
from huiyuan a
join jifen b on a.point>=b.min and a.point<=b.max and b.typeid=1
where a.username='真水无香';
union select a.*,b.grade,b.actor
from huiyuan a
join jifen b on a.point>=b.min and a.point<=b.max and b.typeid=2
where a.username='真水无香';
union select a.*,b.grade,b.actor
from huiyuan a
join jifen b on a.point>=b.min and a.point<=b.max and b.typeid=3
where a.username='真水无香';
union select a.*,b.grade,b.actor
from huiyuan a
join jifen b on a.point>=b.min and a.point<=b.max and b.typeid=4
where a.username='真水无香';看看哪个执行效率比较好,呃有错误自己修改下,MYSQL 没怎么用不知道支持不支持UNION 我用POSTREGSQL