查询以获取订单小于先前订单的客户列表(Query to get list of customers whose orders are less than the previous order)
我正在尝试编写一个sql来获取客户列表,其总订购单位始终小于之前的订单。 如在第n顺序中的总数量小于第n-1阶的总数量等
SQL创建和填充表
create table orders (order_id int, customer_id varchar(5), order_date date, product_id varchar(5), quantity int); Insert into orders values(01,'C1','2000-01-01','P1',10); Insert into orders values(02,'C2','2002-01-01','P2',15); Insert into orders values(03,'C3','2002-04-01','P3',17); Insert into orders values(04,'C4','2003-04-01','P1',20); Insert into orders values(05,'C4','2006-01-01','P2',1); Insert into orders values(06,'C1','2006-05-01','P5',7);
我假设我需要根据Order_id序列号编写一个过程和LOOP。 一旦进入循环,我需要选择对应于order_id的product_id和数量Q. 然后检查是否对于相同的order_id,是否有任何其他数量Q1小于Q.如果是,则打印customer_id。 如果没有,则order_id移动到下一个order_id。
我不确定如何实现我检查数量列的部分,以检查订单是否还有其他数量Q1 <Q for order_id?
请澄清
I am trying to write a sql to get the list of customers whose total ordered units is consistently lesser than the previous order. As in Total Qty in nth order is less than Total qty in n-1 th order, etc
SQL to create and populate table
create table orders (order_id int, customer_id varchar(5), order_date date, product_id varchar(5), quantity int); Insert into orders values(01,'C1','2000-01-01','P1',10); Insert into orders values(02,'C2','2002-01-01','P2',15); Insert into orders values(03,'C3','2002-04-01','P3',17); Insert into orders values(04,'C4','2003-04-01','P1',20); Insert into orders values(05,'C4','2006-01-01','P2',1); Insert into orders values(06,'C1','2006-05-01','P5',7);
I am assuming that I need to write a procedure and LOOP based on Order_id serial number. Once in loop, I need to pick the product_id and quantity Q corresponding to order_id. Then check whether for the same order_id there is any other quantity Q1 that is less than Q. If so, then I print the customer_id. If not, then the order_id moves to next order_id.
I am not sure how to implement the part where I check the quantity column to check whether there is any other quantity Q1 < Q for order_id?
Please clarify
原文:https://stackoverflow.com/questions/40009984
最满意答案
事实证明,如果你的pojo类是一个内部类,虽然你将能够将记录写入数据库,但是你很难用mongojack将它从mongo序列化回pojo。 一旦我从与我的测试相同的文件中提取TestObject,一切正常。
注意:当我正在开发我正在开发的应用程序中使用新概念或框架时,我会从单元测试中测试它们,并且我经常将我的类编写为测试中的内部类,以便它们就在前面我在玩耍的时候。 如果我想使用任何这个实验代码,那么如果它们最终有用,则提取类,或者如果它与我正在做的事情没有进一步关联,则删除测试。
It turns out that if your pojo class is an inner class, although you will be able to write records to the db you will have a bad time trying to serialize it back from mongo into the pojo using mongojack. Once I had extracted TestObject from the same file as my Test everything worked.
Note: When I'm playing around with new concepts or frameworks in an application I'm developing I test them from a unit test and I'll often write my classes as inner classes within the test just so that it's all there in front of me while I'm playing around. If I want to use any of this experiment code I then extract the classes if they end up being useful or remove the test if it has no further relevance to what I'm doing.
相关问答
更多-
编辑: Exception在你的SetPassword类中,不在这一个帖子中发布setpassword的代码或检查SetPassword类中的第32行。 检查你在应用程序的android清单文件中所采取的主题,即你当前的主题是否有动作栏因为你写了getActionBar()。hide(); 在代码中,如果您选择的主题没有操作栏,则可能会抛出异常。 Edit: The Exception is in your SetPassword class not in this one post the code of ...
-
sayHello.invoke(this, null); 第一个参数应该是SimpleService 。 将其更改为: sayHello.invoke(helloClass.newInstance(), null); 为清楚起见,您可以像这样更改代码: sayHello.invoke(helloClass.newInstance(), (Object[]) null); 或这个: sayHello.invoke(helloClass.newInstance()); 否则可能被误解为: sayHell ...
-
调用和测试java方法(Calling and Testing java method)[2021-12-25]
我理解你的问题是如何将XML文件读入Document ,对吧? 有几种方法和库可以从文件中读取XML: Java:如何读取和写入xml文件? 例如: String fileName = ""; // Set path to file DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Documen ... -
在servlet中调用方法(calling method in servlet)[2023-09-26]
从Servlet类创建一个对象并调用该方法: public class Output extends HttpServlet { @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Predicts p = new Predicts(); p.predict(); } } Cre ... -
方法调用问题(Method calling issue)[2023-04-27]
您想要做的语法是: ACR122U.super.open(params[0]); 但是,如果您正在讨论java.io.Reader ,那么这不会起作用,因为Reader类没有定义open()方法; 当然不是一个open(UsbDevice)方法。 The syntax for what you want to do is: ACR122U.super.open(params[0]); However, if you're talking about java.io.Reader, this isn't ... -
我解决了它。对于其他人也可能会遇到相同类型的问题......我删除了静态关键字,如Parkash和KLajdPaja所提到的,并将该方法称为StudentLocalServiceUtil.getStudentByGenderMale() 。错误消失... I solved it..It might be useful to others also going through same type of problem...I removed the static keyword as Parkash and ...
-
在运行时,异常会唤起调用堆栈,直到发生以下情况之一: 它被抓到一个Catch块 它被全局异常处理程序捕获 它不会被用户代码捕获并显示一般的异常消息 在调试情况有点不同时,因为调试器可以设置为在未处理的用户异常时中断。 这可能是你的情况发生了什么。 检查Visual Studio选项Debug / Exceptions以查看您的调试器是否设置为在任何未处理的异常在用户代码冒出和冒出之前捕获。 At runtime, the exception will bubble up the call stack unt ...
-
事实证明,如果你的pojo类是一个内部类,虽然你将能够将记录写入数据库,但是你很难用mongojack将它从mongo序列化回pojo。 一旦我从与我的测试相同的文件中提取TestObject,一切正常。 注意:当我正在开发我正在开发的应用程序中使用新概念或框架时,我会从单元测试中测试它们,并且我经常将我的类编写为测试中的内部类,以便它们就在前面我在玩耍的时候。 如果我想使用任何这个实验代码,那么如果它们最终有用,则提取类,或者如果它与我正在做的事情没有进一步关联,则删除测试。 It turns out t ...
-
好的,我让这个工作。 它与加载库无关,但实际上是从该库调用该方法。 我通过你的问题中的复制/粘贴创建了.java , .h和.cpp文件并运行它们(我必须在.cpp文件中添加#include
) - 并且得到了与你完全相同的错误。 然后我编辑了.cpp文件以包含生成的.h文件。 另外,正如maba在答案中指出的那样,你需要调用(jni_env)->ReleaseStringUTFChars(msg, message); 释放对象。 我的完整.cpp文件现在看起来像这样: #include " ... -
NoClassDefFoundError正在发生,因为multidex只在这个应用程序中部分实现 - 出于某种原因,这在Android 5/6上工作正常,但在Android 4.x上它会使你的应用程序在随机位置使用NoClassDefFoundError崩溃。 在我看来,这种情况应该被Android Studio检测到,你应该被警告你已经不正确地实现了multidex支持。 要解决此问题,请确保您的项目符合以下条件: 应用级build.gradle的defaultConfig部分中的multiDexEnab ...