ezoic

Monday, January 23, 2017

Delete the duplicated rows in a single line without creating new table.

Delete the duplicated rows in a single line without creating new table. 

ALTER IGNORE TABLE table1   ADD UNIQUE INDEX (name1,gender);

Python class self

wiki:

https://en.wikipedia.org/wiki/This_(computer_programming)

quora:

https://www.quora.com/What-does-self-mean-in-python-class-Why-do-we-need-it







A class have methods. Also, a class can have multiple objects. Right? Now when any object calls a method of the class, how would the method know which object has called it?
For example, if any of your family member calls your name, how do you recognize that its your mother or father or brother, if you are sitting in a different room? You recognize the voice. Right?

Similarly, self represents the voice of the object.

Example -

class myClass:
    def __init__(self):
        self.x = []
        self.x.append(1)

    def print_x(self):
        print (self.x)

obj1 = myClass()
obj1.print_x()    # prints [1]

obj2 = myClass()
obj2.print_x()    # prints [1],  not "[ 1, 1]"


Now see, both the times [1] is printed even when we used "append".

Whenever you write - obj1.print_x(), self passes the instance of "obj1" . Now "print_x()" would know that "obj1" has called it. Therefore, obj1 would have its own copy of "x" not matter how many times method "print_x" is called by other objects. Same would be the case with obj2.

In other object oriented languages too, when you call a method using an object, instance of an object get passed automatically(like "this" pointer in C++), but we don't have to write that explicitly. Its just that in python you have to be explicit :)



Websites to get programming, data science certificates and data science camp

Websites to get programming, data science certificates:

freecodecamp

udemy

teamtreehouse

coursera

edx

udacity.com


dataquest

datacamp

o'reilly

springboard

data origami

youtube 

data science camp:


insightdatascience

thedataincubator

datacamp


Collections of complex SQL queries I

Collections of complex SQL queries I

we have the table:

id name department 'id of manager', doj (date of joining)

insert into employee values(1,'John','IT',9,'05-08-2010');

1. list the employees who are not managers


2. manager with only one reportee



3. what is the month with most hiring?
4.what is the experience gap between the first employee and the latest?
5. name the manager with most reportees?

6.list managers who joined after the reportees
7.department with most managers and how many?

8.Delete duplicate rows using a single statement and no table creation.
9.Identify the second highest salary from emp table having salary related data.
10.Statement to determine the oracle version used .
11. Query to accept a date and return the fist date of the quarter in which the date exists.
12.Table A has 100 rows, Table B has Zero rows so number of rows returned from  below query
select a.* from a, b;
13. Set of statements executed in the below sequence.
select count(*) from a;

Count(*)
-------
100

Then 1 row inserted in table a.

rollback;
again 3 rows inserted in the table a;
select count(*) from a;
count(*)
--------
103

create table b using select * from a;

rollback;

so what would be the o/p of below select statement
select count(*) from a; 
?
14 .Statement to print numbers from 1 to 100 in sequence.
15.Create a table with no rows structure similar to existing table using an SQL statement.
16. Few queries related to analytical functions. lead, lag, rank, dense_rank
17. Table Employees

NAME  GENDER
----  ------ 
A    MALE
B    FEMALE
BB   FEMALE
CC   FEMALE
CD   MALE
DD   MALE
DE   FEMALE


Write a query to give the o/p like below

MALE  FEMALE
----  ------
3     4

Monday, January 9, 2017

Atom atom runner shortcut


https://atom.io/packages/atom-runner

on windows, I used the shortcut, alt-r to run a script. And I got the results of the script on the right.




R is not a simple programming language, and it does better on reading excel files than python

R is not a simple programming language, and it does better on reading excel files than python . tried to read excel files to python and R. i...