I've got a problem with an order by.
I have this table
|desc|phone|calls|group|priority|
|cccc|12347|700|13247|0|
|aaaa|12345|900|12345|0|
|bbbb|12346|500|12345|1|
I need to order this table for calls respecting the group, so my result should be
|desc|phone|calls|group|priority|
|aaaa|12345|900|12345|0|
|bbbb|12346|500|12345|1|
|cccc|12347|700|13247|0|
because bbbb is with the same group of aaaa.
How can I do this?
Thanks
EDIT:
Hi all,
sorry if my question is unclear, next time I'll be more specific.
Yes, I need to order this table for calls respecting the group, like if bbbb doesn't exists
Since your question is a bit unclear, An order by is enough
select * from sample order by "group"
sqlfiddle-demo
Related
I am having a serious issue in tableau when comparing the current month value to the current month target. I am currently using data blending for this purpose. But this issue wont solve even if I use tableau relationship joining. I have 3 join clauses. Such as branch ID, Staff ID and Month/year. Pls see the below
Ex - january Target - 95,000
Actual - 126,000
But when 3 joining clauses created, its dropping data to 111,900.
the reason is in january, even the allocated branch ID and month is matching, the other staff id clauses are dropping off. That means even though the table A has all branches , staff ID's and date key, the txn table is having only one staff ID maching for January. If the 3 matches are not satisfying , data is dropping itself. How to solve this isseue? I need to show the total value of 126,000 infront of 95,000. not 111,900.
Hope anyone can help.
Many thanks
This got achieved by a table unioning.
Seems like this could have been solved by changing the join type from an inner join to a right join.
I'm using SQL in Devexpress dashboard designer. I want to select distinct combinations of two parameters.
Perhaps Devexpress uses Transact-SQL but at the same time GROUP BY clause never works for me.
At the same time DISTINCT BY somehowe doesn't work as well.
Example:
There are two IDs 11 and 22
And there are two values of Date for 11, as an example: 21.01.2000 and 22.01.2000. And there's one for 22 as an example: 23.05.2008
Problem here is that I can't coose DISTINCT by date because there are many other IDs which have the same dates.
So I expect to have one distinct combination of ID and Date.
Does anyone faced with the same problem, can you advice any solution / code example?
Using select distinct will filter duplicates if you leave unique row properties out of the selected fields.
so:
Mike Smit
Mike Smit
Will be reduced to
Mike Smit
But if you're also asking for a PK like a Id field you get the following because id makes both rows distinct
1 Mike Smit
2 Mike Smit
Does this help?
I need to group a table by the sum of a NUMC-column, which unfortunately seems not to be possible with ABAP / OpenSQL.
My code looks like that:
SELECT z~anln1
FROM zzanla AS z
INTO TABLE gt_
GROUP BY z~anln1 z~anln2
HAVING SUM( z~percent ) <> 100 " percent unfortunately is a NUMC -> summing up not possible
What would be the best / easiest practices here as I cannot alter the table itself?
Unfortunately the NUMC type is described as numerical text, so at the end it lands in the database as VARCHAR and that is why the functions like SUM or AVG cannot be used.
It all depends on how big your table is. If it is rather small you could get the group fields and the values for sum into an internal table and then sum it using COLLECT statement and eventually remove the rows for which the sum is equal 100%.
One solution is to define the field in the table using a more appropriate type.
NUMC is often used for key fields - like document numbers, which there would never be a reason to add together.
I didn't find a smooth solution.
What I did, was to copy everything in an internal table, looped over it converting the NUMC values to DEC values. Grouping and summing up worked at that point.
At the end, I converted the DEC values back to NUMC values.
It's been awhile. I came back to this post, because someone voted up my original answer. I was thinking about editing my old answer but I decided to post a new one. As this question was asked in 2017, there were some restictions but now it can be done by using CAST function in new OpenSQL.
SELECT z~anln1
FROM zzanla AS z
INTO TABLE #gt_
GROUP BY z~anln1, z~anln2
HAVING SUM( CAST( z~percent AS INT4 ) ) <> 100
While doing a Group By In KDB. I have to find the first not null value in that group for a column
For e.g.
t:([]a:1 1 1 2;b:0n 1 3 4 )
select first b by a from t
I found one way to achieve this is:
select first b except 0n by a from t
I am not sure if it is a correct way to do this. Please provide suggestions.
It seems a good way to do it to me.
Two alternatives would include:
select first b where not null b by a from t
Benefit being it doesn't rely on a certain column type, maybe more clearly explains your intent but it is slightly longer. Or
select b:last fills reverse b by a from t
Which on some test runs was the quickest way.
In kdb there's always multiple ways to do things and never really a right or wrong answer.
I am using
OS - Windows 7,
technology - progess 4gl.
I have two tables customer and order. I am displaying customer details along with their orders. Each customer may have more then one order. The report should be as below
CUSTOMER:-
CUMTOMER NAME ADDRESS
CUSTOMER1 XYZ
ORDER1 OF CUSTOMER1:-
ORDER NO. ORDER DETAILS
1 ASD
2 ASDFGGH
3 FGHJFG /* IT SHOULD REPEAT FOR THE PARTICULAR CUTOMER */
CUSTOMER2 ABC
ORDER1 OF CUSTOMER1:-
ORDER NO. ORDER DETAILS
1 ZXC
2 VNVN
3 JJLK
I Think for this we need one-many relationship between customer and order table. I have only customer and order temp-tables for doing this.Can you please tell me How to repeat the loop inside customer and how to link the tables in one-many relationship. Thanks in advance.
you should write a stored procedure and then link that SP with your report.
I don't know why you would need anything more complicated than a join.
Something like:
select * from customer, order where order.custNum = customer.custNum.
Having said that -- you might find this Progress Knowledgebase article relevant. Some versions of Crystal apparently produce SQL that might need to be adjusted:
http://knowledgebase.progress.com/articles/Article/18979
It sounds like you are just having an issue with how it is shown, I would join the table like Tom suggested order.custNum = customer.custNum
but in the Design section I would do the following:
GH1a Customer Name
GH1b Customer Information
GH2 Order Number
Det Order Information
you could also place all of the Customer Information (name, addr, etc) into a formula so that if the customer doesn't have all the data filled in it won't be shown, and won't show a blank line.