Showing posts with label Sql. Show all posts
Showing posts with label Sql. Show all posts

Tuesday, December 2, 2014

get percentages on SQL querry - Oracle

If we want to get the percentage of some column on same query, we can do it using "ratio_to_report() over()" function.
ratio_to_report(Number_of_books) over()
let's say we have following table called tbl_books.

Book Number_of_books
Book1 30
Book1 20
Book1 10

if we want to get percentages of each book over total number of books we can do as following,
select book,ratio_to_report(Number_of_books) over() * 100 as percentage from tbl_books
it gives,

Book percentage
Book1 50
Book1 33.333333333
Book1 16.66666666


Tuesday, October 7, 2014

Where does MySQL store data in PC


Windows

Find the my.ini file which store in the MySQL installation folder.
and then open the file and Find the “datadir”, this is the where does MySQL stored the data in Windows.
datadir="C:/ProgramData/MySQL/MySQL Server 5.5/Data/"

Linux

Find the my.cnf with the sudo find / -name my.cnf command.
2) viewthe my.cnf file cat /etc/mysql/my.cnf
yongmo@myserver:~$ cat /etc/mysql/my.cnf
#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
# 
[mysqld]
#
# * Basic Settings
#
user   = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket  = /var/run/mysqld/mysqld.sock
port   = 3306
basedir  = /usr
datadir  = /var/lib/mysql
tmpdir  = /tmp
language = /usr/share/mysql/english
skip-external-locking

3) Find the “datadir”, this is where does MySQL stored the data in Linux system. 

Saturday, January 19, 2013

Install a .sql file to a database in MySQL

First open the command prompt and go to the your MySQL installed directory and go to the bin folder in command prompt.Then copy your database file(.sql file) to that directory(C:\Program Files\MySQL\MySQL Server 5.5\bin).
Then in command prompt run this code.

C:\Program Files\MySQL\MySQL Server 5.5\bin>mysql --user=USER_NAME --password=PASSWORD DATABASE_NAME<FILE_NAME.sql


As a example let's think my MySQL user name is root and password is dilan and I want to install a file called queries.sql to the database named myTestDB. The code snippet  will be as following.

C:\Program Files\MySQL\MySQL Server 5.5\bin>mysql --user=root --password=dilan myTestDB<queries.sql