I am trying to create a table with two groups in a BIRT report.
I first group by year, and then by a criteria in a second column. Let's say this criteria is one of [A, B, C, D]. If there doesn't exist a criteria for a year, the default in BIRT is for it to be blank. For example, if 2011 didn't have any B or D criteria, my report would look like:
2010
----
A 1
B 2
C 3
D 4
2011
----
A 5
C 6
However, I want all the possible criteria to show up, even if they don't have any entries for a particular year.
I tried setting the property under advanced->section->show if blank = true, but that didn't do anything.
Any ideas?
(I am using birt 2.6.0)
The SQL query (connecting to a mysql datasource) is fairly simple:
SELECT year_field, decision_field, sales_field
FROM databaseName
The report is http://bit.ly/9SDbNI
And produces a report like:
As I commented earlier, this is a dataset issue, not a BIRT issue. The issue is that the dataset does not include rows where there were no sales for those decision codes, in those years.
I was rather hoping there would be separate tables for the years and decision codes, but it looks as though there's a single table for everything. Therefore, I suggest the following query (based on the query in the rptdesign file, rather than the question):
select y.year_field, d.decision_field, t.sales_field
from
(select distinct year_field from databaseTable) y
cross join (select distinct decision_field from databaseTable) d
left join databaseTable t
on y.year_field = t.year_field and d.decision_field = t.decision_field
Also, change the definition of the Count column to be a count of the sales field, rather than the decision field.
I noticed that you are using MySql. Use SELECT IFNULL(<MyCol>,0) from my_table; to replace the null values with 0.
Related
Is it possible to update 2 columns in an Update statement that are in different tables? - The reason for the"scripted":
Where "Scripted" will be the "flag" so the formula does not run again on the same records if this field is filled in.
MERGE INTO arinvt_lot_docs ALD
USING
(SELECT arinvt.id,arinvt.class,fgmulti.in_date fgmulti.cuser3 FROM arinvt,fgmulti
WHERE arinvt.class LIKE 'CP%'
OR arinvt.class LIKE 'FG%'
OR arinvt.class LIKE 'IN%'
OR arinvt.class LIKE 'LA%'
OR arinvt.class LIKE 'PK%') Classes
ON (ALD.arinvt_id = classes.id
AND to_date(in_date) = '31-Dec-2015') --just picked a date to validate
WHEN MATCHED THEN
UPDATE SET non_conform_id = '21', fgmulti.cuser3 = 'SCRIPTED' --this text "Scripted" will fill in a field that will tell us in our reports if this was set by the script
I would like to join the tables using the arinvt.id field that is present in all 3 tables ARINVT_LOT_DOCS, FGMULTI & obviously ARINVT. ARINVT_LOT_DOCS & FGMULTI contain the NON_CONFROM_ID field that needs to be changed to '21'. The FGMULTI table also contains the CUSER3 field that would have "SCRIPTED" entered in it. The ARINVT table contains the Class of the inventory item which reflects in the conditions mentioned.
You cannot update two tables in one query in Oracle and other DBMS such as SQL Server but you can use transaction to achieve similar result.
This oracle community answers exactly that, if you try to join two tables, you will get this error
ORA-01776: cannot modify more than one base table through a join view
You can use transactions to update two tables in batch-like statement.
This https://stackoverflow.com/a/2044520 shows how to do it but for SQL Sever though. You need similar statement in Oracle.
We have a transactional database with just 2 weeks of data and another archive database which holds data older than 2 weeks. Both DBs share the same schema structure and are in separate servers. We have a reporting application which queries data from both these databases where the user selects which database he wants to query by using a dropdown selection. In order to improve user experience we are thinking to do away with the dropdown selection by making the DB selection transparent in the background. Below are the few options we had in mind
Use UNION for the 2 select queries via DB links
Query DB1 first and if no records query DB2
Since the data volume is more we are apprehensive about our choices.
Appreciate if anyone has any other suggestions on how to approach this.
In my particular opinion, the best two choices are:
always give the user the data newer than a relative date (e.g. the last three months of data).
always give the user the last n data (e.g. the newest 250 rows).
Give all data will be inefficient when you have a big dataset.
But if you want to strengthen the autonomy and protect the user's work (two important design principles in user interfaces) then you must let the user configure the relative time or the number of data items desired. Or you can also let the user explore all/older data in particular situation (e.g. using a special window, a pagination system, a particular interface or a completly new use case).
Let's see two examples. (I assume that user is querying the server with newest data and OLD is the name of the dblink you use to reference the server with the data older than two weeks. I also assume that the target table is named DATATABLE and the column with the date is called DATADATE).
To retrieve the last three months (first choice):
SELECT * FROM DATATABLE
UNION ALL
SELECT * FROM DATATABLE#OLD WHERE MONTHS_BETWEEN(SYSDATE, DATADATE) >= 3;
And, to retrieve the last 250 rows (second choice):
SELECT *
FROM (SELECT * FROM DATATABLE ORDER BY DATADATE DESC)
WHERE ROWNUM <= 250;
UNION ALL
SELECT *
FROM (SELECT * FROM DATATABLE#OLD ORDER BY DATADATE DESC)
WHERE ROWNUM <= (250 - (SELECT COUNT(*) FROM DATATABLE));
I have a two datatable dt1 and dt2 (which are generated in runtime) and i have to apply inner join query on this table.(EmpId is same in both table)
but the no of coloumns and their names are dynamic which are depends upon databse.
both table contains same coloumn name like table 1 have coloumn this table contains leave taken by employee "p" .he have not taken any sickleave so value is null.
EmpId Empname SickLeave Casual Leave
1 P 1
and table two have values like
EmpId Empname SickLeave Casual Leave
1 P 5 5
this table contain total leave given by a copmany to a employee (Max leave)
i have to join this query and show result like this
EmpId Empname SickLeave Casual Leave
1 P 0/5 1/5
so i want to know how can i join this two datable and show result like this using Ef and LINQ. (no of leave given two i.e sick leave ,casual leave but it may be three or 2 or 4 depend upon databese and its name also can be chage accoding to databse)
if any one have an idea please guide me
If you really need dynamic Linq to entities then
OPTION A) string to lambda
Dynamic Expressions and Queries in LINQ
System.Linq.Dynamic can be found at following links
http://msdn.microsoft.com/en-US/vstudio/bb894665.aspx
http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx
http://www.scottgu.com/blogposts/dynquery/dynamiclinqcsharp.zip
How to convert a String to its equivalent LINQ Expression Tree?
OPTION B) Build expression trees
A more thorough approach is to build expression trees. Build expressions trees with code found here:
http://msdn.microsoft.com/en-us/library/system.linq.expressions.aspx
Dynamic LINQ and Dynamic Lambda expressions?
Ok, so i have database on PL/SQL.
Here is my sql question:
SELECT t.AC_NUMBER, t.DATE, a.comment_1, a.comment_2, a.comment_3, a.comment_4
FROM proddba.cust_info t
left join proddba.cust_descr a on a.ac_number=t.ac_number
where a.open_date=(select min(b.open_date)
from proddba.cust_descr b
where b.ac_number=t.ac_number
and b.open_date>=t.date
and b.open_dane<=t.date+7days)
How to dynamically add +7 days to date?
And second, how to get only one date min(b.open_date) if there is two this same datas? Should I use distinct?
(select distinct min(b.open_date)
from proddba.cust_descr b
where b.ac_number=t.ac_number
and b.open_date>=t.date
and b.open_dane<=t.date+7days)
If have to get about 15000 records from database, is this should work?
Best Regards
You can simply add a number of days to a DATE
t.date + 7
will add exactly 7 days to the DATE in t.date (so the time component will be preserved).
MIN will already cause the subquery to return a single data value-- there is no need to add a DISTINCT since it won't ever change the output. I'm not sure what problem you are trying to describe that results from getting multiple rows-- are you possibly concerned that the outer query returns two rows that have the same a.open_date value and you are trying to ensure that you get only one row?
I am new to Oracle and working with a fairly large database. I would like to perform a query that will select the desired columns, order by a certain column and also limit the results. According to everything I have read, the below query should be working but it is returning "ORA-00918: column ambiguously defined":
SELECT * FROM(SELECT * FROM EAI.EAI_EVENT_LOG e,
EAI.EAI_EVENT_LOG_MESSAGE e1 WHERE e.SOURCE_URL LIKE '%.XML'
ORDER BY e.REQUEST_DATE_TIME DESC) WHERE ROWNUM <= 20
Any suggestions would be greatly appreciated :D
The error message means your result set contains two columns with the same name. Each column in a query's projection needs to have a unique name. Presumably you have a column (or columns) with the same name in both EAI_EVENT_LOG and EAI_EVENT_LOG_MESSAGE.
You also want to join on that column. At the moment you are generating a cross join between the two tables. In other words, if you have a hundred records in EAI_EVENT_LOG and two hundred records EAI_EVENT_LOG_MESSAGE your result set will be twenty thousand records (without the rownum). This is probably your intention.
"By switching to innerjoin, will that eliminate the error with the
current code?"
No, you'll still need to handle having two columns with the same name. Basically this comes from using SELECT * on two multiple tables. SELECT * is bad practice. It's convenient but it is always better to specify the exact columns you want in the query's projection. That way you can include (say) e.TRANSACTION_ID and exclude e1.TRANSACTION_ID, and avoid the ORA-00918 exception.
Maybe you have some columns in both EAI_EVENT_LOG and EAI_EVENT_LOG_MESSAGE tables having identical names? Instead of SELECT * list all columns you want to select.
Other problem I see is that you are selecting from two tables but you're not joining them in the WHERE clause hence the result set will be the cross product of those two table.
You need to stop using SQL '89 implicit join syntax.
Not because it doesn't work, but because it is evil.
Right now you have a cross join which in 99,9% of the cases is not what you want.
Also every sub-select needs to have it's own alias.
SELECT * FROM
(SELECT e.*, e1.* FROM EAI.EAI_EVENT_LOG e
INNER JOIN EAI.EAI_EVENT_LOG_MESSAGE e1 on (......)
WHERE e.SOURCE_URL LIKE '%.XML'
ORDER BY e.REQUEST_DATE_TIME DESC) s WHERE ROWNUM <= 20
Please specify a join criterion on the dotted line.
Normally you do a join on a keyfield e.g. ON (e.id = e1.event_id)
It's bad idea to use select *, it's better to specify exactly which fields you want:
SELECT e.field1 as customer_id
,e.field2 as customer_name
.....