首页 \ 问答 \ 查询以获取订单小于先前订单的客户列表(Query to get list of customers whose orders are less than the previous order)

查询以获取订单小于先前订单的客户列表(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
更新时间:2022-06-27 20:06

最满意答案

事实证明,如果你的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 ...
  • 我理解你的问题是如何将XML文件读入Document ,对吧? 有几种方法和库可以从文件中读取XML: Java:如何读取和写入xml文件? 例如: String fileName = ""; // Set path to file DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Documen ...
  • 从Servlet类创建一个对象并调用该方法: public class Output extends HttpServlet { @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Predicts p = new Predicts(); p.predict(); } } Cre ...
  • 您想要做的语法是: 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 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)