sql - DB2 SELECT statement using COUNT and GROUP BY -


I have a database that has a DB2 database in which I have a customer notification, how many times I have duplicated columns in a specific table . Here is an example of data.

  CUSTOMERID | Customs Group | PRODUCTID | PRODUCTNAME | ALERTNAME | Altelevel | XXX | YYY | ZZZ 12345 ABC 987654 Product A Alert 1 4 More data here   

The customer is identified by the Customer ID and Customer Group column. They can have any number of products and these products can get various types of alerts (product, productive and productive all alerts 1).

In our old MySQL database, it was not very difficult because I do something like

  customerID, customer group, productive, product name, alerts, count (alertname) Alert level, select more data ... from where the customer ID = XXX and client group = YYY Group Alert Level alert, alerts, product name   

I was not included in the Not been included tax shall, in which customer information back and several times received a specific warning.

Now that we have moved to DB2, then I have to put each column in the group by SELECT and it (obviously) separates each line and hence the counting is coming back every now 1 for the line, regardless of whether a warning name matches another line for this customer.

Is there a way to rebuild this functionality, which would not require significant overhaul of the way the data is retrieved? As front-facing developer, I have the ability to manipulate data on PHP and I can write SQL statements, but I have no choice but to change the way the data is stored.

What you can do with analytical functions:

  Select customerID, customergroup, ProductID, ProductName, AlertName, AlertCount, Alert Level, More Data ... as AlertConnect (with Alert Name), (COUNT) * From (Select AlertCount), ROW_NUMBER () According to the Order (Order by Customer ID by order of AlertName), WHERE Customer ID = XXX and Customer Group = YYY as Sanknam from table) where SEQNUM = 1 alert Order by level, alertname, product name;    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -