Retrieve list of accounts with specific classification - exact-online

I want to retrieve a list of customer names and a list of the assigned account manager and region as registered using a custom property.
Using the following query, I get multiple lines per customer:
select accountclassifications_account_name
, property_code_attr
, property_description
from exactonlinexml..accountclassifications
where property_code_attr in ( 'BO', 'REGION' )
But I would like to have one field with both the account manager and region. How to do this?

Using the group function listagg you can retrieve multiple values per customer account:
select accountclassifications_account_name
, listagg(property_code_attr || ': ' || property_description) lst
from exactonlinexml..accountclassifications
where property_code_attr in ( 'BO', 'REGION' )
group
by accountclassifications_account_name
When you need a different separator, you can specify it as a separate parameter to listagg.

Related

Mysql Query for fetching records using single Query from three tables

We have three table
table 1- app ( id , name )
table 2- appPlayer ( id , name )
table 3- appPlayerSession ( id , appId , appPlayerId , version)
my Current query is:
SELECT (select name from app k where k.id= aps.appId) AS appName,version,appId,count(version) FROM appPlayerSession aps GROUP BY appId,version,appName
we need to count the session users for each game with same version, and also woth the object of all users data using single mysql query.
Current Result using my query, but we also need players for each app..
As you havent given your expected result and on basis of your requirement you can do something this.it may be enhanced as per your requirement.
SELECT (select name from app k where k.id= aps.appId) AS appName,version,appId,(select P.name from appPlayer P where P.id=aps.appPlayerid) as appPlayerName, count(version) FROM appPlayerSession aps GROUP BY appId,version,appName,appPlayerName
Also check fiddle as per your requirement created as you havent given any data set and its on my assumption.
http://sqlfiddle.com/#!9/30fe4f/1
New Sql as per your new added requirement-
select X.appname,X.version,X.appid,GROUP_CONCAT(distinct X.appPlayerName order by X.appPlayerName) as Users ,
sum(X.vercount)
from (SELECT (select name from app k where k.id= aps.appId)
AS appName,version,appId,
(select P.name from appPlayer P where P.id=aps.appPlayerid)
as appPlayerName, count(version)as vercount
FROM appPlayerSession aps
GROUP BY appId,version,appName,appPlayerName) X
group by X.appname,X.version,X.appid
New fiddle -http://sqlfiddle.com/#!9/13646c/5
You can use JOIN in sql to connect with multiple tables and fetch result
Below is the format :
SELECT t1.col, 
       t3.col 
FROM   table1 
       JOIN table2 
         ON table1.primarykey = table2.foreignkey 
       JOIN table3 
         ON table2.primarykey = table3.foreignkey 
In your case :
SELECT app.col, 
       appPlayer.col,
appPlayerSession.col 
FROM   app 
       JOIN appPlayer 
         ON app.id = appPlayer.appId
       JOIN appPlayerSession 
         ON appPlayer.id = appPlayerSession.appPlayerId
Hope this is helpful.
One suggestion . It is not a standard to use camelCase for table and column names. snake_case is preferred widely.

Looking for a dax function to create an insight to shows all duplicates based on multiple criteria

I'm trying to develop a calculated field within a powerbi report and more importantly an output that I can make into an insight that shows duplicate accounts , that are created with data with criteria matching in multiple columns. For example, give me all accounts that have the same following: Client Name, Provider Name, Date of service, time beginning, time ending, and procedure code. To clarify, there are duplicate accounts in my system due to user error generating more than once, but they do not have the same account number. Too many clients and providers to spell out all the names, so need it to calculate based on what's in each column.
count rows, calculate withing power query editor and in the modeling screen. I run into a ton of token literal errors, and token comma expected errors. When I get no exceptions, it doesn't recognize the expression and doesn't load.
countifs=calculate(
countrows ( Table ),
filter (
table,
table[Client Name] = [Client Name]
& table[Provider Name] = [Provider Name]&[Date Of Service]=[Date Of Service]&[Time started]=[Time started]&[Time ended]=[Time ended]&[billing_codes_and_labels.code]=[billing_codes_and_labels.code]
)
)
I'm looking to grab all duplicate accounts according to the user who's creating for them to be able to delete the duplicate accounts in the system. It will be a matrix report with splicers on each user. The unique values are going to have an output of more than 1, of which this is what the user will be focused on.
With variables, the duplicate count is much cleaner than using the EARLIER function (which was used before there was variable in Power BI). Please see:
countifs =
VAR cName = 'table'[Client Name]
VAR pName = 'table'[Provider Name]
VAR dService = 'table'[Date Of Service]
VAR tStarted = 'table'[Time started]
VAR tEnd = 'table'[Time ended]
VAR bCode = 'table'[billing_codes_and_labels.code]
RETURN
CALCULATE (
COUNTROWS ( 'table' ),
FILTER (
'table',
'table'[Client Name] = cName
&& 'table'[Provider Name] = pName
&& 'table'[Date Of Service] = dService
&& 'table'[Time started] = tStarted
&& 'table'[Time ended] = tEnd
&& 'table'[billing_codes_and_labels.code] = bCode
)
)
Thanks

