如何为我的要求编写SQL查询。 [英] how to write sql query for my requirement.

查看:67
本文介绍了如何为我的要求编写SQL查询。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两张桌子,学生和费用。学生表包含学生相关数据和费用表包含学生的费用记录。



实际上,我的问题是我想展示那些没有支付这个月费用的违纪学生。



Sol。在我看来是:

我想首先从学生表中搜索所有学生,然后查询应在费用表中搜索尚未支付本年度当月费用的学生。\



我的问题是如何根据我的上述要求编写查询。

I have two tables, Students and Fees. Students table contains Student Related Data and Fees table contains Fee record of Students.

Actually, My problem is i want to show defaulter students who have not paid this month fee.

Sol. seems to me is :
I want to search all Students first from Students table, then query should search in Fee table for students who have not paid their fee of this month of Current Year..\

My Question is How to write query for my above requirement.

推荐答案

有很多方法可以做这个。一种方法是将两个表中的数据检索到代码中的结构中,然后您可以遍历它们,查找您的学生类中有值但在费用类中没有相应条目的实例。你可以这样做,但我不推荐它。



另一种方法是使用SQL的功能并执行选择同时查看两个表的,可能加入以某种方式将它们组合在一起;考虑到你要找的东西不会出现,所以你的加入 ing需要考虑到这一点 - 可能会优先考虑 加入的手边 ing。
There are many ways you could do this. One way could be to retrieve the data from both tables into structures in your code, then you could iterate through them looking for instances where you have a value in your student class but no corresponding entry in the fee class. You could do this, but I wouldn''t recommend it.

Another way to do this would be to use the features of SQL and perform a select that looked at both tables simultaneously, possibly joining them together somehow; taking into account that what you are looking for wouldn''t be present, so your joining will need to take this into account - possibly giving preference to the table at the left or right hand side of the joining.


我建​​议你参考下面的链接来学习SQL。然后通过Pete给出的上述解决方案。这应该可以让您了解如何处理您的问题。

SQL教程 [ ^ ]

SQLCourse.com [ ^ ]



您可以在 Google [ ^ ]或者您可以参考CP中有关SQL的初学者文章此处 [ ^ ]
I would recommend you to refer the below links to learn SQL. Then go through the above solution given by Pete. That should give you an idea on how to approach your problem.
SQL Tutorial[^]
SQLCourse.com[^]

You can find more resources on SQL in Google[^] or you can refer to beginner articles on SQL in CP here[^]


这篇关于如何为我的要求编写SQL查询。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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