【求助】三表联查,搞糊涂了
如图,是数据库中的表及关系
首先请问这样的关系有问题吗?
- SQL code
SELECT [_std_item_code],[_std_item_name] FROM [_tbl_std_item] [color=#FF0000]$#%&^*($%...[/color] WHERE [_user_category_name]=[color=#0000FF]strCategoryname[/color]
strCategoryname是自己定义的参数,要根据它查出[_std_item_code]和[_std_item_name]
$#%&^*($%...冰天雪地赤膊跪求这部分怎么写
谢谢各位了
[解决办法]
- SQL code
declare @strCategoryname varchar(30)select * from _tbl_user_category a,_tbl_user_item b,_tbl_std_item cwhere a._user_category_id=b._user_item_category_idand b._user_item_id=c._std_item_idand a._user_category_name=@strCategoryname
[解决办法]
- SQL code
SELECT [_std_item_code],[_std_item_name] FROM [_tbl_std_item] c join tbl_user_item b on b._user_std_item_id=c._std_item_id join tbl_user_category on a._user_category_id=b._user_item_categpry_id WHERE [_user_category_name]=strCategoryname