How to use grouby and count using laravel ORM?

I have an address table where there are many fields like city, ward, tole, district, latitude, longitude. I need to count the number of rows for distinct district. For eg I have following database table as show in screenshot:
I have the rows containing Kathmandu, Bhaktapur and Jhapa as districts. Now I need to get the number of rows containing Kathmandu as district and likewise.
The output should be like this:
array( "Kathmandu"=> 4 , "Bhaktapur" => 1 , "Jhapa"=>1 );
I found multiple solution to the problem in which DB query is used. But I need it ORM way.
You could use aggregated query
$districts = DB::table('address')
->select('district', DB::raw('count(*) as total'))
->groupBy('district')
->pluck('total','district')
->all();

How to add payment conditions to AR outstanding items in a report on Exact Online?

I am using Invantive Control to create an Excel report with some outstanding invoices information from Exact Online.
I have created a model with the block designer and I have the outstanding invoices information I need. Now I also want to know the payment condition of the account which is in debt, but there is no information on the payment condition on the AROutstandingItems table.
This is the query I have so far:
select division_code
, division_name
, number_attr
, outstandingitems_ar_account_code_attr
, outstandingitems_ar_account_name
, description
, invoicedate
, duedate
, currency_code_attr
, invoiceamtfc
, outstandingamtfc
, invoiceamtdc
, outstandingamtdc
from aroutstandingitems
order
by division_code
, outstandingamtdc desc
How can I add the payment condition to my report?
Payment conditions are referenced from the account on the outstanding items. In order to get the (sales) payment conditions on an account, there are several options.
Join the Accounts table and get the payment condition from there (from the field salespaymentcondition_code_attr and salespaymentcondition_description).
The SQL would look like this then:
select ...
, act.salespaymentcondition_code_attr
from aroutstandingitems aom
join exactonlinexml..accounts act
on aom.outstandingitems_ar_account_code_attr = act.code_attr
Use an Excel function to get the payment condition: I_EOL_ACT_SLS_PAY_CODE.
The formula has two parameters: division_code and account_code_attr. The first is optional.
A valid call to the formula would thus be: =I_EOL_ACT_SLS_PAY_CODE(,"22") for the payment condition code for account with code 22 in the current Exact Online company. You can incorporate that in your SQL like this:
select ...
, '=I_EOL_ACT_SLS_PAY_CODE("' + division_code + '", "' + outstandingitems_ar_account_code_attr + '")'
pcn_code
from aroutstandingitems
That would result in your model on sync receive the formula for retrieving the payment condition code. Remember to check the check box 'Formula' to ensure that the SQL outcome is treated as an Excel formula.
The same as above, but then using column expressions:
select ...
, '=I_EOL_ACT_SLS_PAY_CODE("$C{E,.,.,^,.}";"$C{E,.,.,^+3,.}")'
pcn_code
from aroutstandingitems
Remember to check the check boxes 'Formula' and 'Column expression' to ensure that the SQL outcome is treated as an Excel formula with $C column expressions.
The recommended option is to use column expressions, since these work across the widest range of deployment scenarios such as accountancy with hundreds of companies and the formulas are upgrade safe. SQL statements may need to be adapted with new releases of the Exact Online data model of Invantive.

where clause in COUNT function and joining two queries

I have a table that I am trying to count the number of course passed, and also list the modules passed as well.
The first problem I am having is what to put in the where variable, so that its not specific to a customer(I can use the query below for a particular customer and a particular course)but I will like a generic query where the result will be distinct in terms of user and course like the one below
SELECT FirstName
,LastName
,CourseTitle
,Noofmodules
,count(Coursecompleted) AS modulescompleted
FROM EStudentsprogress
WHERE Coursecompleted = '1'
AND EmailAddress = 'scascsc#e.co.uk'
AND CourseTitle = 'Microsoft MOS 2010 EXCEL'
GROUP BY FirstName
,LastName
,CourseTitle
,Noofmodules
How can I make it list the result as above, whereby I don't specify the email address or course title(trying to get the result for all the clients )
Also I have a query that list the courses that is passed by the customer, I will like the column with the list of courses passed be added to the result above, but as a column for each course.
SELECT FirstName
,LastName
,CourseTitle
,EmailAddress
,CourseModule AS coursepassed
FROM EStudentsprogress
WHERE coursecompleted = 1
Cheers
Can you not just add the email address and course title fields to the select fields and the GROUP BY clause.
Also you can use GROUP_CONCAT to bring back a field containing all the course modules.
Something like this:-
SELECT FirstName,
LastName,
CourseTitle,
Noofmodules,
EmailAddress,
CourseTitlecount,
COUNT(Coursecompleted) as modulescompleted,
GROUP_CONCAT(CourseModule) as modulescompletednames
FROM EStudentsprogress
WHERE Coursecompleted = '1'
GROUP BY FirstName, LastName, CourseTitle, Noofmodules, EmailAddress, CourseTitlecount ;