获取两个sql server行之间的区别 [英] Get difference between two sql server rows

查看:100
本文介绍了获取两个sql server行之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

向大家致敬。



我的样式表格如下:



Salutation to you all.

I have my sq l table in the example format below:

id      Stud          Amount    Sem

2       007           5600      SemI
3       002           4500      Sem1 
4       001           5600      SemI
5       007           4500      Sem1I
6       001           5600      SemII
7       002           4500      Sem1
8       002           4500      Sem1I
9       005           4500      SemII







如何编写Sql查询以仅获得仅以semII付款且不以semI付款的学生。

Eg学生005



感谢您的支持



已添加代码块 - OriginalGriff [/ edit]




How can i write an Sql query to get only those students who have made payments in semII only and NOT in semI.
E.g. Student 005

Thanks for your support

[edit]Code block added - OriginalGriff[/edit]

推荐答案

SELECT t1.stud FROM table1 t1 WHERE  t1.sem='semII' AND  NOT EXISTS
(SELECT * FROM table1 t2 WHERE t2.sem='semI' AND t1.stud=t2.stud)


尝试:

Try:
SELECT Stud FROM MyTable a
JOIN (SELECT stud, COUNT(sem) AS sems
      FROM MyTable
      WHERE Sem='SemI' OR Sem='SemII'
      GROUP BY Stud) b
ON a.Stud = b.Stud
WHERE b.sems=1 AND a.Sem='SEMII'


你可以做到......借助于条件......



其中条件的使用方式与bool条件相同。例如

hi you can do it...with the help of where condition...

Where Condition is used like that a bool condition. for example is
select count(*) from TableName where columnname="Condition Value"





如果上述查询返回1则条件为真,其他条件为假。

试试这个



if the above query is return 1 then where condition is true other wise condition is false.
try this

Select * from Student where sem='SemII'





任何查询回复..



for any query hit to reply..


这篇关于获取两个sql server行之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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