rajuchacha007 Posted April 22, 2010 Share Posted April 22, 2010 Hi,I am using mysql query to generate a report. I would like to know can whether we can use group by clause on data itself? Let me elaborate. Let'ss asssume I have following table called employee and database is myrecords.--------------------------------------------------------------------------------------------------------------------------------------------------------------id name accountno city descrption sex--------------------------------------------------------------------------------------------------------------------------------------------------------------1 abc 100 NY senior executive m2 pqr 200 NY senior executive f3 xyz 300 NY senior executive m4 stu 400 LON technical expert f5 def 500 PAR senior executive m6 rth 600 HR m7 uty 700 HR f8 ytt 800 technical expert --------------------------------------------------------------------------------------------------------------------------------------------------- Now I want to display the records based on the description. Partiularly, I am looking for the data based on description only "senior executive" and "HR". I do not wish to take any other records. In short, I am looking for the data based on the data. Can I extract data from data? Therefore, I am using group by description clause. How can I use it?select employee.id,employee.name,employee.accountno,employee.city,employee.descriptionfrom employee group by employee.description order by employee.idAny suggestions or ideas friends? Best regards. Link to comment Share on other sites More sharing options...
slow Posted April 22, 2010 Share Posted April 22, 2010 uhm... I think I don't fully understand your problem because the solution seems too simple...why don't you use the HAVING clause (see mysql syntax)http://www.databasejournal.com/features/mysql/article.php/3469351/The-HAVING-and-GROUP-BY-SQL-clauses.htmanother way is to use the jasper report (or IReport :) ) filter expression... are you sure your query is correct?reading it:select employee.id,employee.name,employee.accountno,employee.city,employee.descriptionfrom employee group by employee.description order by employee.idI think you are in confusion about the use og Group in SQL syntax and Group in IReport...from wikipedia: The GROUP BY clause is used to project rows having common values into a smaller set of rows. GROUP BY is often used in conjunction with SQL aggregation functions or to eliminate duplicate rows from a result set. The WHERE clause is applied before the GROUP BY clause. The HAVING clause includes a predicate used to filter rows resulting from the GROUP BY clause. Because it acts on the results of the GROUP BY clause, aggregation functions can be used in the HAVING clause predicate.if you select all details of a single employee... i think without aggregation functions GROUP BY hasn't effect.your query can be:select employee.id,employee.name,employee.accountno,employee.city,employee.descriptionfrom employeewhere employee.description = 'senior executive' OR employee.description = 'HR'order by employee.id ____________________________________if it works... give me KARMA points please! : ) Post Edited by slow at 04/22/2010 08:08 Link to comment Share on other sites More sharing options...
rajuchacha007 Posted April 22, 2010 Author Share Posted April 22, 2010 Your solution is right. I showed me some positive direction although it didn't work in my example. Karma is given. Thank and best regards. Link to comment Share on other sites More sharing options...
rajuchacha007 Posted April 22, 2010 Author Share Posted April 22, 2010 Will you please let me know any example of filter expression in ireport? Link to comment Share on other sites More sharing options...
slow Posted April 22, 2010 Share Posted April 22, 2010 A Filter Expression is a Boolean returning expression applied to each detail-row of your report...if the row satisfy the expression (returning new Boolean(True)) then it's printed.suppose you have a query like this (it's a dummy query!)select 1 as val from dualunionselect 2 as val from dualunionselect 3 as val from dualunionselect 4 as val from dualunionselect 5 as val from dualunionselect 6 as val from dualunionselect 7 as val from dualand you create a filter expression like:new Boolean($F{VAL}.intValue()>5)then the result contains olny two rows... val=6 and val=7...it is similar to set a WHERE condition in a SQL statement (that i prefer...)(where val>5)It can be edited from report->edit query->filter expression ____________________________________if it works... give me KARMA points please! : ) Post Edited by slow at 04/22/2010 10:14 Link to comment Share on other sites More sharing options...
rajuchacha007 Posted April 22, 2010 Author Share Posted April 22, 2010 Hey Thanks....I am using ireport 3.7.1. Have you got any documentation about this particular edition? Link to comment Share on other sites More sharing options...
slow Posted April 22, 2010 Share Posted April 22, 2010 NO , sorry... :)I use a very old IReport version due an old inherited application... :) but it works fine. ____________________________________if it works... give me KARMA points please! : ) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now