Saturday, June 10, 2017

Different Types of SQL-02

Filter:

SELECT e.first_name, e.salary, d.department_id, d.department_name
FROM employees e
     JOIN departments d ON e.department_id= d.department_id
WHERE d.department_id=20
AND e.salary >=2000
ORDER BY e.first_name ;

IN and NOT IN Conditions:
IN condition is the value for true from the list of values.
NOT IN condition is the value for false from the list of values.

SELECT e.department_id, e.employee_id, e.first_name
FROM employees e
WHERE e.department_id IN (10,20,50)
ORDER BY e.department_id, e.employee_id ;

SELECT e.department_id, e.employee_id, e.first_name
FROM employees e
WHERE e.department_id NOT IN (10,20,50)
ORDER BY e.department_id, e.employee_id ;

EXISTS and NOT EXISTS Conditions:

SELECT d.department_id, d.department_name
FROM   departments d
WHERE  EXISTS (SELECT 1
               FROM   employees e
               WHERE  d.department_id = e.department_id)
ORDER BY d.department_id;

BETWEEN and NOT BETWEEN Conditions:

SELECT d.department_id, d.department_name
FROM   departments d
WHERE  department_id NOT BETWEEN 20 AND 40
ORDER BY d.department_id;


SELECT d.department_id, d.department_name
FROM   departments d
WHERE  department_name NOT LIKE '%n'
ORDER BY d.department_id;

Different Types of SQL-01

Inline Views:

        SELECT ed.first_name, ed.department_name
FROM   (SELECT e.first_name, d.department_name
        FROM   employees e, departments d
        WHERE  d.department_id = e.department_id) ed
ORDER BY ed.first_name;

WITH Clause:

WITH emp_dept AS (
  SELECT e.first_name, d.department_name
  FROM   employees e, departments d
  WHERE  d.department_id = e.department_id
)
SELECT ed.first_name, ed.department_name
FROM   emp_dept ed
ORDER BY ed.first_name;

Views:

CREATE OR REPLACE VIEW emp_dept_join_v AS
  SELECT e.first_name, d.department_name
  FROM   employees e, departments d
  WHERE  d.department_id = e.department_id;
 
SELECT ed.first_name, ed.department_name
FROM   emp_dept_join_v ed
ORDER BY ed.first_name;

Different Types of SQL-00

Wildcard "*":

SELECT e.*, d.*
FROM employees e
    JOIN departments d ON d.department_id=e.department_id
ORDER BY e.employee_id ;

Column Aliases:

SELECT employee_id AS Employee_No, first_name||' '||last_name AS Full_Name
FROM employees
ORDER BY employee_id ;

Table Aliases:

SELECT e.employee_id,
       e.first_name ||' '|| e.last_name AS Full_Name,
       d.department_id,
       d.department_name
FROM   employees e
       JOIN departments d ON e.department_id = d.department_id
ORDER BY e.employee_id;

Functions:

SELECT UPPER('Lowercase text') AS text FROM dual ;

Expressions:

SELECT 1+2 AS addition
FROM dual ;

Scalar Subqueries:

SELECT d.department_id, d.department_name,
(SELECT COUNT(*) FROM employees e WHERE e.department_id=d.department_id) AS Emp_Count
FROM departments d
ORDER BY d.department_id ;


SELECT d.department_id, d.department_name, COUNT(e.employee_id) AS emp_count
FROM   departments d
       LEFT OUTER JOIN employees e ON d.department_id = e.department_id
GROUP BY d.department_id, d.department_name
ORDER BY d.department_id;

Monday, March 27, 2017

Oracle Apex

Hello who's of you know about Oracle Apex ?

Do you know how easy it is ?

Do you know future of Oracle Apex ?


Monday, October 20, 2014

Circular Dubly Linked List in C++

#include <iostream>
using namespace std;

class node 
{
   int value;
   node *head;
   node *tail;
   node *next;
   node *previous;
   node *current;
public:
  
   node()
   {
       value =0;
       head=NULL;
       tail=NULL;
       next=NULL;
   }
  
   bool isEmpty ()
   {
      if (head==NULL) return true;
   else
      return false ;
   }

   void SetFirstElement (int value)
   {
       if (isEmpty () )
        {
           node *n = new node ;
           n->next=NULL;
           n->value=value;
           n->previous=NULL;
           head=tail=current=n;
        }

   }

   void AddItem (int value)
   {
       if (isEmpty () ) SetFirstElement (value);
  
       else
        {
          node *n= new node;
          n->value=value;
          n->previous=current;
          n->next=NULL;
          tail->next=n;
          current=tail=n;
      
        }
    }
  
   void Remove () 
   {
      if (head!=NULL)
      {
         node *temp;
         temp=head;
         head=head->next;
         delete temp;
      }
      else
         cout <<"EMPTY"<<endl;
   }

  
   void print ()
  {
           if(isEmpty ())
           {
               cout<<"List is empty"<<endl;
           }
          
           else
               cout<<"The list is"<<endl;
  
           current=head;
          
           while(current!=NULL)
           {
               cout<<current->value<<endl;
               current=current->next;
           }
   }
   void add_at_begining (int value)
   {
      node *temp= new node ;
      temp->value=value;
      temp->previous=NULL;
      temp->next=head;
      head=temp;
   }

