Showing posts with label Query. Show all posts
Showing posts with label Query. Show all posts

November 05, 2018

SQL Where IN Having and Group by Query Sample

customer table



select * from customer where country = 'IN'



select * from customer where country in ('in','us');


select * from customer having country = 'in'




select * from customer GROUP BY country



select customer_name,sum(credit) as balance from customer group by country;



select customer_name,sum(credit) as balance from customer where country in ('in','us','jp');



select customer_name,sum(credit) as balance from customer group by country having balance > 1800;



Thank you..

February 02, 2016

Hibernate - selecting multiple rows in a single query



/*
SQLyog Community Edition- MySQL GUI
MySQL - 5.1.32-community
*********************************************************************
*/
/*!40101 SET NAMES utf8 */;

create table `tbl_dcs` (
`columnA` varchar (30),
`columnB` varchar (30)
);
insert into `tbl_dcs` (`columnA`, `columnB`) values('1','11');
insert into `tbl_dcs` (`columnA`, `columnB`) values('2','22');
insert into `tbl_dcs` (`columnA`, `columnB`) values('3','33');


Queries

select * from cfed_sample.tbl_dcs order by columnA;


select columnA,group_concat(columnB) from cfed_sample.tbl_dcs group by columnA;

@OrderBy(clause = "NAME DESC")
Set<Foo> fooList = new HashSet();

String hql = "FROM Foo f ORDER BY f.name";
Query query = sess.createQuery(hql);


other options

/*
SQLyog Community Edition- MySQL GUI
MySQL - 5.1.32-community
*********************************************************************
*/
/*!40101 SET NAMES utf8 */;

create table `dcs_hotels` (
`Book_date` date ,
`Avail_hotel` double
);
insert into `dcs_hotels` (`Book_date`, `Avail_hotel`) values('0000-00-00','4');
insert into `dcs_hotels` (`Book_date`, `Avail_hotel`) values('0000-00-00','3');
insert into `dcs_hotels` (`Book_date`, `Avail_hotel`) values('0000-00-00','5');
insert into `dcs_hotels` (`Book_date`, `Avail_hotel`) values('0000-00-00','1');


select Book_date,group_concat(Avail_hotel) from cfed_sample.dcs_hotels group by Book_date;



http://javabelazy.blogspot.in/

July 10, 2013

to search whether a date is in between two date fields through my sql query

How to search whether a date is in between two date fields through my sql query




see the below table

----------------------------------------------------------
id | start_date    | end_date     | amount | status  | particular
-----------------------------------------------------------
1  | 12-02-2012 |13-07-2013  | 1729    | active  | Zulily
-----------------------------------------------------------
2  | 07-02-2014 |23-02-2014  | 1989   | active  | IOS 7
-----------------------------------------------------------
3  | 07-03-2014 |16-03-2014  | 1987    | active  | Windows 8.1
-----------------------------------------------------------
4  | 12-06-2014 |13-07-2014  | 1987    | active  | Ouya
-----------------------------------------------------------
5  | 12-10-2014 |28-11-2014  |2013    | active  | Comet C/2012
 -----------------------------------------------------------




 SQL query : select * from tbl_interest_rates where now() between start_date and  end_date;
Dated : 10 jully 2013

result  : 1  | 12-02-2012 |13-07-2013  | 1729    | active  | Zulily



This example will find whether the given date is inbetween dates in the given table.

+Shimjith Kumar
+Vipin Cp


http://belazy.blog.com/

August 05, 2012

Compare database mysql date with current date

 Comparing mysql database date with current java date
/**
 *
 */
package Date;



import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author deep
 *
 * program compares todays date with that in db
 *
 */






public class JavaDate {

    /**
     * @param args
     */
    public static void main(String[] args) {
        String dateInDB = "2011-1-12";
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        String currentDate = format.format(new Date());
        System.out.println(" Current date : " +currentDate);
        System.out.println(" date in db   : " +dateInDB);
        if(currentDate.compareTo(dateInDB) <= 0)
            System.out.println("current date is greater ");
        else
            System.out.println("db date is greater ");
    }

}


Thanking you....

Facebook comments