查询比较2个表中的价格并执行消息

时间:2016-09-23 13:09:55

标签: java sql-server

我被困了好几天我正在尝试构建一个sql query来检查我的产品是否需要订购....所以我想要的是一个查询进行检查

我有Priority_lvl一个columns Prio_level ,Prio_Number的表first column已经在second column内的值包含了exable'law','medium'的值..... 。'50','100'有数字Products

我的第二个表columns Pro_Quantity column有我的产品容量。我的其他Pro_Capa_level Prio_level的值为Pro_Quantity,我已插入其他查询。

所以我需要一个查询,告诉我Prio_Number列是否小于Pro_Capa_level每次依赖Priority_lvl是产品....

CREATE TABLE [dbo].[Priority_lvl]( [Prio_id] [int] IDENTITY(1,1) NOT NULL, [Prio_level] [varchar](50) NOT NULL, [Prio_Number] [int] NOT NULL ) ON [PRIMARY]

Products

CREATE TABLE [dbo].[Products]( [Pro_Id] [int] NOT NULL, [Pro_Name] [varchar](50) NOT NULL, [Pro_Price] [float] NULL, [Pro_Quantity] [int] NULL, [Pro_Supplier_id] [int] NOT NULL, [Pro_Tax] [float] NOT NULL, [Cat_products] [varchar](50) NULL, [Pro_Capa_level] [varchar](50) NULL, CONSTRAINT [PK_Products] PRIMARY KEY CLUSTERED ( [Pro_Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY]

SELECT * FROM Products P INNER JOIN .Products ON   Products.Pro_Capa_level= Priority_lvl.Prio_level WHERE Pro_Capa_level = Prio_level  AND Pro_Quantity<=Prio_Number ;

这是我的尝试,但很糟糕

public ArrayList<Update_del_insert_products> getproList()
     {
         ArrayList <Update_del_insert_products> proList =new ArrayList <Update_del_insert_products> ();
         Connection connection =getConnection();
           SELECT * FROM Products P INNER JOIN .Products ON   Products.Pro_Capa_level= Priority_lvl.Prio_level WHERE Pro_Capa_level = Prio_level  AND Pro_Quantity<=Prio_Number ;
         Statement stt;
         ResultSet rss;
         try{
            stt = connection.createStatement();
            rss = stt.executeQuery(query);
            Update_del_insert_products  update_del_insert_products ;
            while(rss.next())
            {
               update_del_insert_products = new Update_del_insert_products (rss.getString("Pro_Id"),rss.getString("Pro_Name"),rss.getString("Pro_Price"),rss.getString("Pro_Quantity"),rss.getString("Pro_Supplier_id"),rss.getString("Pro_Tax"),rss.getString("Cat_products"),rss.getString("Pro_Capa_level"));
               proList.add(update_del_insert_products);
            }
            }catch (Exception e){
                e.printStackTrace();
            }
         return proList;
     } 

这是我的执行

public function update($id, Request $input)
    {
        if ($this->notFound($id)) {
            return $this->response->notFound();
        }

        $input = $this->converter->convert($input);
        $this->model->where("id", $id)->update($input);

        return $this->response->updated();
    }


private function notFound($id)
    {
        return !count($this->model->find($id));
    }

1 个答案:

答案 0 :(得分:0)

String query ="SELECT * FROM Priority_lvl INNER JOIN Products ON 
Products.Pro_Capa_level= Priority_lvl.Prio_level WHERE Pro_Capa_level = Prio_level 
AND Pro_Quantity<=Prio_Number ";