   bool search (int value)
   {
    current=head;
   
    while (current!=NULL)
      {
          if(current->value==value) return true;
          current=current->next;
      }
   }

   void AddItem(int back, int value)
   {
    current=head;
   
    if(search(back))
    {
      while(current!=NULL)
         {
            if(current->value==back)
               {
                  node *temp=new node;
                  temp=current->next;
                  node *temp1=new node;
                  temp1->value=value;
                  temp1->next=temp;
                  temp1->previous=current;
                  current->next=temp1;
               }
            current=current->next;
         }
      }
   }

   void sort ()
   {
       for(int i=0;i<10;i++)
       {
           current=head;
           while(current!=NULL)
           {  
               if(current->next==NULL) break;
               if(current->value>current->next->value)
               {
                      swap(current,current->next);
               }
      current=current->next;
           }
       }
   }
  
   void Remove (int value)
   {
    current=head;
   
    while(current!=NULL)
    {
      if(current->value==value)
      {
         node *temp=new node;
         temp=current;
         node *temp1=new node;
         temp1->previous=temp->previous;
         temp1->value=current->next->value;
         temp1->next=current->next->next;
         current=temp1;
         delete temp;
      }
     
      current=current->next;
    }
  }

  void print_previous (int value)
  {
    if(search(value))
    {
      current=head;
      while (current!=NULL)
         {
            if(current->value==value)
            {
                cout<<"CURRENT"<<current->value<<endl<<"Previous:"<<current->previous->value<<endl;
            }
           
            current=current->next;  
         }
     }
   }

   int check_elements();

   void swap(node *element1,node *element2 )
   {
      node *temp1,*temp2= new node;
      int temp=element1->value;

      temp1=element1;
      temp1->value=element2->value;
      element1=temp1;

      temp2=element2;
      temp2->value=temp;

      element2=temp2;
   }

  void check (int value)
  {
     current=head;
     while(current!=NULL)
     {
         if(current->value==value){ swap(current,current->next);break;}
     
         current=current->next;
     }
  }

  int max_value ()
  {
      current=head;
  
      int temp=0;
      while(current!=NULL)
        {
           if(temp<current->value) temp=current->value;
           current=current->next;
        }
     return temp;
  }

};

int main()
{
    return 0;
}

Checking Parenthesis code - in C++

#include<iostream>
#include<string>
#include<cassert>

using namespace std;

template<class T> class StackADT
{
public:

    virtual void initialstack() = 0;
    virtual bool isEmpty() const = 0;
    virtual bool isFull() const = 0;
    virtual void push(const T& otheritem) = 0;
    virtual T top() const = 0;
    virtual void pop() = 0;
};

template <class T> class Stack : public StackADT<T>{
    int size, tos;
    T *list;

public:
    Stack(int size)
    {
        if(size <= 0)
        {
            cout << "Size of the array must be positive" << endl;
            cout << "By default it is set to 100" << endl;
            this->size = 100;
        }
        else
        {
            this->size = size;
        }

        tos = 0;
        list = new T[this->size];
    }
    void initialstack()
    {
        tos = 0;
    }
    bool isFull() const
    {
        return(tos == size);
    }
    bool isEmpty() const
    {
        return(tos == 0);
    }
    void push(const T& otheritem)
    {
        if(!isFull())
        {
            list[tos] = otheritem;
            tos++;
        }
        else
        {
            cout << "Can not add t a full stack" << endl;
        }
    }
    void pop()
    {
        if(!isEmpty())
        {
            tos--;
        }
        else
        {
            cout << "Canno remove from a empty stack" << endl;
        }
    }
    T top() const
    {
        assert( tos != 0);
        return list[tos-1];
    }
    void copystack(const Stack<T>& otherstack)
    {
        delete[] list;
        size = otherstack.size;
        tos = otherstack.tos;

        list = new T[size];
        for(int j=0; j<tosl j++)
        {
            list[j] = otherstack.list[j];
        }
    }
    ~Stack()
    {
        delete []list;
    }

};


int main()
{

   int i, l;
   Stack<char> stack(100);
   char str[100] = {"{(A+B-C}"};
  
   l=strlen(str);
   for(i=0; i<l; i++)
   {
      
       if((str[i] == '(') ||  (str[i] == '{') || (str[i] == '['))
       {
            stack.push(str[i]);
       }
       else if((str[i] == ')') ||  (str[i] == '}') || (str[i] == ']'))
       {
             if(str[i] == ')')
           {
             if(stack.top() == '(')
                    {
                         stack.pop();
                    }
                    else
                    {
                          cout << "The parenthesis are not balanced "<< endl;
                    }
             }
             else if(str[i] == '}')
             {
                 if(stack.top() == '{')
                 {
                     stack.pop();
                 }
                 else
                 {
                     cout << "The parenthesis are not balanced "<< endl;
                 }
             }
             if(str[i] == ']')
             {
                 if(stack.top() == '[')
                 {
                     stack.pop();
                 }
                 else
                 {
                     cout << "The parenthesis are not balanced "<< endl;
                 }
             }
         }
     }
   
   if(stack.isEmpty())
   {
       cout << "The parenthesis are balanced " << endl;
   }
  

 
   return 0;
}