Thursday, October 10, 2019

SQL: We need JOINS to fetch combined info from two tables connected by foreign key(s)

Here is an example:

Using the AND operator in the WHERE clause to get a value from both tables each, as shown in query below:

Inserting date in Oracle table, for doing that we need to use the TO_DATE function like: TO_DATE('12/01/2016', 'DD/MM/YYYY'), as shown in example below:
Then SELECT for a specific DATE as given below:

----------------------------------------------------------------------------------------------------------------------
To get 'weekly' data (sum/count) :

suppose there is a 'sales' table having a 'sold_date' field, then

SELECT product_name, SUM(price) FROM sales WHERE sold_date <= (sysdate) AND sold_date >= (sysdate - 7);

Similarly for generating Monthly reports

SELECT product_name, SUM(price) FROM sales WHERE sold_date <= (sysdate) AND sold_date >= (sysdate - 30);


-------------------------------------------------------------------------------------------------------------
We can have multiple AND operator in a SQL query
-----------------------------------------------------------------------------------------------------------
Understanding SQL Transactions

-----------------------------------------------------------------------------------------------------------
You can PRINT text in Oracle using AS clause:





No comments:

Post a Comment

इश्क में ग़ैरत-ए-जज़्बात ने रोने ना दिया - सुदर्शन फ़ाकिर

 इश्क में ग़ैरत-ए-जज़्बात ने रोने ना दिया वरना क्या बात थी किस बात ने रोने ना दिया आप कहते थे कि रोने से ना बदलेंगे नसीब उमर भर आप की इस बात...