使用两个表选择记录-嵌套SQL查询 [英] Selecting recordes using two tables - Nested SQL query

查看:293
本文介绍了使用两个表选择记录-嵌套SQL查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.


我有两个桌子
* UsersPoints(Column- UserName,Points)
* PrizeGiven(Column- UserName,Points)


假设我想将奖金奖励给那些具有> 100积分的用户(从表UserPoints中获得),然后我将该用户名和100积分插入PrizeGiven表中,以便在以后的奖金分配中删除该用户(我不会删除此用户用户和UserPoints表中的点).


((从点数大于100的UsersPoints中选择用户名)不在其中的用户名(从PrizeGiven的点数= 100中选择UserName)"


但是查询不起作用!!!

Hello to all.


I have two tables
* UsersPoints(Column- UserName , Points)
* PrizeGiven(Column- UserName , Points)


suppose i want to give prize to those users who have >100 points ( from table UserPoints) and then i will insert that username and 100 Points in PrizeGiven Table so that i can remove this user in future prise distribution( i am not removing this user and points from UserPoints Table).


"(select UserName from UsersPoints where Points >100) WHERE UserName NOT IN (select UserName from PrizeGiven where Points=100)"


But query is not working !!!

推荐答案

您在SQL语法中犯了一个错误.

You made an error in the SQL syntax.

SELECT up.UserName 
FROM UsersPoints up 
WHERE 
    up.Points >100 AND 
    up.UserName NOT IN 
        (SELECT pg.UserName 
         FROM PrizeGiven pg 
         WHERE pg.Points=100
        )



问候,

曼弗雷德(Manfred)



Regards,

Manfred


这篇关于使用两个表选择记录-嵌套SQL查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