Month: April 2025

  • It IS About Islam Exposing the Truth about ISIS, Al-Qaeda, and the Caliphate

    It IS About Islam Exposing the Truth about ISIS, Al-Qaeda, and the Caliphate

    Glenn Beck’s 019-It IS About Islam examines the historical and contemporary relationship between Islam and the West, challenging common narratives. The book argues that many widely held beliefs about Islam, such as its inherent peacefulness and the moderation of certain groups, are inaccurate. Beck explores the historical development of Islam, focusing on the life of Muhammad and the emergence of various interpretations and sects. He also analyzes the rise of extremist groups like ISIS and al-Qaeda, connecting their ideologies to historical precedents. Finally, the book critiques the West’s response to these groups and the role of political and media narratives in shaping public understanding.

    Understanding Islam: Core Tenets, History, and Controversies

    Here is a study guide based on the provided source material, designed to enhance your understanding of key concepts:

    I. Core Islamic Concepts

    • Quran: Muslims believe the Quran to be the direct word of Allah, as revealed to Muhammad [1]. It is not considered a collection of stories written by humans, but rather, the first-person voice of God [1]. Unlike the Bible, it is believed to be unchangeable [1].
    • Hadith: These are oral traditions recounting the life and practices of Muhammad [2, 3]. Because the Quran can be contradictory and confusing, the Hadith became very important in determining the rules for daily life [2]. There are many “weak” or fraudulent Hadith, and the most authoritative collectors were not born until nearly 180 years after Muhammad’s death [4].
    • Sharia Law: Sharia law is a wide-ranging system that encompasses crime, politics, economics, and personal matters [5]. It is not a single document, leading to different interpretations [5]. Sharia is derived from the Quran, the Hadith, Ijma (consensus of Muslim scholars), and Qiyas (reasoning by analogy) [3]. Many Muslims believe that Sharia is the only acceptable law for Muslims [3, 6].
    • Some Muslims seek to follow Sharia even in Western countries, attempting to solve disputes within its limits [7]. Some believe a Muslim judge should rule by Sharia law, and hate man-made law [7].
    • Jihad: Jihad is often translated as “struggle,” but it has multiple interpretations [8, 9]. Some Muslims and Islamic scholars define it as an inner struggle to do good [8, 9]. However, it is also considered a holy war, an obligation from Allah [10]. Some interpret it as a means to purify oneself or one’s community [8]. Some believe that jihad is a path to establish Islam over all other religions [11].
    • Caliphate: A caliphate is an Islamic empire ruled by a successor to the prophet Muhammad [12]. The first caliph was Abu Bakr, Muhammad’s father-in-law [12].

    II. Historical Context

    • Jefferson’s Quran: Thomas Jefferson owned one of the first English translations of the Quran, which he acquired in 1765 [13, 14]. He was curious about laws of many kinds, including those that claimed to carry the word of God [14].
    • Early Islamic Expansion: After Muhammad’s death, the Muslim community faced challenges in uniting around a common direction, due to the lack of a complete written Quran [2]. This led to reliance on memories, written fragments of God’s word, and the Hadith [2].
    • Sunni-Shia Split: The loss of Muhammad’s divine revelations and leadership led to divisions within Islam, particularly the split between Sunnis and Shias [2].
    • Wahhabism and Salafism: These movements sought to return to what they considered to be the original, pure form of Islam [15]. They often reject modern interpretations and emphasize strict adherence to early Islamic texts and practices [15].
    • The Muslim Brotherhood: Founded in the 1930s, the Muslim Brotherhood views jihad as an obligation and seeks to model themselves on the martyrs [10]. Documents have revealed their plan to transform America into an Islamist society [11]. They aim to destroy Western civilization and make God’s religion victorious [11].

    III. Key Figures

    • Muhammad: Considered by Muslims to be the last prophet, his life and teachings form the basis of Islam [1]. The Quran is believed to be the direct word of God as revealed to him [1].
    • Abu Bakr: The first caliph, or successor, to Muhammad, appointed after Muhammad’s death [12].
    • Hassan al-Banna: Founder of the Muslim Brotherhood [10].
    • Sayyid Qutb: An influential figure whose writings are embraced by jihadist groups [16].
    • Osama bin Laden: A key figure in al-Qaeda, his organization sought to destroy the United States [8].
    • Abu Bakr Naji: An al-Qaeda theologian who wrote “The Management of Savagery”, which is considered a key strategic text for jihadist groups [17, 18].

    IV. Controversial Issues and Criticisms

    • Violence and Jihad: Some argue that the concept of jihad is often used to justify violence and terrorism [8, 10]. Some interpret jihad as a fight against non-believers [19]. There is debate over whether the term jihad refers to an inner struggle for good, or an external physical struggle [8, 9].
    • Sharia Law in the West: Some fear the implementation of Sharia law in Western countries, noting the existence of Sharia courts and the potential conflict with secular legal systems [20].
    • Treatment of Non-Muslims: Historically, non-Muslims in Muslim-controlled lands have sometimes been given a second-class status (dhimmi), required to pay a tribute (jizya) [21, 22]. There are documented instances of massacres and enslavement of non-Muslims by Muslim forces [22].
    • Freedom of Speech: Some Islamic texts, like Ash-Shifa, advocate violence against those who disrespect Muhammad [23, 24]. This creates tension with Western values regarding freedom of expression [23].
    • Apologists: Some scholars and academics are accused of downplaying or ignoring the violent aspects of Islam by focusing on more peaceful interpretations [9, 25].
    • The Role of Western Foreign Policy: Some sources claim that the West is attempting to blame itself for terrorism, rather than acknowledging that the actions of terrorist groups are solely their own [26].

    V. Key Lies

    • The source material includes a section called “Thirteen Deadly Lies,” which addresses common misconceptions about Islam [13]. It states that claims such as “The Muslim Brotherhood is a moderate, mainstream Islamic group” [13] and “Islam respects freedom of speech” [13] are lies. Other lies include: Muslims don’t seek to live under Sharia [5], and Islam translates to peace [27].

    VI. Strategies for Understanding

    • Go to Primary Sources: It is essential to go to the primary Islamic sources, such as the Quran and Hadith, to understand the religion [28, 29].
    • Understand Motivations: To understand enemies, one must understand their motivations and goals [30].
    • Challenge Misconceptions: It is important to challenge misconceptions and stereotypes about Islam [31].

    VII. The Need for Action

    • Educated Citizenry: An educated citizenry needs to fight back against what the source material considers lies about Islam [30].
    • Truth: The source material suggests that the truth needs to be known by the public, despite what is claimed by politicians and the mainstream media [31].

    This study guide should help you navigate the complex information presented in the sources. Remember to consult the source material directly for a more detailed understanding of each point.

    Islam, Islamist Extremism, and the West

    Here is a briefing document based on the provided source material and our conversation history:

    Subject: Understanding Key Aspects of Islam and Islamist Extremism

    I. Core Islamic Texts and Concepts

    • Quran: Considered by Muslims to be the direct word of Allah, as revealed to Muhammad [1, 2]. It is not considered a collection of stories written by humans [2].
    • It is believed to be unchangeable, unlike the Bible [1].
    • Hadith: Oral traditions recounting the life and practices of Muhammad. These became important for determining rules for daily life [2].
    • Many Hadith are considered “weak” or fraudulent [2]. The most authoritative collectors were not born until nearly 180 years after Muhammad’s death [3].
    • Sharia Law: A comprehensive system encompassing crime, politics, economics, and personal matters, derived from the Quran, Hadith, Ijma (consensus), and Qiyas (reasoning by analogy) [4].
    • Many Muslims believe Sharia is the only acceptable law for Muslims [4]. Some seek to follow Sharia even in Western countries [4].
    • Jihad: Often translated as “struggle,” with multiple interpretations [5, 6].
    • Some define it as an inner struggle to do good [5].
    • Others consider it a holy war, an obligation from Allah to purify oneself or one’s community, and a path to establish Islam over all other religions [5, 7].
    • Caliphate: An Islamic empire ruled by a successor to the prophet Muhammad [8].
    • The first caliph was Abu Bakr, Muhammad’s father-in-law [8].

    II. Key Historical Developments

    • Early Islamic Expansion: After Muhammad’s death, the Muslim community lacked a complete written Quran, leading to reliance on memories, fragments, and Hadith [2].
    • Sunni-Shia Split: Divisions arose within Islam due to the loss of Muhammad’s divine revelations and leadership, most notably the split between Sunnis and Shias [3].
    • Wahhabism and Salafism: Movements aiming to return to the original, pure form of Islam [4]. They often reject modern interpretations and emphasize strict adherence to early Islamic texts [4].
    • The Muslim Brotherhood: Founded in the 1930s, the Brotherhood views jihad as an obligation and seeks to transform societies into Islamist states [7, 9].
    • Documents reveal their plan to transform America into an Islamist society, destroy Western civilization and make God’s religion victorious [10].

    III. Key Figures

    • Muhammad: Considered the last prophet by Muslims; his life and teachings form the basis of Islam [2].
    • The Quran is believed to be the direct word of God as revealed to him [2].
    • Abu Bakr: The first caliph, successor to Muhammad [8].
    • Hassan al-Banna: Founder of the Muslim Brotherhood [7, 9].
    • Sayyid Qutb: An influential figure whose writings are embraced by jihadist groups [9, 11].
    • Osama bin Laden: A key figure in al-Qaeda, sought to destroy the United States [5, 12].
    • Abu Bakr Naji: An al-Qaeda theologian who wrote “The Management of Savagery”, a key strategic text for jihadist groups [13].

    IV. Controversial Issues and Criticisms

    • Violence and Jihad: The concept of jihad is often used to justify violence and terrorism [5, 7, 14].
    • There is debate over whether jihad refers to an inner struggle for good or an external physical struggle [5, 6, 15].
    • Sharia Law in the West: Some fear the implementation of Sharia law in Western countries, noting the existence of Sharia courts and potential conflict with secular legal systems [4].
    • Treatment of Non-Muslims: Historically, non-Muslims in Muslim-controlled lands have sometimes been given a second-class status (dhimmi) and required to pay a tribute (jizya) [14].
    • There are documented instances of massacres and enslavement of non-Muslims by Muslim forces [16].
    • Freedom of Speech: Some Islamic texts advocate violence against those who disrespect Muhammad, creating tension with Western values [17-20].
    • Apologists: Some scholars and academics are accused of downplaying or ignoring the violent aspects of Islam by focusing on more peaceful interpretations [15, 21-23].
    • The Role of Western Foreign Policy: Some sources claim that the West is attempting to blame itself for terrorism, rather than acknowledging that the actions of terrorist groups are solely their own [14, 24].

    V. Key Lies and Misconceptions

    • Claims such as “Islam translates to peace” are false; the more accurate translation is “submission” [25].
    • The Muslim Brotherhood is not a moderate, mainstream Islamic group [26].
    • Islam does not necessarily respect freedom of speech [17, 20].
    • Muslims do not all seek to live under Sharia [4].

    VI. Strategies for Understanding

    • Primary Sources: It is crucial to study primary Islamic sources like the Quran and Hadith [6].
    • Understand Motivations: To understand enemies, one must understand their motivations and goals [27, 28].
    • Challenge Misconceptions: Challenge stereotypes and misrepresentations of Islam [23, 29].

    VII. The Need for Action

    • Educated Citizenry: An informed public is necessary to combat misinformation and threats [28].
    • Truth: The public needs to be informed of the truth, despite claims from politicians and the media [28].

    VIII. Specific examples of Islamist extremism

    • Al-Qaeda: This group began its war against the West long before the attacks of 9/11. Al-Qaeda operatives were responsible for the assassination of Massoud [30].
    • ISIS: This group has established what it calls a caliphate, and is responsible for numerous atrocities [8, 22].
    • The Muslim Brotherhood: This group seeks to establish an Islamist society in America [10, 31, 32].

    IX. The Importance of Dabiq

    • The town of Dabiq in northwest Syria is the location where ISIS slaughtered a Western hostage [16]. The ISIS video warned that the conflict would continue until the crusader army was defeated in Dabiq [16].

    This briefing document should help provide a better understanding of the complex issues surrounding Islam and Islamist extremism.

    Understanding Islam: A Critical Inquiry

    Here is a FAQ based on the provided sources and our conversation history:

    Q: What are the main sources of Islamic teachings?

    • The primary sources are the Quran, believed by Muslims to be the direct word of Allah, and the Hadith, which are oral traditions recounting the life and practices of Muhammad [1]. Sharia law is derived from these sources along with Ijma (consensus of Muslim scholars) and Qiyas (reasoning by analogy) [2].

    Q: What is Sharia law?

    • Sharia is a comprehensive code of conduct for Muslims, derived from the Quran and the Sunnah (the teachings and practices of Muhammad) [2, 3]. It covers all aspects of life, including family, business, and legal matters [4]. Some Muslims believe that Sharia is the supreme law, which should be followed by Muslims wherever they are [3].

    Q: What is the concept of Jihad?

    • Jihad is often translated as “struggle” and has multiple interpretations [5, 6]. Some view it as an inner spiritual struggle to live virtuously [5], while others understand it as a physical struggle or war to defend or spread Islam [6, 7]. Some interpretations of jihad involve warfare against non-Muslims to establish the religion [6, 8]. Some Muslim leaders believe that jihad is an obligation from Allah on every Muslim [7].

    Q: What is Wahhabism and Salafism?

    • These are movements within Islam that seek to return to the original, pure form of the religion, as practiced by the early generations of Muslims [9]. They often reject modern interpretations and emphasize strict adherence to early Islamic texts [9].

    Q: What is the Muslim Brotherhood?

    • The Muslim Brotherhood is a transnational Islamist organization founded in the 1930s [7]. It aims to establish Islamic states and implement Sharia law. The Brotherhood is committed to a long-term “civilization jihad,” seeking to influence and infiltrate Western societies [10].

    Q: What is the difference between Sunni and Shia Muslims?

    • The split between Sunni and Shia Muslims arose after the death of Muhammad, mainly over the issue of who should be his successor [11]. Sunnis believe that the successor should be chosen from among the prophet’s companions, while Shias believe that it should be someone from the prophet’s family, starting with Ali [11].

    Q: Is Islam a peaceful religion?

    • While some Muslims and scholars emphasize the peaceful aspects of Islam, others point to passages in the Quran and Hadith that advocate for violence against non-believers [6, 8]. The word “Islam” translates to “submission,” not “peace” [12]. Some sources also claim that the concept of being “made victorious with terror” is a component of Islam [13].

    Q: What is the view of free speech in Islam?

    • Some Islamic texts advocate for violence against those who disrespect Muhammad or Islam [14, 15]. This creates tension with Western notions of free speech [16-18]. Some Muslims believe that it is necessary to suppress speech that casts Islam in a bad light [19].

    Q: How does Islamist extremism affect the West?

    • Islamist extremist groups like al-Qaeda and ISIS have carried out numerous terrorist attacks in the West [20]. The Muslim Brotherhood aims to infiltrate Western societies and establish Islamic enclaves [10, 21]. Some Muslims living in the West may believe that Sharia law is superior to secular law and may attempt to establish their own courts [22, 23].

    Q: What are some common misconceptions about Islam?

    • Some common misconceptions include:
    • That Islam means peace [12]
    • That Islam respects freedom of speech [16]
    • That all Muslims support or seek to live under sharia law [4, 22]
    • That poverty or a lack of jobs is the root cause of terrorism [24, 25]
    • That the Muslim Brotherhood is a moderate organization [10, 21]
    • Many believe that claims that Islam is a religion of peace are lies used to mislead people [26].

    Q: How should the West respond to Islamist extremism?

    • The sources suggest that the West must:
    • Understand the ideology and motivations of Islamist groups [27, 28]
    • Study primary Islamic texts like the Quran and Hadith [1]
    • Avoid self-blame and recognize that Islamist violence is often driven by religious motivations [25]
    • Challenge misrepresentations of Islam and the use of politically correct language [29]
    • Recognize the importance of the truth as it relates to the motives and goals of radical Islamic groups [27]

    Understanding Islam: A Critical Inquiry

    Here is a FAQ based on the provided sources and our conversation history:

    Q: What are the main sources of Islamic teachings?

    • The primary sources are the Quran, believed by Muslims to be the direct word of Allah, and the Hadith, which are oral traditions recounting the life and practices of Muhammad [1]. Sharia law is derived from these sources along with Ijma (consensus of Muslim scholars) and Qiyas (reasoning by analogy) [2].

    Q: What is Sharia law?

    • Sharia is a comprehensive code of conduct for Muslims, derived from the Quran and the Sunnah (the teachings and practices of Muhammad) [2, 3]. It covers all aspects of life, including family, business, and legal matters [4]. Some Muslims believe that Sharia is the supreme law, which should be followed by Muslims wherever they are [3].

    Q: What is the concept of Jihad?

    • Jihad is often translated as “struggle” and has multiple interpretations [5, 6]. Some view it as an inner spiritual struggle to live virtuously [5], while others understand it as a physical struggle or war to defend or spread Islam [6, 7]. Some interpretations of jihad involve warfare against non-Muslims to establish the religion [6, 8]. Some Muslim leaders believe that jihad is an obligation from Allah on every Muslim [7].

    Q: What is Wahhabism and Salafism?

    • These are movements within Islam that seek to return to the original, pure form of the religion, as practiced by the early generations of Muslims [9]. They often reject modern interpretations and emphasize strict adherence to early Islamic texts [9].

    Q: What is the Muslim Brotherhood?

    • The Muslim Brotherhood is a transnational Islamist organization founded in the 1930s [7]. It aims to establish Islamic states and implement Sharia law. The Brotherhood is committed to a long-term “civilization jihad,” seeking to influence and infiltrate Western societies [10].

    Q: What is the difference between Sunni and Shia Muslims?

    • The split between Sunni and Shia Muslims arose after the death of Muhammad, mainly over the issue of who should be his successor [11]. Sunnis believe that the successor should be chosen from among the prophet’s companions, while Shias believe that it should be someone from the prophet’s family, starting with Ali [11].

    Q: Is Islam a peaceful religion?

    • While some Muslims and scholars emphasize the peaceful aspects of Islam, others point to passages in the Quran and Hadith that advocate for violence against non-believers [6, 8]. The word “Islam” translates to “submission,” not “peace” [12]. Some sources also claim that the concept of being “made victorious with terror” is a component of Islam [13].

    Q: What is the view of free speech in Islam?

    • Some Islamic texts advocate for violence against those who disrespect Muhammad or Islam [14, 15]. This creates tension with Western notions of free speech [16-18]. Some Muslims believe that it is necessary to suppress speech that casts Islam in a bad light [19].

    Q: How does Islamist extremism affect the West?

    • Islamist extremist groups like al-Qaeda and ISIS have carried out numerous terrorist attacks in the West [20]. The Muslim Brotherhood aims to infiltrate Western societies and establish Islamic enclaves [10, 21]. Some Muslims living in the West may believe that Sharia law is superior to secular law and may attempt to establish their own courts [22, 23].

    Q: What are some common misconceptions about Islam?

    • Some common misconceptions include:
    • That Islam means peace [12]
    • That Islam respects freedom of speech [16]
    • That all Muslims support or seek to live under sharia law [4, 22]
    • That poverty or a lack of jobs is the root cause of terrorism [24, 25]
    • That the Muslim Brotherhood is a moderate organization [10, 21]
    • Many believe that claims that Islam is a religion of peace are lies used to mislead people [26].

    Q: How should the West respond to Islamist extremism?

    • The sources suggest that the West must:
    • Understand the ideology and motivations of Islamist groups [27, 28]
    • Study primary Islamic texts like the Quran and Hadith [1]
    • Avoid self-blame and recognize that Islamist violence is often driven by religious motivations [25]
    • Challenge misrepresentations of Islam and the use of politically correct language [29]
    • Recognize the importance of the truth as it relates to the motives and goals of radical Islamic groups [27]

    A History of Islam and Islamist Extremism

    Here is a timeline of key events and developments related to Islam and Islamist extremism, based on the provided sources:

    Early Islam (c. 609-732 AD)

    • c. 609 AD: Muhammad receives his first revelations in a mountain cave near Mecca [1].
    • c. 610-632 AD: Muhammad begins to preach the word of God, and his revelations are memorized or written on fragments, but not yet compiled into a complete written Quran [2, 3].
    • c. 622 AD: Muhammad and his followers move to Medina, marking the beginning of the Islamic calendar. Islam becomes a political and military force [4].
    • c. 632 AD: Death of Muhammad, leading to the selection of Abu Bakr as the first Caliph [5].
    • 632-732 AD: Islamic conquest and conversion spreads, reaching as far north as France, where their advance is stopped by Charles Martel at the Battle of Tours [3, 6].

    The Islamic Golden Age and Subsequent Decline (c. 700-1800)

    • 700-1250 AD: The Islamic Golden Age, marked by advancements in learning and science [7].
    • c. 1200 AD: Islam has enjoyed nearly half a millennium of continuous expansion since the time of Muhammad [6].
    • 1200-1798 AD: The Islamic world begins to decline, and the Ottoman Empire is eventually surpassed by European powers [8].
    • 1798: Napoleon’s invasion of Egypt [9].

    Rise of Modern Islamist Ideologies (18th-20th Centuries)

    • Late 18th Century: The rise of Wahhabism, calling for a return to the pure Islam of the early generations [10].
    • 19th Century: The Ottoman Empire declines, and European powers exert control in the Middle East [8].
    • Early 20th Century: The Ottoman Caliphate collapses (1924), leaving the Muslim world without a single leader. The lands of the former Caliphate are divided by Western powers [11].
    • 1920s-1930s: The rise of the Muslim Brotherhood in Egypt, founded by Hassan al-Banna, who taught that misery was caused by two things: Western influence and the Jews [12].

    Mid to Late 20th Century

    • 1947: The British mandate expires in Palestine leading to the creation of Israel. [13]
    • 1980s: The mujahedeen in Afghanistan, backed by the US, fight the Soviet Union. This period is considered to be a key moment in the development of the Islamist movement [14].

    The Rise of al-Qaeda and Islamist Terrorism (Late 20th – Early 21st Century)

    • 1980s-1990s: Osama bin Laden emerges as a key figure in al-Qaeda, which begins its war against the West [15].
    • 1981: Anwar Sadat, president of Egypt, is assassinated by members of the Muslim Brotherhood [16].
    • 2000-2003: Al-Qaeda’s “Phase I: The Muslim Awakening” of their twenty-year plan, beginning with 9/11 and aimed at provoking the West [17].
    • 2001: Al-Qaeda is responsible for the 9/11 attacks [14, 17].
    • 2003-2006: Al-Qaeda’s “Phase II: Opening Eyes”, using propaganda and battlefield victories to reawaken Muslims and return them to the foundations of their faith [17].
    • 2004: Publication of “The Management of Savagery” by Abu Bakr Naji, a key strategic text for jihadist groups [18, 19].

    The Rise of ISIS and Continued Conflict (2010-Present)

    • 2011: Unrest in the Middle East leads to the toppling of Hosni Mubarak in Egypt. This period became known as the Arab Spring [16].
    • 2011: Qaradawi issues a fatwa outlining the Islamic standard for jihad [20].
    • 2013: Al-Qaeda predicted that a new Islamic government would form a Caliphate, which would occur by 2016 [21].
    • 2014: The Islamic State (ISIS) declares itself a Caliphate, adopting al-Qaeda’s ideology [21].
    • 2014-present: ISIS commits atrocities in its controlled territories, broadcasting executions and using the Quran and Sharia to justify its actions [22, 23].
    • 2015: The Charlie Hebdo massacre in France leads to further media self-censorship [24]. The Islamic State continues to be ground zero for crimes against humanity [22].
    • 2000-2020: Al-Qaeda’s twenty-year plan, which included the establishment of an Islamic Caliphate, was scheduled to be completed by the year 2020 [25-27].

    Ongoing Issues

    • Present Day: The struggle continues between those who seek to moderate Islam and those who seek to impose a totalitarian and fundamentalist form of the religion [28]. Some fear that the West is being infiltrated by radical Islamist groups [29].

    This timeline highlights the key historical developments and the ongoing struggle between various factions of Islam, from its early days to the present. It also underscores the continuing threat posed by Islamist extremist groups.

    A Concise History of Islam

    Islam’s history is marked by periods of expansion, cultural flourishing, and internal conflict, and is characterized by a unique relationship between religion and political power [1-3].

    Early Expansion (7th-8th Centuries):

    • The religion began in Mecca with the revelations of Muhammad [4].
    • After facing opposition in Mecca, Muhammad and his followers migrated to Medina, where Islam became a political and military force [3]. This event marks the beginning of the Islamic calendar [3].
    • Following Muhammad’s death, the Islamic community rapidly expanded through conquest and conversion [5].
    • By 732, Islamic expansion had reached into France, where it was halted at the Battle of Tours [4, 5].

    The Islamic Golden Age (c. 700-1250):

    • This period saw significant advancements in science, mathematics, and philosophy [6].
    • Muslims translated and preserved the works of Greek philosophers like Aristotle and Plato [7].
    • However, this era was not without conflict, as there were sporadic bouts of violence between Muslims and religious minorities [7].
    • The flourishing of Islam during this period was based on military and trading power and cultural reappropriation [8].

    Decline and the Rise of Islamist Ideologies (c. 1250-1924):

    • The Caliphate, the political and religious leadership of the Islamic world, gradually declined [9].
    • The Islamic world was surpassed by Western powers [10].
    • The Ottoman Empire, the last major Caliphate, was known as the “sick man of Europe” before it was dismembered after World War I [11, 12].
    • In 1924, the Caliphate was abolished by the secular Turkish Republic, leaving the Muslim world without a single leader [11].
    • The fall of the Caliphate is considered a tragedy by radical Islamists, who seek to restore it [11].
    • The loss of the Caliphate led to a push to revive Islam, and a belief that it is a total system that should include a political vision and social order [13].
    • The Muslim Brotherhood was founded in 1928 to restore the Caliphate and impose Islamic law on all nations [14].

    The Rise of Modern Islamist Movements (20th-21st Centuries):

    • The creation of Israel and the loss of Arab lands became propaganda tools for those who saw Islam as the solution to the world’s problems [15].
    • The 20th century saw the rise of modern Islamist ideologies, including Salafism and Wahhabism which seek to return to the original, pure form of Islam [15].
    • The Soviet war in Afghanistan in the 1980s was a key moment for the development of the Islamist movement. The US supported the Mujahideen in Afghanistan [16].
    • Al-Qaeda, founded by Osama bin Laden, launched a war against the West [17].
    • The 9/11 attacks in 2001 marked a turning point in the relationship between the West and radical Islamists [17].
    • ISIS declared a new Caliphate in 2014, committing atrocities and seeking to expand its territory [18].

    Key Themes in Islamic History

    • The concept of Dar al-Islam (house of Islam) and Dar al-harb (house of war): This division of the world into Muslim lands and non-Muslim lands has influenced the relationship between Islam and the rest of the world [19].
    • The inseparability of religion and politics: Unlike Christianity, where a separation of church and state developed over time, Islam has historically been associated with political power and conquest [2, 3].
    • The importance of the Quran and Hadith: These texts are regarded as the ultimate authority for Muslims and have been used to justify various actions throughout history [20].
    • The ongoing struggle between moderate and extremist interpretations of Islam: This tension has existed throughout Islamic history [21]. Some seek a classically liberal approach recognizing faith as something between God and the individual, while others seek to impose Islamic law on the world [21].

    This history reveals that Islam is not a monolithic entity, but rather a diverse religion with various interpretations and movements. The tension between these interpretations continues to shape the Islamic world and its relationship with the West today [21].

    Sharia Law: An Overview

    Islamic law, known as Sharia, is a complex system of rules and guidelines derived from the Quran and the teachings of Muhammad [1, 2]. It is not just a legal code, but an all-encompassing way of life [1]. Sharia is meant to be a pathway to God’s will [1, 3].

    Sources of Sharia:

    • Quran: The central, sacred text of Islam, believed to be the word of God as revealed to Muhammad [4].
    • Sunna/Hadith: The example and practices of Muhammad’s life, as recorded in oral traditions [4].
    • Ijma: The consensus of Muslim scholars [4].
    • Qiyas: Reasoning by analogy, which establishes new precedents in areas where the Quran and Hadith are unclear [4].

    Key Aspects of Sharia:

    • Sharia covers a wide range of matters, including crime, politics, economics, and personal matters such as sexuality, diet, hygiene, prayer, and fasting [5]. It is intended to guide all aspects of life [3].
    • Sharia is considered by some to be the supreme law over everything and everyone, regardless of where they live [3].
    • Sharia is not a static set of rules; there are varying interpretations of Sharia [5-7]. Different schools of legal thought emerged after Muhammad’s death as scholars debated the meaning of the Quran and Hadith [8].
    • Sharia is viewed by many Muslims as a religious imperative [9]. Some believe that living under Sharia is a defined religious obligation [9, 10]. Muslims are expected to follow Sharia, wherever they live, and it must take precedence over the laws of man [7].
    • Some Muslims believe that the entire Muslim community must live under Sharia [11].
    • Some Islamic scholars believe that no other sovereign or authority is acceptable to a Muslim unless it guarantees the application of Sharia in its entirety [4].
    • Many Muslims believe that Sharia is the answer to the world’s problems and represents the holistic worldview of Muhammad and the Quran [12].

    Sharia and Governance:

    • Sharia includes a “program for government,” which is why Islam has been a political force since its beginning [2].
    • Historically, there has been no separation of church and state in Islam, and caliphs were both religious and political leaders [1].
    • Sharia law developed a set of rules, laws, and traditions for non-Muslims, who were often treated as second-class citizens if they survived initial waves of conquest [13].
    • Some interpretations of Sharia call for Muslims to continuously wage war against non-Muslims until Islam establishes supremacy over all other religions [14].

    Sharia and Punishment:

    • Sharia prescribes punishments for crimes considered to be against God, called hudud, including theft, adultery, and apostasy. Punishments range from lashes to banishment to death [15].
    • According to some interpretations of Sharia, theft may be punished by amputation of a hand [8, 15], and adultery is punishable by death by stoning [8, 16].
    • Apostasy, or abandoning Islam, is considered the most severe crime in Sharia, and can be punished by death [17].
    • Blasphemy, or anything seen as insulting to God or Muhammad, is also considered a severe crime, with punishments ranging from fines to amputation to hanging or beheading [8].

    Sharia and Non-Muslims

    • Non-Muslims were sometimes allowed to retain their faith if they paid a tribute called a jizya, and were considered “protected” or “guilty” people (dhimmi) [13].
    • In some interpretations of Sharia, only “People of the Book” (Jews and Christians) are allowed to live in exchange for paying the jizya, and other non-Muslims must either convert to Islam or be killed [14].
    • In addition to paying the jizya, non-Muslims were required to acknowledge their position as second class citizens, and sometimes had to wear distinctive clothing [18].

    Sharia in the Modern World:

    • Many Muslims around the world support the implementation of Sharia as the official law in their countries [12]. Some polls show that a large majority of Muslims in some countries favor making sharia the official law [9, 12, 16].
    • Some groups seek to impose Sharia on the entire world. [19, 20]
    • There are increasing instances of Sharia law coming into conflict with Western legal systems [21]. For example, some courts in the West have had cases where the husband claimed that it was his right to have sex with his wife at any time under Sharia law, or that a woman’s testimony should be worth half of a man’s [8, 21].
    • There is concern that some groups are trying to introduce Sharia into the judicial system in the West [22].
    • Some Muslim leaders have set up their own courts that follow Sharia, and some of these leaders have expressed support for harsh punishments such as cutting off the hands of thieves [23, 24].

    Different Interpretations of Sharia:

    • There are varying interpretations of Sharia, leading to different practices across the Islamic world [5, 6, 25].
    • Some argue that Sharia is flexible and can be adapted to different political systems and cultures [25].
    • Others argue that Sharia is an eternal, unchangeable system that must take precedence over all other laws [7].
    • Many moderate Muslims believe that Sharia is personal religious law and moral guidance, but some groups have a literalist and absolutist view that believes Sharia should be imposed on everyone everywhere [20, 25].

    It is important to note that there is no one “Sharia”; the term refers to a body of law and tradition interpreted differently across time and by different groups. It is this range of interpretations that forms the basis of both moderate and radical Islam.

    Jihad: Interpretations and Justifications

    Jihad is a complex concept with multiple interpretations, ranging from a personal spiritual struggle to a physical war against non-believers [1-5].

    Multiple Interpretations of Jihad:

    • Some interpretations of Jihad focus on the internal struggle to be a better Muslim [1, 2, 4, 5]. This can include striving for virtue, doing good works, and taking personal responsibility [1, 4, 5].
    • Some scholars and Muslims view Jihad as a personal commitment to service, patience, and taking the higher road [2, 4].
    • Other interpretations view Jihad as a physical war against non-believers, and a holy duty for Muslims [6-10].
    • Some Muslims consider Jihad to be a legitimate tenet of Islam, meaning to purify oneself or one’s community [2].
    • Many Muslims and Islamic scholars consider the more correct definition of jihad to be the inner struggle to do good and follow God’s teachings [2].

    Jihad as Holy War:

    • The Quran outlines the Islamic duty to make war upon non-Muslims [6]. Specifically, Sura 9, verse 29, explains the duty to fight those who do not believe in Allah, the Last Day, or forbid what has been forbidden by Allah and his messenger [6]. It also mentions fighting those who do not acknowledge Islam among the People of the Scripture (Jews and Christians) until they pay the Jizyah with willing submission and feel subdued [6, 11].
    • Sura 47, verse 4, sanctions taking captives as spoils of war [7]. It orders Muslims to continue Jihad against disbelievers until they embrace Islam or come under Muslim protection [7].
    • Sura 2, verse 154, states that Allah will reward holy warriors who fight on his behalf [8].
    • Some interpretations of Jihad involve the use of violence, crudeness, terrorism, frightening others, and massacring [12].
    • Some scholars believe that Jihad is the most merciful method for all created things and the most sparing of the spilling of blood [13].
    • Some Islamic scholars have stated that war is the real basis of relations between Muslims and non-Muslims, and that the infidelity of non-Muslims is the cause of such war [14].
    • Classical Islamic scholars have defined Jihad as a holy war, contrasting it with other religions where war is only for purposes of defense [10].
    • Some interpretations of Jihad emphasize the need to convert everyone to Islam by persuasion or by force [10].
    • Some Islamic scholars believe that Muslims are obligated to raid the lands of infidels, occupy them, and exchange their system of governance for an Islamic one [15].
    • Some believe that the objective of Islamic Jihad is to eliminate un-Islamic systems of rule and establish an Islamic system in its place [16].
    • Some Muslims believe that the goal of Islam is to spread its system of law across the world; therefore, any opposition to spreading Islamic law could be defined as a defensive act [17].
    • Some interpret Jihad as a movement aimed at preventing enemies from forcing their hegemony over land and people through violence that takes away freedom, kills people, and usurps wealth [18].
    • Jihad is sometimes interpreted as confronting violence with violence and force with force [18].

    Jihad and its Justifications:

    • Some believe that disbelief alone is enough to justify murder [19].
    • Some Muslims believe that those who wage war against Allah and his messenger should be killed, crucified, have their hands and feet cut off, or be exiled [20].
    • Some also see “mischief in the land” as a justification for violence, with “mischief” referring to various types of evil [19].
    • Some interpretations of jihad see it as a way of extending the sovereignty of God’s law throughout the world [21].

    “Defensive Jihad”

    • Some apologists for Jihad argue that, according to Islamic law, Allah will only countenance a “defensive” jihad, and that jihad is only justifiable once Muslim lands are attacked or Muslims are persecuted [22].
    • However, the definition of “defensive” can be broad. For example, some believe that if Muslims are not permitted to live according to Sharia law, it could be considered persecution and justification for defensive jihad [23].
    • Some have also used the concept of “defensive jihad” to justify attacks that could be seen as offensive, such as terrorist attacks [17].
    • Some have defined defensive jihad as a movement that prevents enemies from forcing their hegemony over land and people by violence that eliminates freedom, kills people, and usurps wealth [18].

    Jihad and Motivation

    • Jihad must be done in the cause of Allah [24].
    • Anger, or worldly motivations, are not sufficient reasons for a Muslim to engage in jihad [25, 26].
    • Some believe that those who fight for reasons of anger or worldly emotions will not receive a heavenly reward [25, 26].

    Modern Interpretations

    • Some Muslims and Islamic scholars are urging a careful scrutiny and revision of traditional understandings of jihad [14].
    • Some Muslim groups such as the Muslim Brotherhood are committed to a “civilization jihad,” a long-term plan to influence and infiltrate Western societies and destroy Western civilization from within [27-29].
    • Some groups believe that they will conquer Europe and America not through the sword but through dawa, which is the principal means of the Muslim Brotherhood’s civilization jihad [28].

    It is important to note that the concept of jihad is not monolithic and has been interpreted and used in many different ways throughout history.

    ISIS and al-Qaeda: A Comparative Analysis

    ISIS and al-Qaeda are both radical Islamist terrorist groups that share a common goal of establishing a global Caliphate under Sharia law, but they have distinct origins, strategies, and organizational structures [1-4].

    Shared Ideology:

    • Both groups adhere to a supremacist political ideology, known as Islamism, which seeks to impose Sharia law on the world [1, 5].
    • They believe that Islam is not a religion of peace, but rather a religion of war [6].
    • Both groups believe that they are charged with playing an active role in bringing about the end times [7].
    • They both seek to replace the world order of sovereign nation-states with a new world order divided between the Caliphate and the Muslim community of believers, and the unbelievers [8].
    • They believe in the concept of dar al-Islam (house of Islam) versus dar al-harb (house of war, or the rest of us) [9].
    • Both groups believe that their actions are justified by their interpretation of Islamic texts [10].
    • Both groups believe that they are the true protectors of Islam [11].
    • Both groups are focused on expanding their power to the entire planet [12].
    • Both see the imposition of Sharia law as an imperative [4].

    Origins and Evolution:

    • Al-Qaeda emerged as a terrorist organization, while ISIS evolved from al-Qaeda’s Iraq branch and became a quasi-government controlling territory [13, 14].
    • Al-Qaeda’s origins can be traced back to the fight against the Soviet Union in Afghanistan. It later became a global terrorist network led by Osama bin Laden [15, 16].
    • ISIS grew out of the chaos of the Syrian Civil War and the power vacuum in Iraq after the withdrawal of U.S. forces [13, 17, 18].
    • Al-Qaeda had a twenty-year plan to install a Caliphate, and the 9/11 attacks were part of that plan [15].

    Organizational Structure and Leadership:

    • Al-Qaeda has evolved from a terrorist organization to an ideological movement to which ISIS and other jihadi groups pledge allegiance [19].
    • Al-Qaeda is no longer seen as having a command-and-control structure like a mini-Pentagon, but rather a movement with adherents that are self-recruited and can spring up anywhere [19].
    • ISIS declared itself a Caliphate in 2014, establishing a physical territory and governing structure in parts of Syria and Iraq [20].
    • ISIS’s self-appointed leader, Abu Bakr al-Baghdadi, declared himself Caliph and changed his name to include “Muhammad,” believing himself to be the Mahdi [21].

    Tactics and Strategies:

    • Al-Qaeda primarily operates as a terrorist organization conducting attacks on Western targets [8, 15, 22].
    • ISIS uses a combination of terrorism and conventional warfare to expand and control territory [18, 20, 23].
    • ISIS is known for its brutality, using beheadings, massacres, and enslavement as methods of control and intimidation [21, 23].
    • Both groups use propaganda, social media, and videos to spread their message and recruit new members [21, 24-26].
    • Both groups use cyberattacks to target America’s economic might [2].

    Goals and Objectives:

    • Al-Qaeda’s goal was to re-establish the Caliphate and return Islam to global dominance [15].
    • ISIS’s objective is to establish a global Caliphate and impose Sharia law on all survivors, believing it is their duty to bring about the end times [7, 27].
    • ISIS believes it will be a key agent of the coming apocalypse [28].
    • ISIS wants to engage in a final confrontation with the West that will result in World War III [29].
    • Both groups believe the West will lose its will to fight, allowing the Caliphate to grow in strength and territory [2].

    Relationship and Merging of the Groups:

    • ISIS grew out of Al-Qaeda in Iraq [3, 13].
    • There is evidence that al-Qaeda and ISIS are merging [3].
    • Al-Qaeda’s ideology and terrorist tactics went mainstream after ISIS declared the Islamic State [14].
    • The declaration of the Caliphate by ISIS was a goal al-Qaeda had predicted a decade earlier [14].

    Specifics about ISIS

    • ISIS’s capital is al-Raqqa in eastern Syria [18].
    • ISIS has cells operating in more than a dozen countries with outposts where it governs pockets of territory [30].
    • Some ISIS members believe that their leader, al-Baghdadi, is the Mahdi himself [21].
    • ISIS considers the village of Dabiq to be the location of the final battle between the forces of Islam and the infidels [17, 27].
    • ISIS propaganda refers to the United States as the “forces of Rome” who will be defeated at Dabiq [27].
    • ISIS believes that after this battle, there will be an open road to Istanbul and Europe beyond [27].
    • ISIS has a digital magazine called Dabiq [24].
    • ISIS has razed the birthplace of human civilization in Iraq and Syria to build a new Caliphate [31].
    • ISIS destroys ancient artifacts because they consider them “worthless,” even if they are worth billions of dollars [31].

    Specifics about Al-Qaeda

    • Al-Qaeda’s twenty-year plan, which began in 2001, has seven phases [15, 16].
    • Al-Qaeda’s plan included drawing America into war in Afghanistan and Iraq, toppling secular governments, and creating an Islamic Caliphate [32].
    • Al-Qaeda’s plan predicted the Arab Spring, when secular governments would topple [32].
    • Al-Qaeda’s plan included a special focus on Syria, because Syria is home to Dabiq, and it is the doorstep to toppling Jordan and Israel [17].

    Differences in Tactics

    • While both groups use violence, ISIS is known for extreme brutality, including beheadings, crucifixions, and mass executions [23, 33, 34].
    • ISIS uses savagery as a central method of ruling to shock and deter. It may alienate some potential supporters, but it forces many more into submission [21].

    Response to the Groups

    • Some governments recognize the threat posed by both groups, and see no distinction between them [35].
    • Some governments and media outlets do not acknowledge the connection between Islam and the actions of these groups, labeling them as “not Islamic” [36-38].
    • The U.S. administration initially downplayed the threat of ISIS, calling them a “JV team” [37].

    In conclusion, while ISIS and al-Qaeda share the ultimate goal of a global Caliphate under Sharia law, they have evolved with different strategies and methods. Al-Qaeda has become an ideological movement with decentralized control, while ISIS has established itself as a quasi-government with control of territory. Both groups use violence and propaganda to spread their message and achieve their goals [19, 20].

    The Caliphate: Goals, History, and Challenges

    The overarching goal of a Caliphate is to establish a global Islamic state governed by Sharia law [1-3]. This objective is central to the ideologies of various radical Islamist groups [4, 5], including ISIS and al-Qaeda [6, 7].

    Here are specific goals and aspects associated with the Caliphate as described in the sources:

    • Unification of Muslims: The Caliphate aims to unite all Muslims under a single political and religious authority, transcending national borders and secular laws [2, 8]. The vision is to erase the boundaries of nation-states and create one Muslim community, the umma [2, 9].
    • Implementation of Sharia Law: A key objective is to enforce Sharia law in all aspects of life, encompassing legal, social, and political systems [2, 8]. Sharia is viewed as the inalterable law of God [1, 5]. The Caliphate sees its mission as “compelling the people to do what the Sharia (Allah’s law) requires of them” [10].
    • Global Expansion: The Caliphate seeks to expand its territory and influence worldwide [1, 11]. This is based on the concept that dar al-harb (house of war, referring to non-Muslim lands) should shrink, giving way to a global Caliphate of believers [2, 11, 12].
    • Rejection of Western Influence: The Caliphate seeks to reverse the perceived decline of the Islamic world by rejecting Western innovations and traditions, such as secular constitutions and nation-states [2, 13]. It aims to restore Islam to what is seen as its original, pure form [5, 14].
    • Establishment of an Islamic State: The Caliphate aims to set up an Islamic state to faithfully implement Sharia law as Muhammad and the first four rightly guided caliphs did [2].
    • Role in the End Times: Many Islamists believe that establishing the Caliphate is a necessary step to bring about the return of the Mahdi and the Day of Judgment [15, 16]. The Caliphate is seen as a sign of the impending end times, giving meaning to those who seek it [15, 17]. Some ISIS members believe that their leader, Abu Bakr al-Baghdadi, is the Mahdi [17].
    • Total Submission to Allah: The Caliphate requires complete submission to Allah, with Muslims acknowledging their purpose to carry out the commands of Allah, establish His religion, and refer to His law for judgment [1, 10].
    • Confrontation with the West: The Caliphate seeks a final confrontation with the West that they hope will result in World War III [18]. They believe that the West will lose its will to fight, allowing the Caliphate to grow in strength and territory [19].
    • Establishing a new world order: The Caliphate seeks to replace the world order of sovereign nation-states with a new world order divided between the Caliphate and the Muslim community of believers, and the unbelievers [12].
    • Rejection of National Citizenship: The Caliphate does not recognize national citizenship or the borders of countries, and uses terms like Syria and Iraq that have no meaning [8].

    Historical and Ideological Context:

    • The concept of the Caliphate is rooted in Islamic history, dating back to the time of Muhammad and the early Islamic empires [4, 20].
    • The Caliphate expanded from Spain to India by the beginning of the eighth century A.D. [21].
    • The abolition of the Ottoman Caliphate in 1924 is seen as a tragedy by radical Islamists, who seek to reestablish it [6, 22].
    • The desire to create a Caliphate has been a long-standing goal for groups like al-Qaeda and the Muslim Brotherhood [6, 23].
    • The rise of ISIS and its declaration of a Caliphate in 2014 has galvanized many Islamists around the world [24].
    • Reestablishing the Caliphate was a goal for Osama bin Laden and al-Qaeda [6].

    Specific Actions and Beliefs of the Caliphate:

    • The Caliphate considers those who are not true Muslims to be enemies [8].
    • The Caliphate imposes harsh punishments on those who don’t follow Sharia Law [25].
    • The Caliphate uses violence and brutality to instill fear and force submission [6, 17, 26].
    • They believe that they are fulfilling prophecies of Muhammad about the coming Day of Judgment [17].
    • Many radicals believe that the Caliphate will be ruled from Jerusalem [27]. They see Jordan as the eastern gate to Israel [27].
    • The Caliphate sees itself as a divinely ordained political entity destined to spread to the corners of the earth [9].

    Challenges to the Idea of the Caliphate:

    • Many Muslims do not recognize the legitimacy of the Caliphate established by ISIS [9].
    • Some view the idea of a Caliphate as a fanciful dream, or an absurd delusion that will never happen [27, 28].
    • Some Western political and media figures have downplayed the threat of the Caliphate, dismissing it as unrealistic [28-30].

    In summary, the Caliphate’s goal is to establish a global Islamic state under Sharia law, uniting all Muslims, rejecting Western influence, and fulfilling prophecies about the end times [16]. This is a core objective for many radical Islamist groups, and it involves the use of various tactics, including violence, propaganda, and political action [5, 9].

    By Amjad Izhar
    Contact: amjad.izhar@gmail.com
    https://amjadizhar.blog

  • Al-Riyadh Newspaper, April 7, 2025: US Tariffs, International Relations, EU Response, Saudi Stock Market, Digital Transformation

    Al-Riyadh Newspaper, April 7, 2025: US Tariffs, International Relations, EU Response, Saudi Stock Market, Digital Transformation

    These articles from “Al Riyadh” newspaper cover a range of topics from early April 2025. Several pieces discuss international relations and trade, including Saudi Arabia’s condemnation of Israeli actions and the European Union’s response to potential US tariffs. Economic news includes analysis of the Saudi stock market, oil price fluctuations due to global factors, and challenges facing the petrochemical industry. Other articles highlight Saudi Arabia’s domestic initiatives in human capabilities development, project management, digital transformation in education and media, and efforts to support the Arabic language. Finally, there are reports on local events, sports news, and community updates, including aid efforts for Gaza and cultural events in Saudi Arabia.

    01
    لتصدي للتحايل بربط التأشيرة بحجوزات الطيران لمدة البرامج وإقامة المعتمرين

    Study Guide: Analysis of “20734.pdf” Excerpts

    I. Key Themes and Concepts:

    • The Israeli-Palestinian Conflict: Understand the historical context, including UN Resolution 181 (1947), the 1948 Arab-Israeli War, and the displacement of Palestinians. Focus on the concept of the two-state solution and international support for it.
    • Saudi Arabia’s Foreign Policy: Analyze Saudi Arabia’s consistent stance on the Palestinian issue, its demand for a 1967 border-based independent Palestinian state with East Jerusalem as its capital, and its condemnation of Israeli actions. Note its emphasis on the Palestinian people’s right to self-determination.
    • International Reactions to the Conflict: Recognize the international community’s criticism of Israeli policies like settlement construction and the separation wall. Understand the call for recognition of a Palestinian state on 1967 borders by the UN Security Council member states that haven’t yet done so.
    • Economic News and Analysis: Understand the impact of international events (like potential US tariffs) on global and Saudi markets, including the oil sector. Note the analysis of defensive sectors during times of uncertainty and the reasons behind market fluctuations.
    • Saudi Arabia’s Domestic Developments: Be aware of various events within Saudi Arabia, including regional administrative appointments, conferences (e.g., Human Capability Initiative, Global Project Management Forum), and initiatives in education and culture (e.g., King Salman Global Academy for Arabic Language, Riyadh Art Week).
    • Global Trade and Tariffs: Understand the potential implications of increased tariffs and trade disputes, particularly the US-China trade tensions, and their effect on various economies and sectors.
    • The Role of Technology and Artificial Intelligence: Note the discussion on the increasing reliance on AI for analysis and decision-making and the potential risks associated with the decline of human critical thinking.
    • Sports and Cultural Events: Be aware of the coverage of local sports leagues, team performances, and cultural events like “Layali Dami Al-Saif” and the revival of traditional Najdi dances.
    • Social Issues and Humanitarian Concerns: Understand the reports on the humanitarian situation in Gaza, including food insecurity, restricted aid, and the psychological impact on children. Note the discussions around visa policies and expatriate worker issues.
    01
    «اليمامة الصحفية» تقيم حفل المعايدة السنوي لمنتسبيها

    II. Quiz:

    1. What was the main outcome of UN Resolution 181 in 1947 regarding Palestine, and what significant event in 1948 resulted in the displacement of many Palestinians?
    2. Describe Saudi Arabia’s official stance on the establishment of a Palestinian state, specifically mentioning the key conditions for establishing diplomatic relations with Israel.
    3. According to the excerpts, what actions by Israel are frequently criticized by the international community and Saudi Arabia in relation to the Palestinian territories?
    4. Explain the analysis provided in the text regarding the performance of “defensive sectors” like telecommunications and food during times of economic uncertainty.
    5. What was the focus of the Human Capability Initiative conference mentioned in the excerpts, and under whose patronage was it held?
    6. Describe the potential negative consequences discussed in the text regarding the increasing global trade tensions and the imposition of tariffs, particularly by the US and China.
    7. According to one of the opinion pieces, what is a potential danger associated with the increasing reliance on artificial intelligence for analysis and decision-making?
    8. What was the significance of the “Layali Dami Al-Saif” event, and what broader cultural initiative was it part of in Jeddah?
    9. Based on the excerpts, what are some of the key challenges faced by the population in Gaza, as reported by international organizations?
    10. According to the excerpts, what is the primary goal of the King Salman Global Academy for Arabic Language’s collaboration with Indiana University?
    01
    «السوق السعودي».. تراجع حاد وسط هبوط بورصات العالم

    III. Quiz Answer Key:

    1. UN Resolution 181 called for the partition of Palestine into two states: one Jewish and one Arab. The 1948 Arab-Israeli War, which led to the establishment of Israel, resulted in the displacement and expulsion of hundreds of thousands of Palestinians.
    2. Saudi Arabia’s stance is firm on the necessity of the Palestinian people obtaining their legitimate rights, demanding an independent Palestinian state based on the 1967 borders with East Jerusalem as its capital. It has stated there will be no diplomatic relations with Israel without recognition of this state and a withdrawal from the Israeli aggression on Gaza and the West Bank.
    3. The international community and Saudi Arabia frequently criticize Israeli policies such as the construction of the separation wall, the building and expansion of settlements in Palestinian territories, and the ongoing incursions into Al-Aqsa Mosque. They uphold the rights of Palestinians, including their right to self-determination and independence.
    4. The analysis suggests that during times of current uncertainty, defensive sectors like telecommunications and food are considered to be in a state of defense, implying they might be more stable or less affected by market downturns compared to other sectors.
    5. The Human Capability Initiative conference, held under the patronage of the Crown Prince and Chairman of the Council of Ministers’ Committee for the Human Capability Development Program, focused on preparing for the future “beyond 2014” and enhancing human capabilities to adapt to rapid global changes.
    6. The potential negative consequences of increased tariffs and trade disputes include higher prices for consumers, the possibility of a global trade war, and the risk of pushing economies around the world into recession. The US-China trade tensions, with retaliatory tariffs, exacerbate these concerns.
    7. One opinion piece suggests that a potential danger of increasing reliance on AI is the decline of human critical thinking and the transformation of humans into obedient followers of machine decisions, potentially leading to intellectual extinction before digital superiority.
    8. “Layali Dami Al-Saif” was a significant and celebratory intellectual gathering inaugurated by the Governor of Makkah, emphasizing Saudi Arabia’s cultural and literary values. It served as the launch of an exhibition titled “Layali fi Hubb Khalid Al-Faisal” as part of the “Jeddah Season 2025.”
    9. Key challenges faced by the population in Gaza include severe food insecurity due to the continued closure of crossings and prevention of aid entry, the destruction of water infrastructure, and the repeated forced displacement amidst ongoing conflict, leading to psychological distress, particularly among children.
    10. The primary goal of the King Salman Global Academy for Arabic Language’s collaboration with Indiana University is to train teachers of Arabic for non-native speakers using advanced educational methods, enhance their teaching abilities, and develop the skills of their learners.
    01
    “وزارة الحج والعمرة” تحدد 1 من ذي القعدة آخر موعد لمغادرة المعتمرين

    IV. Essay Format Questions:

    1. Analyze the consistency and key principles of Saudi Arabia’s foreign policy towards the Israeli-Palestinian conflict as presented in the provided excerpts. Discuss the potential impact of this stance on regional and international diplomatic efforts.
    2. Critically evaluate the interconnectedness of global economic events, such as US tariff policies, and their potential ripple effects on the Saudi Arabian economy, particularly the oil and stock markets, as suggested by the text.
    3. Discuss the significance of the various conferences and initiatives mentioned in the excerpts (e.g., Human Capability Initiative, Riyadh Art Week, King Salman Global Academy for Arabic Language) in the context of Saudi Arabia’s Vision 2030 goals for human capital development and cultural enrichment.
    4. Explore the potential benefits and risks of the increasing integration of artificial intelligence into analysis and decision-making processes, drawing upon the arguments presented in the opinion piece regarding the future of human intellect.
    5. Examine the humanitarian situation in Gaza as depicted in the excerpts, considering the roles and responsibilities of international actors and the long-term implications for the affected population.
    01
    حرس الحدود بالمدينة ينقذ 3 مواطنين تعطلت واسطتهم البحرية في عرض البحر

    V. Glossary of Key Terms:

    • قرار 181 (Resolution 181): A United Nations resolution passed in 1947 that called for the partition of Palestine into two separate states, one Jewish and one Arab.
    • حل الدولتني (Two-State Solution): A proposed framework for resolving the Israeli-Palestinian conflict by establishing two independent states, one for Israelis and one for Palestinians, living side-by-side in peace and security.
    • حق تقرير المصير (Right to Self-Determination): The principle that a people should be able to freely decide their own political status and form of government without external influence.
    • الجدار الفاصل (Separation Wall): A barrier constructed by Israel in the West Bank, the route and impact of which are highly controversial and have been condemned by international bodies.
    • المستوطنات (Settlements): Israeli civilian communities established on land captured by Israel in the 1967 war, considered illegal under international law by many countries and organizations.
    • وكالة غوث وتشغيل اللاجئين الفلسطينيين (UNRWA – United Nations Relief and Works Agency for Palestine Refugees in the Near East): A UN agency that provides assistance and protection to Palestinian refugees registered in Jordan, Lebanon, Syria, the West Bank, and the Gaza Strip.
    • العمرة (Umrah): A voluntary Islamic pilgrimage to Mecca that can be performed at any time of the year, distinct from the annual Hajj pilgrimage.
    • الرسوم الجمركية (Tariffs): Taxes imposed by a government on imported or exported goods.
    • التحول المؤسسي والخدمي (Institutional and Service Transformation): A comprehensive process of organizational change aimed at improving efficiency, effectiveness, and the quality of services provided.
    • منظمة الأمم المتحدة للطفولة (UNICEF – United Nations Children’s Fund): A UN agency responsible for providing humanitarian and developmental aid to children worldwide.
    • الذكاء الاصطناعي (Artificial Intelligence – AI): The theory and development of computer systems able to perform tasks that normally require human intelligence, such as visual perception, speech recognition, decision-making, and translation between languages.
    • مبادرة القدرات البشرية (Human Capability Initiative): A program or conference focused on developing and enhancing the skills, knowledge, and potential of individuals, often in line with broader national development goals.
    • الإرث الثقافي (Cultural Heritage): The legacy of physical artifacts and intangible attributes of a group or society that are inherited from past generations, maintained in the present, and bestowed for the benefit of future generations.
    • الرؤية (Vision) 2030: A strategic framework launched by Saudi Arabia with the goal of diversifying its economy, developing public service sectors, and enhancing its role in the international community.
    01
    قادة مصر والأردن وفرنسا يدعون إلى عودة فورية لوقف إطلاق النار في غزة

    Al Riyadh Newspaper: April 7, 2025 – Key Themes

    Briefing Document: Analysis of Provided Sources

    This briefing document summarizes the main themes, important ideas, and key facts extracted from the provided excerpts of the Al Riyadh newspaper dated Monday, April 7, 2025. The articles cover a range of topics, including international relations, economic developments, local events, cultural initiatives, and social issues within Saudi Arabia and the wider region.

    1. Palestinian Issue:

    • Two-State Solution Support: The Kingdom’s position remains consistent in supporting the legitimate rights of the Palestinian people, emphasizing the necessity of a two-state solution with an independent Palestinian state based on the 1967 borders, with East Jerusalem as its capital.
    • Condemnation of Israeli Policies: Saudi Arabia criticizes Israeli policies, including the construction of the separation wall and settlements, and affirms the Palestinians’ right to self-determination and independence.
    • No Diplomatic Ties Without Recognition: The Kingdom has informed the US administration that there will be no diplomatic relations with Israel unless the independent Palestinian state is recognized on the 1967 borders, East Jerusalem is its capital, and the Israeli aggression on the Gaza Strip ceases with the withdrawal of all Israeli occupation forces.
    • Call for International Recognition: The Kingdom reiterates its constant call to the international community, especially Security Council member states that have not yet recognized Palestine, to recognize the Palestinian state on the 1967 borders with East Jerusalem as its capital. This is to enable the Palestinian people to attain their legitimate rights and for a comprehensive and just peace to be achieved for all.
    • Condemnation of Al-Aqsa Mosque Incursion: Saudi Arabia strongly condemns the storming of the blessed Al-Aqsa Mosque by the Israeli National Security Minister under the protection of the occupation police and the expulsion of worshippers. It reiterates its denunciation of the continued blatant Israeli violations of the sanctity of Al-Aqsa Mosque.
    • Condemnation of Targeting UNRWA Clinic: The Kingdom also condemns the targeting by Israeli occupation forces of a clinic belonging to the United Nations Relief and Works Agency for Palestine Refugees in the Near East (UNRWA) in the Jabalia refugee camp in the northern Gaza Strip, denouncing the continued targeting by Israeli occupation forces.
    • Deteriorating Humanitarian Situation in Gaza: UNICEF reports on the severe food insecurity in the Gaza Strip due to the ongoing Israeli aggression and the continued closure of crossings, preventing the entry of medical aid, supplies, and nutritional supplements for 35 days. Over a million children in Gaza have been deprived of life-saving aid for more than a month, representing a flagrant violation of international humanitarian law.
    • Water Crisis in Gaza: The majority of water wells in Gaza are out of service, and the central desalination plant west of Gaza City is damaged, alongside power shortages. The municipality now relies by 70% on transported water in tankers, part of which is distributed in barrels on carts to areas not reached by the municipal water network. Israeli occupation deliberately targeted water facilities during the aggression, causing significant damage and widespread destruction of wells and networks, creating a severe crisis.
    01
    خبراء الأمم المتحدة لحقوق الإنسان يدعون إلى وضع حد للإبادة الجماعية في غزة

    2. Saudi Arabia’s Internal Affairs and Vision 2030:

    • Eid Al-Fitr Greetings: Princes and officials received well-wishers on the occasion of Eid Al-Fitr in Riyadh and the Eastern Province.
    • Institutional and Service Transformation: The Emir of Hail emphasized that the next stage requires achieving institutional and service transformation in line with the objectives of the Kingdom’s Vision 2030.
    • Human Capabilities Initiative Forum: Riyadh will host the second edition of the Human Capabilities Initiative Forum from April 29 to May 1, 2025, under the patronage of the Crown Prince. The forum aims to unite international efforts, enrich dialogue, exchange expertise, and discuss ideas that enhance the readiness of human capabilities to cope with rapid global changes. Over 300 leaders, policymakers, and experts from various sectors will participate.
    • Global Project Management Forum: Riyadh will also host the fourth edition of the Global Project Management Forum from May 17 to 19, 2025, focusing on “The Next Generation in Project Management: Power of Operations, Power of Human Capital, Power of Technology.” The forum aims to discuss the future of project management, promote innovation, and strengthen the Kingdom’s position as a global leader in this vital field.
    • King Salman Medical City Training Center: The Saudi Commission for Health Specialties has accredited the training program in neurosurgery at King Salman Medical City in Madinah as a comprehensive training program.
    • Ministry of Education at Geneva International Exhibition of Inventions: The Ministry of Education will participate in the 2025 edition of the Geneva International Exhibition of Inventions, showcasing 134 inventions by Saudi talents, including students and companies, reflecting the Kingdom’s focus on national priorities, innovation, and development in line with Vision 2030.
    • Ehsan Platform Recognition: The Ehsan platform was recognized and honored for its outstanding services in achieving sustainable social impact, aligning with the objectives of Vision 2030.
    • King Abdulaziz Center for World Culture (Ithra) Participation: Ithra will participate in the Riyadh Art Week, showcasing the interaction between Saudi cultural heritage and global influences in contemporary art.
    01
    أسهم أوروبا تغلق عند أدنى مستوى في 14 شهرا بسبب الحرب التجارية

    3. Economic Developments and Market Trends:

    • Stock Market Fluctuations: The Saudi stock market experienced fluctuations mirroring global market trends, particularly influenced by US President Trump’s announcement of imposing high customs tariffs on imports, raising fears of a negative impact on the global economy and trade disputes. An analyst noted that the Saudi market values remain fair and that impulsive selling could lead to significant investor losses. Defensive sectors like telecommunications and food are considered relatively safe during the current uncertainty.
    • Impact of US Tariffs: The US imposition of high customs tariffs on imports from several countries, including China and potentially the European Union, is a significant concern. This has led to retaliatory tariffs and increased global trade tensions, raising fears of inflation and a slowdown in economic growth. Experts predict US consumers will face higher prices, and European consumers will also feel the pressure.
    • Oil Price Decline: Oil prices fell significantly by 7% due to China’s increase in customs tariffs on American goods, escalating trade war fears and leading investors to anticipate a greater likelihood of recession. Major investment banks lowered their global oil demand growth forecasts.
    • US-EU Trade Tensions: The European Union is considering a unified response to the US tariffs, likely targeting $28 billion worth of American imports. There are fears that the escalating trade dispute could turn into a global trade war, increasing costs for economies and pushing consumers into recession.
    01
    “الصحة” تؤكد: التحول الصحي أسهم في رفع متوسط العمر المتوقع إلى 78.8 سنة

    4. Regional Security and International Relations:

    • US Envoy’s Visit to Lebanon: The US Deputy Assistant Secretary of State for Near Eastern Affairs visited Lebanon and held meetings with top officials, including President Michel Aoun, to discuss the situation in southern Lebanon and other issues. This coincides with continued Israeli airstrikes on Lebanese territories despite the ongoing cessation of hostilities since November 27. The debate about the disarmament of Hezbollah has resurfaced.
    • Yemen Conflict: The Houthi group announced the killing and injury of six people in an American bombing in Saada governorate, the group’s main stronghold in northern Yemen. The US Central Command confirmed conducting strikes against Houthi missile sites. The Houthis also reported targeting a supply ship of the US aircraft carrier “Truman” with a ballistic missile and claimed to have disrupted “hostile attacks on Yemen” in the past hours, vowing to continue their operations until the aggression on Gaza stops and the blockade is lifted.
    • Iran-US Relations: Oman is reportedly mediating talks between Iran and the United States. The article also outlines key historical junctures in the long-standing rivalry between Tehran and Washington.
    • US Visa Restrictions on South Sudan: The United States imposed unprecedented visa restrictions on citizens of South Sudan, accusing the transitional government of not taking steps to address issues with its citizens who have been deported from the US.
    01
    الالمملكة تُشارك في أعمال الدورة 221 للمجلس التنفيذي لمنظمة اليونسكو

    5. Social and Cultural Events:

    • Riyadh Art Week: Riyadh Art Week is taking place, featuring exhibitions, workshops, and interactive art displays across the capital, highlighting the dynamic contemporary art scene in Saudi Arabia.
    • “Layali Fi Hubb Khalid Al-Faisal” Exhibition: An exhibition titled “Layali Fi Hubb Khalid Al-Faisal” was inaugurated as part of the “Jeddah Season 2025,” celebrating the artistic and literary legacy of Prince Khalid Al-Faisal.
    • King Salman Global Academy for the Arabic Language Program in the US: The King Salman Global Academy for the Arabic Language, in cooperation with Indiana University in the United States, is organizing a specialized scientific program for Arabic language teachers of non-native speakers.
    • Abu Dhabi Arabic Language Centre New Index: The Abu Dhabi Arabic Language Centre announced a new index, “Arabic Language Strength Index,” to measure and track the community’s connection to the Arabic language.
    01
    البنك الدولي يشيد بريادة المملكة في تطوير تقنيات “تحلية المياه

    6. Sports:

    • Saudi U-17 National Team Qualifies for FIFA U-17 World Cup: The Saudi U-17 national team qualified for the FIFA U-17 World Cup 2025 in Qatar after defeating Thailand 3-1 in the AFC U-17 Asian Cup qualifiers held in Taif.
    • Jeddah to Host AFC Basketball Asia Cup Draw: Jeddah will host the draw ceremony for the AFC Basketball Asia Cup, which will be held in Saudi Arabia in early August.
    • Al-Ahli Coach Linked to Bundesliga Club RB Leipzig: Reports suggest that Matthias Jaissle, the coach of Al-Ahli Saudi FC, is a potential candidate to take over as coach of RB Leipzig due to the poor ongoing results of the current coach, Marco Rose.

    7. Opinion and Analysis:

    • The Saudi Role in International Mediation: An opinion piece highlights Saudi Arabia’s growing political standing and its potential to become a significant global mediator in international conflicts, especially in the Middle East, driven by Vision 2030.
    • The Impact of Artificial Intelligence on Human Thought: An article discusses the increasing reliance on artificial intelligence for analysis and decision-making, raising concerns about the potential decline of human critical thinking and the risk of humans becoming overly dependent on machines.
    • Critique of Al-Hilal Football Club Performance: A fan expresses disappointment with the recent performance of Al-Hilal football club, stating that the team no longer strikes fear in opponents and needs to address the level of some players.

    8. Traffic Regulations and Safety:

    • General Directorate of Traffic Clarifies Enforcement Procedures: The General Directorate of Traffic clarified that vehicle impoundment or penalty enforcement will only occur after the expiry of the grace period stipulated by regulations (Article 75), emphasizing that fines are doubled only if payment is not made within the specified period. The system offers violators several options, including a 30-day grace period with a 25% discount if paid within that period, and the possibility of requesting a 90-day extension for payment within the first 15 days of the violation being recorded.
    • Citizens Demand Addressing Dangerous Afif/Qassim Road: Citizens and travelers are urging relevant authorities to address the dangerous state of the Afif/Qassim road, which has become a major artery but suffers from poor condition, potholes, and frequent truck traffic, leading to accidents. They are calling for the acceleration of the road dualization project.

    9. Customs and Smuggling:

    • Saudi Customs Records 1071 Seizure Cases: Saudi customs outlets recorded 1071 seizure cases of prohibited items, including drugs, controlled substances, tobacco products, and monetary amounts, reflecting the ongoing efforts of the Zakat, Tax and Customs Authority to enhance security and protect society.

    This briefing document provides a snapshot of the diverse issues and events covered in the provided excerpts from Al Riyadh newspaper, highlighting Saudi Arabia’s active engagement in regional and international affairs, its focus on achieving the goals of Vision 2030, and various local developments and social concerns.

    Saudi Arabia: Global Events and Initiatives

    FAQ on the Provided Sources

    1. What are the key historical and ongoing issues concerning Palestine as highlighted in the sources?

    The sources emphasize the 1947 UN Resolution 181 calling for the division of Palestine into two states and the subsequent 1948 Arab-Israeli War, which led to the displacement of hundreds of thousands of Palestinians. The international stance, supported by the Kingdom of Saudi Arabia, advocates for a two-state solution with an independent Palestinian state based on the 1967 borders, with East Jerusalem as its capital. The sources criticize Israeli policies such as building the separation wall and expanding settlements, while affirming the rights of Palestinians, including their right to self-determination and independence. The Kingdom of Saudi Arabia maintains that there will be no diplomatic relations with Israel without the recognition of an independent Palestinian state within the 1967 borders and the withdrawal of Israeli forces from the Gaza Strip. The continued Israeli incursions into Al-Aqsa Mosque and targeting of UNRWA facilities in Gaza are also condemned.

    2. What is the Kingdom of Saudi Arabia’s position on the Palestinian issue and what actions does it advocate for?

    The Kingdom of Saudi Arabia’s position on the Palestinian issue is firm and supportive of the legitimate rights of the Palestinian people, including their right to an independent state based on the 1967 borders with East Jerusalem as its capital. Saudi Arabia insists that there will be no diplomatic ties with Israel until an independent Palestinian state is recognized within these borders and the Israeli aggression against Gaza ends with a full withdrawal of its forces. The Kingdom consistently calls on the international community, particularly permanent members of the UN Security Council, to recognize the State of Palestine. It strongly condemns Israeli actions such as incursions into Al-Aqsa Mosque and attacks on Palestinian civilians and facilities, urging an end to these violations.

    3. How did the Riyadh stock market and Saudi economy react to global economic events and trends mentioned in the sources?

    The Riyadh stock market experienced a downturn, mirroring global market declines following concerns over potential US tariffs on imports announced by President Trump. This sparked fears of trade wars and negative impacts on the global economy. Despite the market fluctuations, Saudi economic analysts maintained that the Saudi market values remained fair and cautioned against impulsive selling, emphasizing the strong fundamentals of the Saudi economy, particularly the expected significant spending by tourists in 2024. Certain sectors like telecommunications and food were considered defensive in the face of economic uncertainty. The drop in oil prices, partly attributed to China’s retaliatory tariffs on US goods, also influenced the economic outlook.

    4. What initiatives and events are being organized in Saudi Arabia to promote human capital development and innovation, as highlighted in the sources?

    Saudi Arabia is actively investing in human capital development through initiatives like the “Human Capability Initiative” conference, scheduled for April 2025 in Riyadh. This major event, under the patronage of the Crown Prince, aims to prepare for future needs by focusing on developing human capabilities to adapt to rapid global changes. It will bring together over 300 global experts and leaders from various sectors to exchange ideas and promote readiness for the future job market. The Ministry of Education is also partnering in this effort, including hosting an educational exhibition. Additionally, King Abdulaziz University is organizing a conference on digital media and communication, and the Riyadh will host the Global Project Management Forum, all indicating a strong focus on development and innovation in line with Vision 2030.

    5. What are the concerns and reactions regarding potential trade wars and tariffs, as discussed in the sources?

    The sources express significant concern over the potential for escalating trade wars triggered by the United States imposing tariffs on imports, particularly from China. This has led to retaliatory tariffs and fears of a global economic slowdown or recession. International organizations like the United Nations Conference on Trade and Development (UNCTAD) have voiced concerns about the negative impact on poorer nations. The European Union is also considering a unified response to US tariffs, fearing a broader trade conflict that could harm global economies and consumers. Economic experts predict potential price increases for consumers and disruptions to international trade. The historical context of past tariffs and their impacts, such as during the Great Depression, is also referenced, highlighting the potential dangers of protectionist trade policies.

    6. What is the situation in Gaza concerning humanitarian aid, water resources, and the impact of ongoing conflict on civilians, especially children?

    The situation in Gaza is dire, with severe restrictions on the entry of humanitarian aid, medical supplies, and food, ongoing for at least 35 days according to UNICEF. This has led to a critical lack of essential resources, including treatment for malnutrition in children, exacerbated by renewed Israeli military actions. The conflict has caused widespread displacement, with nearly 1.9 million people, including many children, repeatedly forced to flee amidst shelling, fear, and loss. Water infrastructure has been severely damaged, with the central desalination plant west of Gaza City impacted, leading to a heavy reliance on tanker trucks to distribute limited water supplies. The psychological impact on civilians, particularly children, is also significant. The UN and other organizations continue to call for an end to hostilities and unfettered access for humanitarian assistance.

    7. What cultural and heritage-related events and initiatives are highlighted in the sources within Saudi Arabia?

    The sources showcase a vibrant cultural scene in Saudi Arabia. The “Nights in the Love of Khaled Al-Faisal” event in Jeddah, part of the “Jeddah Season 2025,” celebrates the artistic and literary contributions of Prince Khaled Al-Faisal. Riyadh is hosting “Riyadh Art Week,” featuring over 45 galleries and artistic spaces, aiming to highlight the Kingdom’s contemporary art scene and its interaction with the global art world. The King Salman Global Academy for the Arabic Language is collaborating with Indiana University in the US to conduct a training program for Arabic language teachers, emphasizing the development of modern teaching methods. Additionally, the Abu Dhabi Arabic Language Centre announced a new index, “Arabic Language Strength Index,” to measure and track the Arab community’s connection with the Arabic language. The historical village of Saduq, near Riyadh, is presented as a living heritage site reflecting the region’s deep historical and cultural roots. The revival of the traditional Najdi war dance during Eid celebrations in Al-Salmiyah also underscores efforts to preserve and pass on cultural heritage.

    8. What are some of the international political and diplomatic activities involving Saudi Arabia mentioned in the sources, beyond the Palestinian issue?

    Beyond its consistent stance on Palestine, Saudi Arabia is portrayed as an active player in international diplomacy. The sources mention Saudi Arabia hosting American, Russian, and Ukrainian officials for talks, indicating its potential role as a mediator in global conflicts. This is seen as a reflection of Saudi Arabia’s growing capabilities and ambitions in international relations, particularly in conflict resolution. The Kingdom’s Vision 2030 is credited with enhancing Saudi Arabia’s political standing and its ability to influence international issues. The sources suggest a future where Saudi Arabia plays an increasingly significant role in international mediation, moving beyond its traditional role in a region often associated with conflict.

    Israeli Actions in Lebanon, Syria, and Jerusalem

    The sources discuss Israeli occupation forces in several contexts.

    One source mentions an Israeli raid in southern Lebanon, where the Israeli army announced it targeted two operatives in “Hezbollah”. A statement from the Lebanese Ministry of Health reported that the final death toll from this raid rose to two, after one injured person in Zibqin died from their severe wounds. The Israeli military spokesperson stated that the two individuals were targeted while rebuilding “terrorist infrastructure belonging to Hezbollah” in the “engineering sector”.

    Another source discusses the Al-Aqsa Mosque in Jerusalem, mentioning that “Jewish Talmudic groups” according to “Temple organizations” are advocating for the introduction and slaughter of a young goat inside the mosque as a “sacrifice to God on the Arab Passover every year”. This source also notes that these “Temple” groups have managed to perform some rituals inside Al-Aqsa in past years, while their attempts to conduct animal sacrifices have failed, as this is described as the only religious ritual they haven’t been able to carry out inside the mosque. The context here refers to “the occupation,” indicating the perspective of those who view Israel’s presence in Jerusalem as an occupation.

    Furthermore, the sources report on Israeli military actions in other regions, including “Israeli attacks” in Syria and a potential future “Israel attack”. A strike in Sidon, southern Lebanon, is also mentioned, following the killing of a leader in the Izz al-Din al-Qassam Brigades, his daughter, and his grandson in an Israeli raid in Hama, Syria. This strike in Sidon is noted as the second instance targeting the capital’s suburbs since a ceasefire was established.

    The sources also refer to a past ceasefire agreement that stipulated the withdrawal of “Hezbollah” to north of the Litani River and the dismantling of their military installations, in exchange for the withdrawal of the Israeli army from all Lebanese territories it entered during a previous war. This agreement was considered a victory for Lebanon, linked to previous international resolutions, including those related to disarming all non-state forces. The text explicitly mentions “the occupied Lebanese territories” in this context.

    Additionally, one source indicates that “Israel authorities” have a responsibility under international humanitarian law to ensure the basic needs of the population in the Gaza Strip are met. This implies a degree of control or responsibility over the territory and its inhabitants, consistent with the concept of occupation, although the term itself is not used in this specific instance.

    Al-Aqsa Mosque: Israeli-Palestinian Context and Temple Groups

    The sources discuss the Al-Aqsa Mosque in Jerusalem in the context of the Israeli-Palestinian issue and actions by certain religious groups.

    One source mentions the Al-Aqsa Mosque in Jerusalem while reporting on the Kingdom’s condemnation of the Israeli occupation forces targeting a UNRWA clinic in the Jabalia camp in the Gaza Strip. This indicates that the Al-Aqsa Mosque is located in a context where Israel’s presence is viewed as an occupation.

    Another source reports on calls by the “Return to the Temple Mount” organization urging its supporters to start attempting to slaughter sacrifices, such as a goat or sheep, inside the Al-Aqsa Mosque or at its gates during the Jewish Passover. This call was directed at supporters in the Old City of occupied Jerusalem, with the intention of trying throughout the following week to present the sacrifice at the “appropriate time” according to their interpretation of the Torah.

    Furthermore, the sources detail that “Jewish Talmudic groups,” as stated by “Temple” organizations, advocate for the introduction and slaughter of a young goat inside the Al-Aqsa Mosque every year as a “sacrifice to God on the Arab Passover”. These “Temple” groups have reportedly succeeded in performing some religious rituals inside Al-Aqsa in past years, such as blowing the horn and offering plant sacrifices. However, their attempts to conduct animal sacrifices inside the mosque have failed, and this is described as the only religious ritual they haven’t been able to carry out there. This discussion about the Al-Aqsa Mosque is framed within the context of the “occupation”.

    Gaza: Humanitarian Crisis and Regional Conflict

    The sources discuss the Gaza Strip primarily in the context of the humanitarian crisis and the ongoing Israeli-Palestinian conflict.

    One source highlights the critical need for humanitarian aid to enter the Gaza Strip. UNICEF has thousands of life-saving aid parcels, intended mostly for Gaza, that are currently being stored. Edward Beigbeder, UNICEF Regional Director for the Middle East and North Africa, emphasized the urgency of allowing immediate aid access, stating that it is a legal obligation under international law, not merely a charitable act. He specifically called on Israeli authorities to ensure the basic needs of the Palestinian population in the Gaza Strip are met, in accordance with their responsibilities under international humanitarian law. This includes the legal duty to guarantee the provision of essential items like food and medicine for families to survive.

    Furthermore, the Gaza Strip is mentioned as a central point of solidarity in the region’s conflicts. Houthi forces have announced the resumption of naval attacks in the Red Sea and the Arabian Sea in support of the “Palestinian people in Gaza” against what they identify as “Israeli ships”. Their stated goal is to continue these operations and prevent navigation until the “aggression” against Gaza ceases and the blockade is lifted. This group is described as being aligned with Iran. In response, the United States has reportedly restarted intensive air strikes on Houthi-controlled areas in Yemen after a pause.

    Additionally, one of the sources mentions that the Kingdom condemned the actions of “Israeli occupation forces” for targeting a UNRWA clinic in the Jabalia camp within the Gaza Strip. This indicates a perspective that views Israel as the occupying power in Gaza and denounces military actions taken by Israeli forces there.

    US Trade Tariffs and Global Economic Impact

    The sources discuss trade tariffs primarily in the context of actions taken by the United States, particularly under the administration of Donald Trump, and the responses from other countries and economic observers.

    Several sources highlight a mutual trade tariff war between the USA and the rest of the world, triggered by US actions. Economists have advised investors to exercise caution and re-evaluate their investment strategies amidst these increasing trade tensions. The market downturn has been partly attributed to China imposing retaliatory tariffs on the United States. In response to these developments, the US Treasury Secretary acknowledged that the stock market experienced a short-term decline due to the tariffs but did not believe they would be the sole cause of an economic recession.

    One source notes that US trade tariffs have historically rarely yielded positive outcomes. It points out that Donald Trump’s recent implementation of tariffs was a departure from the United States’ long-standing promotion of free trade and globalization. Historically, the US has imposed tariffs, but these measures have often failed to achieve convincing results. Trump’s policies included rejecting multilateral trade agreements such as the World Trade Organization (WTO) and the North American Free Trade Agreement (NAFTA), which was renegotiated into USMCA. These actions reflect a unilateral “America First” approach. Trump’s motivations included bolstering American industries, particularly in rural and industrial areas that form his electoral base, and reducing the federal budget deficit.

    The European Union (EU) has also discussed the implications of US tariffs and potential countermeasures. EU ministers aimed to present a unified response and indicated a readiness to implement retaliatory measures if negotiations with Washington to remove the tariffs were unsuccessful.

    Regarding the impact on other regions, the sources specifically mention Saudi Arabia and other Gulf countries. While the direct impact of US tariffs might be limited due to exemptions for energy products, there could be indirect effects. A slowdown in the US economy, potentially caused by these trade tensions, could reduce global demand for oil and petrochemical products, affecting the revenues of Gulf oil-producing nations. A more significant concern for the Gulf region was the consideration by Trump’s team to devalue the US dollar, which could lead to a reshaping of the global financial system.

    Overall, the sources portray the imposition of trade tariffs by the US as a significant shift in international trade policy, generating retaliatory actions from other major economies and causing concern among investors and economic policymakers globally.

    Global Cultural Exchange Initiatives

    The sources discuss several cultural exchange initiatives across different fields, including language, arts, and broader human development.

    One significant cultural exchange initiative is the cooperation between the King Salman Global Academy for the Arabic Language and Indiana University in the United States. This is a project aimed at training Arabic language teachers for non-native speakers. The program focuses on developing the teachers’ educational capabilities through advanced teaching methods and enhancing the skills of their students. According to the Secretary-General of the academy, “this program comes as a completion of the efforts made in developing the skills of Arabic language teachers and learners for non-native speakers”. The initiative reflects the academy’s “keenness to exchange experiences with Indiana University to benefit from academic expertise and the best practices in teaching the Arabic language at the international level”. The program includes a “specialized training course on linguistic tests and a course specialized in training on the ‘Hamza’ test (an academic test)”, emphasizing the practical application of assessment tools.

    Another prominent cultural exchange initiative is “Riyadh Art Week”. This event is described as a “platform that brings together various components of the artistic scene in the Kingdom and the world, thereby contributing to drawing the features of the future of art in the region”. It aims to foster “purposeful dialogues between local and international artistic communities”. The week encompasses various activities, including “conversations and workshops”, a “video art program” showcasing the works of both “Saudi and international artists”, and “carefully curated art exhibitions” that are accompanied by “discussion sessions and interactive workshops” on local and global artistic topics. Notably, “a number of prominent Saudi artists open the doors of their studios to visitors, providing a unique opportunity for direct interaction with their creative methods”. The themes explored during the event include “the role of art in inspiration, connection, and challenge”, and it delves into topics like “how human arts face global and emerging issues”.

    The upcoming “Human Capability Initiative conference” in Riyadh, in partnership with the Ministry of Education and the international education exhibition (EDGEx), also has aspects of cultural exchange. This initiative is intended to “discuss the latest practices and major projects in various sectors” and serve as a “platform for exchanging opinions and visions about projects, with the aim of achieving greater success and enhancing human capabilities”. The target audience includes professionals from the government and private sectors, engineering and contracting companies, entrepreneurs, consultants, and youth office managers, suggesting a broad exchange of knowledge and expertise.

    Additionally, the “Winter at Tantora” festival is mentioned as a “global event that brings different cultures together”, explicitly highlighting its role in cultural exchange.

    These examples demonstrate diverse cultural exchange initiatives discussed in the sources, spanning from formal academic collaborations focused on language education to large-scale artistic events fostering dialogue and interaction between local and international artists, as well as broader forums for the exchange of ideas and practices in human development and festivals celebrating cultural diversity.

    Main Headings

    • برعاية الملك.. تكريم الفائزات بجائزة الأميرة نورة للتميز النسائي Under the King’s patronage, winners of the Princess Noura Award for Women’s Excellence are honored.
    • السوق السعودي يواكب هبوط البورصـات العالميـة The Saudi market keeps pace with the decline of global stock markets.
    • التصدي للتحايل بربط التأشيرة بمدة برنامج العمرة Combating fraud by linking the visa to the duration of the Umrah program
    • لبنان: مقتل شخصين في غارة إسرائيلية Lebanon: Two killed in Israeli airstrike
    • طـــهـــران تـــعـــارض عــقــد مـــفـــاوضـــات مــبــاشــرة مـــع واشــنــطــن Tehran opposes direct negotiations with Washington
    • غزة: مليون طفل يواجهون شبح المجاعة Gaza: One million children face the specter of famine

    By Amjad Izhar
    Contact: amjad.izhar@gmail.com
    https://amjadizhar.blog

  • Foundations of Linear Algebra: Core Concepts and Applications

    Foundations of Linear Algebra: Core Concepts and Applications

    The provided text serves as a foundational resource for linear algebra, starting with basic concepts like vectors, vector spaces, real numbers, and geometric interpretations of these ideas. It progresses to vector operations such as addition, subtraction, scalar multiplication, and the crucial concepts of linear combinations and spans. The material then introduces special vectors like zero and unit vectors, along with the notion of linear independence and dependence. Further topics include the dot product and its relation to vector length, followed by an introduction to matrices, their operations (addition, subtraction, scalar multiplication, and matrix multiplication), and special types of matrices. The text also explores determinants and their geometric significance before moving into more advanced topics like vector spaces, bases, projections, orthonormal bases achieved through the Gram-Schmidt process, and finally, matrix decomposition techniques.

    Vector Norms, Distances, Vector Operations, and Matrix Fundamentals Study Guide

    I. Key Concepts and Definitions:

    A. Vectors: * Definition: A quantity having magnitude and direction, often represented as an ordered list of numbers (components or entries). * Representation: Column vectors are commonly used, enclosed in square brackets (e.g., [x, y]). * Dimensions: An $n$-dimensional vector has $n$ components and belongs to the vector space $\mathbb{R}^n$. * Equality: Two vectors are equal if and only if all their corresponding components are equal.

    B. Scalars: * Definition: A quantity with only magnitude (a single number).

    C. Vector Norms: * Definition: A function that assigns a non-negative length or size to each vector in a vector space. * Norm Two (Euclidean Norm or $L^2$ Norm): For a vector $v = [v_1, v_2, …, v_n]^T$, the norm two is $||v||_2 = \sqrt{v_1^2 + v_2^2 + … + v_n^2}$.

    D. Euclidean Distance: * Definition: The straight-line distance between two points in Euclidean space. * Formula: The Euclidean distance between two vectors $a = [a_1, a_2, …, a_n]^T$ and $b = [b_1, b_2, …, b_n]^T$ is $d(a, b) = ||a – b||_2 = \sqrt{(a_1 – b_1)^2 + (a_2 – b_2)^2 + … + (a_n – b_n)^2}$. * Relationship to Norm: The Euclidean distance between two points is the norm of the vector connecting them.

    E. Special Vectors: * Zero Vector: A vector where all components are zero, denoted by $\vec{0}$. * Unit Vector: A vector with a magnitude (norm) of one. * Standard Unit Vectors ($e_i$): Vectors with a single component equal to one and all other components equal to zero (e.g., in $\mathbb{R}^3$, $e_1 = [1, 0, 0]^T$, $e_2 = [0, 1, 0]^T$, $e_3 = [0, 0, 1]^T$). * Sparse Vector: A vector with many of its entries as zero.

    F. Vector Operations: * Addition: Adding two vectors of the same dimension is done component-wise: $(a + b)_i = a_i + b_i$. * Subtraction: Subtracting two vectors of the same dimension is done component-wise: $(a – b)_i = a_i – b_i$. * Scalar Multiplication: Multiplying a vector by a scalar multiplies each component of the vector by that scalar: $(ca)_i = c \cdot a_i$.

    G. Properties of Vector Addition: * Commutativity: $a + b = b + a$ * Associativity: $(a + b) + c = a + (b + c)$ * Identity Element: $a + \vec{0} = \vec{0} + a = a$ * Inverse Element: $a + (-a) = (-a) + a = \vec{0}$, where $-a$ is the vector with components $-a_i$.

    H. Linear Combination: * Definition: A vector formed by multiplying a set of vectors by scalars and adding the results. For vectors $v_1, v_2, …, v_k$ and scalars $c_1, c_2, …, c_k$, the linear combination is $c_1v_1 + c_2v_2 + … + c_kv_k$. * Coefficients: The scalars ($c_i$) in a linear combination.

    I. Span of Vectors: * Definition: The set of all possible linear combinations of a set of vectors. * Example: The span of two non-collinear vectors in $\mathbb{R}^2$ is the entire $\mathbb{R}^2$. The span of two collinear vectors in $\mathbb{R}^2$ is a line through the origin. The span of a single non-zero vector in $\mathbb{R}^2$ is a line through the origin. The span of the zero vector is just the zero vector.

    J. Dot Product (Scalar Product): * Definition: An operation that takes two equal-length sequences of numbers (usually coordinate vectors) and returns a single number. * Formula: For two vectors $a = [a_1, a_2, …, a_n]^T$ and $b = [b_1, b_2, …, b_n]^T$, their dot product is $a \cdot b = a_1b_1 + a_2b_2 + … + a_nb_n$. * Relationship to Norm: $v \cdot v = ||v||_2^2$.

    K. Matrices: * Definition: A rectangular array of numbers arranged in rows and columns. * Dimensions: An $m \times n$ matrix has $m$ rows and $n$ columns. * Indexing: The element in the $i$-th row and $j$-th column is denoted as $A_{ij}$ or $a_{ij}$. * Square Matrix: A matrix with an equal number of rows and columns ($m = n$). * Identity Matrix ($I_n$): An $n \times n$ square matrix with ones on the main diagonal (from the upper-left to the lower-right) and zeros everywhere else. * Matrix Equality: Two matrices are equal if and only if they have the same dimensions and all their corresponding entries are equal.

    L. Matrix Operations: * Scalar Multiplication: Multiplying a matrix by a scalar multiplies each entry of the matrix by that scalar. * Matrix Addition and Subtraction: Performed element-wise on matrices of the same dimensions. * Matrix Multiplication: The product of an $m \times k$ matrix $A$ and a $k \times n$ matrix $B$ is an $m \times n$ matrix $C$, where $C_{ij} = \sum_{l=1}^{k} A_{il}B_{lj}$ (the dot product of the $i$-th row of $A$ and the $j$-th column of $B$).

    M. Properties of Matrix Operations: * Associativity of Matrix Multiplication: $(AB)C = A(BC)$ * Distributivity: $A(B + C) = AB + AC$ and $(A + B)C = AC + BC$ * Scalar Multiplication with Matrix Multiplication: $r(AB) = (rA)B = A(rB)$ * Identity Matrix Property: $AI = IA = A$, where $I$ is the identity matrix of appropriate dimension.

    N. Determinants: * Definition (for a $2 \times 2$ matrix): For a matrix $A = \begin{pmatrix} a & b \ c & d \end{pmatrix}$, the determinant is $\det(A) = ad – bc$. * Calculation (by cofactor expansion): The determinant of a matrix can be calculated by expanding along any row or column using cofactors. * Properties: * $\det(I) = 1$ * Swapping two rows (or columns) changes the sign of the determinant. * If a matrix has a row (or column) of zeros, its determinant is zero. * If a matrix has two identical rows (or columns), its determinant is zero. * Multiplying a row (or column) by a scalar $c$ multiplies the determinant by $c$. * $\det(A^T) = \det(A)$ * $\det(AB) = \det(A)\det(B)$

    O. Basis of a Vector Space: * Definition: A set of linearly independent vectors that span the entire vector space. * Properties: Every vector in the space can be expressed as a unique linear combination of the basis vectors.

    P. Orthonormal Basis: * Definition: A basis where all vectors in the set are orthogonal to each other and each vector has a norm (length) of one (they are unit vectors). * Orthogonal Vectors: Two vectors $u$ and $v$ are orthogonal if their dot product is zero ($u \cdot v = 0$). * Gram-Schmidt Process: An algorithm for orthonormalizing a set of linearly independent vectors in an inner product space.

    II. Quiz:

    1. Explain the relationship between the Euclidean norm of a vector and the Euclidean distance between two points.
    2. What are the key differences between a zero vector and a unit vector? Provide an example of each in $\mathbb{R}^3$.
    3. Describe the process of adding two vectors and multiplying a vector by a scalar. How do the dimensions of the vectors play a role?
    4. State the commutative and associative properties of vector addition. Provide a brief example to illustrate one of these properties.
    5. Define a linear combination of vectors. What role do the coefficients in a linear combination play?
    6. Explain the concept of the span of a set of vectors. What does it mean if the span of a set of vectors in $\mathbb{R}^n$ is equal to $\mathbb{R}^n$?
    7. What is the formula for the dot product of two $n$-dimensional vectors? How is the dot product related to the norm of a vector?
    8. Describe the structure of an $n \times n$ identity matrix. How does it behave when multiplied by another matrix?
    9. For a $2 \times 2$ matrix $A = \begin{pmatrix} a & b \ c & d \end{pmatrix}$, what is its determinant? How does swapping the rows of $A$ affect its determinant?
    10. Define a basis of a vector space. What two key properties must a set of vectors satisfy to form a basis?

    III. Quiz Answer Key:

    1. The Euclidean distance between two points (represented by vectors $a$ and $b$) is defined as the Euclidean norm of the vector that connects these two points, which is the vector $a – b$ (or $b – a$). Thus, $d(a, b) = ||a – b||_2$.
    2. A zero vector is a vector where all its components are zero (e.g., $[0, 0, 0]^T$ in $\mathbb{R}^3$), and its magnitude is zero. A unit vector is a vector whose Euclidean norm (length) is one (e.g., $[1, 0, 0]^T$ in $\mathbb{R}^3$).
    3. To add two vectors, their corresponding components are added together. To multiply a vector by a scalar, each component of the vector is multiplied by that scalar. Vector addition is only defined for vectors of the same dimension, and the resulting vector has the same dimension.
    4. The commutative property states that the order of addition does not matter: $a + b = b + a$. For example, if $a = [1, 2]^T$ and $b = [3, 4]^T$, then $a + b = [4, 6]^T$ and $b + a = [4, 6]^T$.
    5. A linear combination of vectors $v_1, v_2, …, v_k$ is a sum of scalar multiples of these vectors: $c_1v_1 + c_2v_2 + … + c_kv_k$. The coefficients ($c_i$) determine how each vector is scaled and contribute to the resulting vector of the combination.
    6. The span of a set of vectors is the set of all vectors that can be formed by taking linear combinations of the original vectors. If the span of a set of vectors in $\mathbb{R}^n$ is equal to $\mathbb{R}^n$, it means that any vector in the $n$-dimensional space can be expressed as a linear combination of the vectors in that set.
    7. The dot product of two $n$-dimensional vectors $a = [a_1, …, a_n]^T$ and $b = [b_1, …, b_n]^T$ is $a \cdot b = a_1b_1 + … + a_nb_n$. The dot product of a vector with itself is equal to the square of its Euclidean norm: $v \cdot v = ||v||_2^2$.
    8. An $n \times n$ identity matrix ($I_n$) is a square matrix with ones on its main diagonal and zeros elsewhere. When an $m \times n$ matrix $A$ is multiplied by an $n \times n$ identity matrix $I_n$, the result is $A$. Similarly, when an $n \times n$ identity matrix $I_n$ is multiplied by an $n \times k$ matrix $B$, the result is $B$.
    9. For $A = \begin{pmatrix} a & b \ c & d \end{pmatrix}$, $\det(A) = ad – bc$. Swapping the rows of $A$ results in the matrix $\begin{pmatrix} c & d \ a & b \end{pmatrix}$, whose determinant is $cb – da = -(ad – bc) = -\det(A)$. Thus, swapping rows changes the sign of the determinant.
    10. A basis of a vector space is a set of vectors that satisfies two key properties: (1) the vectors in the set must be linearly independent (no vector in the set can be expressed as a linear combination of the others), and (2) the vectors in the set must span the entire vector space (every vector in the space can be expressed as a linear combination of the basis vectors).

    IV. Essay Format Questions:

    1. Discuss the significance of vector norms and Euclidean distance in various fields such as machine learning and data analysis. Provide specific examples of how these concepts are applied.
    2. Explain the concept of linear dependence and linear independence of vectors. How is this concept related to the idea of a basis for a vector space and the uniqueness of linear combinations?
    3. Describe the process of matrix multiplication and its properties. Compare and contrast matrix multiplication with scalar multiplication and discuss the implications of the non-commutative nature of matrix multiplication.
    4. Explain the concept of the determinant of a square matrix and its key properties. Discuss the geometric interpretation of the determinant in two and three dimensions.
    5. Describe the Gram-Schmidt process for orthonormalizing a set of linearly independent vectors. Explain the importance of orthonormal bases in linear algebra and its applications.

    V. Glossary of Key Terms:

    • Vector: A quantity with both magnitude and direction, represented as an ordered list of numbers.
    • Scalar: A quantity with only magnitude (a single number).
    • Norm: A function that assigns a non-negative length or size to a vector.
    • Euclidean Norm ($L^2$ Norm): The square root of the sum of the squares of the vector’s components, representing its length.
    • Euclidean Distance: The straight-line distance between two points in Euclidean space.
    • Zero Vector: A vector with all components equal to zero.
    • Unit Vector: A vector with a magnitude (norm) of one.
    • Standard Unit Vectors: Vectors with one component equal to one and all others zero.
    • Sparse Vector: A vector with many zero entries.
    • Linear Combination: A vector formed by a sum of scalar multiples of other vectors.
    • Span: The set of all possible linear combinations of a set of vectors.
    • Dot Product: An operation on two vectors that returns a scalar, calculated as the sum of the products of their corresponding components.
    • Matrix: A rectangular array of numbers arranged in rows and columns.
    • Square Matrix: A matrix with an equal number of rows and columns.
    • Identity Matrix: A square matrix with ones on the main diagonal and zeros elsewhere.
    • Determinant: A scalar value that can be computed from the elements of a square matrix, providing information about the matrix’s properties.
    • Basis: A set of linearly independent vectors that span the entire vector space.
    • Orthonormal Basis: A basis where all vectors are orthogonal (dot product is zero) and have a norm of one.
    • Orthogonal Vectors: Two vectors whose dot product is zero.
    • Gram-Schmidt Process: An algorithm for orthonormalizing a set of linearly independent vectors.

    Briefing Document: Review of Linear Algebra Concepts

    This briefing document summarizes the main themes and important ideas from the provided source material, focusing on foundational concepts in linear algebra, including vectors, norms, distance, matrices, determinants, linear transformations, and the Gram-Schmidt process.

    I. Vectors: Fundamental Building Blocks

    • Definition and Representation: Vectors are quantities possessing both magnitude (length) and direction, distinguishing them from scalars, which only have magnitude. They can be represented geometrically as arrows in space or algebraically as ordered lists of numbers (components or entries).
    • In a two-dimensional space (R²), a vector can be represented as [x, y] or using parentheses like (4, 0) or {3, 4}. The components indicate the movement along the horizontal (x) and vertical (y) axes.
    • In an n-dimensional space (Rⁿ), a vector a is represented as a column of n elements:
    • [ A₁ ]
    • [ A₂ ]
    • [ … ]
    • [ A<0xE2><0x82><0x99> ]
    • The index of a vector’s element starts from 1 to n. Notation like Aᵢ refers to the i-th element of vector A.
    • Vectors can also contain other vectors as entries (nested vectors), which can be represented using capital letters (e.g., A) with arrow notation for the vector entries (e.g., A₁). In such cases, double indexing (e.g., a₁₁) is used to denote the element within a specific vector entry.
    • Magnitude (Norm) and Distance:
    • The norm of a vector measures its size or length. For a vector v = [v₁, v₂, …, v<0xE2><0x82><0x99>], the norm (specifically the L₂ norm or Euclidean norm) is calculated as:
    • ||v|| = √(v₁² + v₂² + … + v<0xE2><0x82><0x99>²)
    • “take all the units that form this vector and then so are on this vector and use them Square them and then add them and then take the square root of that that’s the distance or I have to say the norm of this Vector”. For example, the norm of vector v = [3, 4] is √(3² + 4²) = √25 = 5.
    • The Euclidean distance (also called L₂ distance or “aladine distance” in the source) between two points (vectors) A and B in n-dimensional space is the norm of the vector connecting A to B (B – A or A – B).
    • d(A, B) = ||B – A|| = √((B₁ – A₁)² + (B₂ – A₂)² + … + (B<0xE2><0x82><0x99> – A<0xE2><0x82><0x99>)²)
    • “the aladan distance between two points let’s say A and B in N dimensional space is the norm of the vector connecting a to B”. The order of subtraction inside the square doesn’t matter due to the squaring operation.
    • Special Vectors:
    • Zero Vector: A vector where all its components are zero. Denoted as 0 with an arrow on top (e.g., 0 in R³ is [0, 0, 0]). “the zero and arrow on the top it basically refers to the vector like we saw before only with the difference that all its me numbers are zero”.
    • Unit Vectors: Vectors with one element equal to one and all others zero. The i-th unit vector in n dimensions, eᵢ, has a 1 in the i-th position and 0 elsewhere (e.g., in R³, e₁ = [1, 0, 0], e₂ = [0, 1, 0], e₃ = [0, 0, 1]). “vectors with a single element equal to one and all the others zero denoted as EI for the E unit Vector in N dimensions are referred by unit vectors”.
    • Sparse Vectors: Vectors with many of their entries as zero.
    • Vector Operations:
    • Addition: Two vectors of the same dimension are added element-wise. “when it comes to Vector addition we just add the corresponding elements”.
    • Subtraction: Similar to addition, subtraction is performed element-wise.
    • Scalar Multiplication: Multiplying a vector by a scalar involves multiplying each component of the vector by that scalar, effectively scaling the vector’s magnitude. “formally the scalar multiplication involves multiplying each component of a vector by scalar value effectively scaling the vector’s magnitude”.
    • Properties of Vector Addition:
    • Commutative: a + b = b + a. “adding two different VOR the direction or the order is not important”.
    • Associative: (a + b) + c = a + (b + c).
    • Identity Element: There exists a zero vector 0 such that a + 0 = a. “adding a zero Vector to this original a vector or not we in all cases it just adding a zero Vector has no effect”.
    • Inverse Element: For every vector a, there exists a vector -a such that a + (-a) = 0. Subtracting a vector from itself results in the zero vector. “when we have a vector consisting of the scalers like a is equal 2 23 in the same manner if we take this a and we subtract it from itself so a minus a then what we will get is … Vector zero”.
    • Applications of Vectors:
    • Word Counting: Vectors can represent the frequency of words in a document. Each element of the vector corresponds to a word in a dictionary, and the value represents the number of times that word appears. This is fundamental in natural language processing for tasks like topic modeling and sentiment analysis. “a vector of a length n for instance can represent the number of times each of these words in a dictionary of n words appears in a document”.
    • Customer Purchases: Vectors can record customer purchases over time, with each element representing the quantity or dollar value of a specific item purchased.

    II. Span and Linear Combinations

    • Linear Combination: A linear combination of vectors A₁, A₂, …, A<0xE2><0x82><0x99> is an expression of the form β₁A₁ + β₂A₂ + … + β<0xE2><0x82><0x99>A<0xE2><0x82><0x99>, where β₁, β₂, …, β<0xE2><0x82><0x99> are scalar coefficients. “a linear combination simply involves taking several vectors … and to get a linear combination we need to uh scale each of those vectors which means that we need to have these different scalers”. The scalars are the “coefficients of linear combination”.
    • Span: The span of a set of vectors is the set of all possible vectors that can be formed by taking all possible linear combinations of those vectors. “the spend of a set of vectors is a set of all possible linear combinations of these vectors”.
    • Relationship between Span and Linear Combination: If a vector b can be expressed as a linear combination of vectors in a set V, then b lies within the span of V.
    • Span Examples:The span of the zero vector is just the zero vector itself.
    • The span of a single non-zero vector in R² or R³ is the line passing through the origin and the vector.
    • The span of two non-parallel vectors in R² is the entire R² plane. If they are parallel, their span is a line.
    • Any vector in Rⁿ can be expressed as a linear combination of the standard unit vectors e₁, e₂, …, e<0xE2><0x82><0x99>. The coefficients of this linear combination are simply the components of the vector itself. “any Vector B in N Dimensions can be expressed as a linear combination of a standard unit vectors E1 up to e n … those coefficients they are not just randomly picked coefficients those are the entries of this Vector B”.

    III. Matrices: Arrays of Numbers

    • Definition and Representation: A matrix is a rectangular array of numbers arranged in rows and columns. An m x n matrix has m rows and n columns. Elements of a matrix A are denoted by aᵢⱼ, where i is the row index and j is the column index (starting from 1). “a matrix is nothing else than a rectangular array of numbers organized in rows and columns”.
    • Special Types of Matrices:
    • Identity Matrix (I<0xE2><0x82><0x99>): A square (n x n) matrix with ones on the main diagonal (from top-left to bottom-right) and zeros elsewhere. It is formed by combining the unit vectors as its columns (or rows). “the identity Matrix i n which is a square Matrix with one on the diagonal and zeros elsewhere is basically a matrix that is built using those unit vectors”. The determinant of an identity matrix is always 1.
    • Zero Matrix: A matrix where all its elements are zero.
    • Square Matrix: A matrix with an equal number of rows and columns (n x n).
    • Diagonal Matrix: A square matrix where all the off-diagonal elements are zero. The identity matrix is a special case of a diagonal matrix.
    • Matrix Operations:
    • Scalar Multiplication: Multiplying a matrix by a scalar involves multiplying every element of the matrix by that scalar.
    • Matrix Addition and Subtraction: Performed element-wise between matrices of the same dimensions.
    • Matrix Multiplication: The product of an m x p matrix A and a p x n matrix B is an m x n matrix C, where each element cᵢⱼ is the dot product of the i-th row of A and the j-th column of B. Matrix multiplication is generally not commutative (AB ≠ BA).
    • Properties of Matrix Operations: Scalar multiplication distributes over matrix addition, and matrix multiplication is associative and distributes over matrix addition. r(AB) = (rA)B = A(rB).

    IV. Determinants: A Scalar Value of a Square Matrix

    • Definition and Importance: The determinant is a scalar value that can be computed from the elements of a square matrix. It provides important information about the matrix, such as whether the matrix is invertible and the volume scaling factor of the linear transformation represented by the matrix. “the determinant is a scalar value that can be computed from the elements of a square Matrix”.
    • Calculation:2×2 Matrix: For a matrix [[a, b], [c, d]], the determinant is ad – bc.
    • 3×3 Matrix: Can be calculated using the rule of Sarrus or by cofactor expansion along any row or column. The formula involves sums and differences of products of three elements, with signs determined by the position of the elements.
    • General (n x n) Matrix: Calculated using cofactor expansion recursively. The determinant is the sum (or difference) of the products of each element in a row (or column) with its corresponding cofactor, which is (-1)^(i+j) times the determinant of the submatrix obtained by removing the i-th row and j-th column.
    • Properties of Determinants:The determinant of the identity matrix is 1.
    • Swapping two rows or columns of a matrix changes the sign of its determinant.
    • If a matrix has a row or a column of zeros, its determinant is zero.
    • If a matrix has two identical rows or columns, its determinant is zero.
    • Multiplying a row or column of a matrix by a scalar k multiplies the determinant by k.
    • The determinant of a triangular matrix (upper or lower) is the product of its diagonal elements.
    • The determinant of the transpose of a matrix is equal to the determinant of the original matrix: det(Aᵀ) = det(A).
    • The determinant of a product of matrices is the product of their determinants: det(AB) = det(A) det(B).

    V. Basis of a Vector Space

    • Definition: A basis of a vector space is a set of linearly independent vectors that span the entire vector space. Every vector in the space can be expressed as a unique linear combination of the basis vectors. “a basis of a vector space is a set of all both linearly independent vectors that spend the entire Vector space”.
    • Linearly Independent Vectors: A set of vectors is linearly independent if no vector in the set can be written as a linear combination of the others.
    • Spanning the Entire Vector Space: A set of vectors spans a vector space if every vector in the space can be expressed as a linear combination of the vectors in the set.

    VI. Gram-Schmidt Process: Orthonormalizing a Set of Vectors

    • Purpose: The Gram-Schmidt process is an algorithm for orthonormalizing a set of linearly independent vectors in an inner product space (like Euclidean space). The output is a set of orthonormal vectors that span the same subspace as the original set.
    • Orthonormal Vectors: A set of vectors is orthonormal if all vectors in the set are orthogonal (their dot product is zero) and each vector has a norm (length) of 1.
    1. Steps:Start with a set of linearly independent vectors {a₁, a₂, …, a<0xE2><0x82><0x99>}.
    2. The first orthogonal vector v₁ is the same as the first original vector: v₁ = a₁. The first orthonormal vector e₁ is obtained by normalizing v₁: e₁ = v₁ / ||v₁||.
    3. For each subsequent vector a<0xE2><0x82><0x99> (where k > 1), the orthogonal vector v<0xE2><0x82><0x99> is obtained by subtracting its projection onto the previously computed orthonormal vectors:
    4. v<0xE2><0x82><0x99> = a<0xE2><0x82><0x99> – Σᵢ<0xE2><0x82><0x8B>¹ to <0xE2><0x82><0x99>-¹ proj_<0xE2><0x82><0x81>ᵢ(a<0xE2><0x82><0x99>) = a<0xE2><0x82><0x99> – Σᵢ<0xE2><0x82><0x8B>¹ to <0xE2><0x82><0x99>-¹ ((a<0xE2><0x82><0x99> ⋅ eᵢ) / (eᵢ ⋅ eᵢ)) eᵢ
    5. Since eᵢ are orthonormal, eᵢ ⋅ eᵢ = ||eᵢ||² = 1, so the formula simplifies to:
    6. v<0xE2><0x82><0x99> = a<0xE2><0x82><0x99> – Σᵢ<0xE2><0x82><0x8B>¹ to <0xE2><0x82><0x99>-¹ (a<0xE2><0x82><0x99> ⋅ eᵢ) eᵢ
    7. “we need to subtract is projection on all previously computed orthogonal vectors by using this formula”.
    8. The orthonormal vector e<0xE2><0x82><0x99> is then obtained by normalizing v<0xE2><0x82><0x99>: e<0xE2><0x82><0x99> = v<0xE2><0x82><0x99> / ||v<0xE2><0x82><0x99>||.
    9. Repeat steps 3 and 4 for all vectors in the original set.

    This briefing document provides a foundational overview of key linear algebra concepts discussed in the provided source material. Understanding these concepts is crucial for various applications in machine learning, data science, and other quantitative fields.

    Frequently Asked Questions on Linear Algebra Concepts

    1. What is the Euclidean distance and how is it related to the norm of a vector? The Euclidean distance between two points, say A and B, in an N-dimensional space is a measure of the straight-line distance between them. Mathematically, if A has coordinates (A1, A2, …, An) and B has coordinates (B1, B2, …, Bn), the Euclidean distance d(A, B) is calculated as the square root of the sum of the squares of the differences between their corresponding coordinates: √((A1 – B1)² + (A2 – B2)² + … + (An – Bn)²).

    The norm of a vector, on the other hand, measures the length or magnitude of a single vector. For a vector V with components (V1, V2, …, Vn), the L2 norm (also known as the Euclidean norm or just the norm) is defined as ||V||₂ = √(V1² + V2² + … + Vn²).

    The Euclidean distance between two points A and B can be seen as the norm of the vector that connects A to B. If we form a vector by subtracting the coordinates of A from B (or vice versa), the norm of this resulting vector is equal to the Euclidean distance between A and B. For example, if the vector connecting A to B is V = B – A = (B1 – A1, B2 – A2, …, Bn – An), then the norm of V, ||V||₂, is exactly the Euclidean distance d(A, B). Thus, the Euclidean distance is a specific application of the norm concept, applied to the vector representing the displacement between two points.

    2. How are vectors represented, and what distinguishes them from scalars? Vectors are quantities that possess both magnitude (length) and direction. They are typically represented in a coordinate system. In a two-dimensional space (R²), a vector can be represented by its x and y components, either in parentheses (e.g., (4, 0)) or in square braces (e.g., [3, 4]). In a three-dimensional space (R³), a vector is represented by its x, y, and z components (e.g., (a, b, c) or [a, b, c]). Generally, in an N-dimensional space (Rⁿ), a vector ‘a’ can be represented as a column vector with n entries: [A1, A2, …, An]ᵀ.

    Scalars, in contrast, are quantities that have only magnitude and no direction. They are simply numbers (real numbers in the context of these sources). Examples of scalars include temperature, speed (as opposed to velocity), and mass.

    The key distinction is the presence of direction. Vectors describe a movement or displacement from one point to another in space, characterized by how far to move in each dimension, while scalars just indicate an amount or quantity.

    3. What are zero vectors and unit vectors, and why are they important? A zero vector is a vector in which all of its components are zero (e.g., [0, 0, 0] in R³). It has zero magnitude and no specific direction. Zero vectors are important because they act as the additive identity in vector addition (adding a zero vector to any vector does not change the vector). They are also useful in various linear algebra operations and algorithms, such as representing a null displacement or an initial state.

    Unit vectors are vectors with a magnitude (length) of one. In N dimensions, the standard unit vectors, often denoted as eᵢ, have a single component equal to one at the i-th position and all other components equal to zero (e.g., e₁ = [1, 0, 0]ᵀ, e₂ = [0, 1, 0]ᵀ, e₃ = [0, 0, 1]ᵀ in R³). Unit vectors are crucial because they provide a standard basis for representing any vector in a vector space as a linear combination of these unit vectors. They are also used to indicate direction without magnitude and are essential in concepts like vector normalization and coordinate systems.

    4. What does the sparsity of a vector refer to, and why is it significant? The sparsity of a vector refers to the characteristic of having many of its entries as zero. A sparse vector is one where a significant proportion of its components are zero. The sparsity pattern indicates the positions of the non-zero entries.

    Sparsity is significant for several reasons, especially in high-dimensional data and computations.

    • Computational Efficiency: Operations involving sparse vectors (like dot products or matrix-vector multiplications) can be performed more efficiently as we only need to process the non-zero elements. This saves time and memory.
    • Data Representation: In many real-world applications, data can be naturally sparse. For example, in text analysis, a document can be represented as a vector where each component corresponds to a word in a vocabulary, and most components will be zero for words that do not appear in that document.
    • Feature Selection: Sparsity is often a desirable property in machine learning models, as it can lead to feature selection (where irrelevant features have zero weights), making the models simpler, more interpretable, and less prone to overfitting.

    5. How are vectors used to represent word counts in a document? Vectors can be used to represent the frequency of words in a document by creating a vector where each dimension corresponds to a unique word in a predefined vocabulary (or dictionary). The value in each dimension of the vector represents the number of times that specific word appears in the document.

    For example, if our dictionary consists of the words {“word”, “row”, “number”, “horse”, “eel”, “document”}, a document could be represented by the vector [3, 2, 1, 0, 4, 2]. This vector indicates that the word “word” appears 3 times, “row” appears 2 times, “number” appears 1 time, “horse” appears 0 times, “eel” appears 4 times, and “document” appears 2 times in the document.

    This representation is fundamental in natural language processing for tasks like text analysis, information retrieval, and building language models. By quantifying word occurrences, we can perform mathematical operations on text data, such as comparing documents based on their word content or identifying the topic of a document. The concept of stop words (common words like “the”, “is”, “a”) which often have high frequencies but low informational value, is also relevant in this context.

    6. Explain the operations of vector addition and subtraction. Vector addition is performed element-wise. If we have two vectors, say A = [A₁, A₂, …, A<0xE2><0x82><0x99>]ᵀ and B = [B₁, B₂, …, B<0xE2><0x82><0x99>]ᵀ, both in Rⁿ, their sum C = A + B is a new vector C = [A₁ + B₁, A₂ + B₂, …, A<0xE2><0x82><0x99> + B<0xE2><0x82><0x99>]ᵀ. This means that the i-th component of the resulting vector is the sum of the i-th components of the two original vectors. Vector addition requires that the vectors have the same dimensions.

    Similarly, vector subtraction is also performed element-wise. If we have two vectors A = [A₁, A₂, …, A<0xE2><0x82><0x99>]ᵀ and B = [B₁, B₂, …, B<0xE2><0x82><0x99>]ᵀ, their difference D = A – B is a vector D = [A₁ – B₁, A₂ – B₂, …, A<0xE2><0x82><0x99> – B<0xE2><0x82><0x99>]ᵀ. The i-th component of the resulting vector is the difference between the i-th components of the two original vectors. Like addition, vector subtraction also requires the vectors to have the same dimensions.

    Geometrically, vector addition can be visualized using the parallelogram law or the head-to-tail method, where the resultant vector represents the diagonal of the parallelogram formed by the two vectors or the vector from the tail of the first to the head of the second. Vector subtraction A – B can be thought of as adding A to the vector -B, where -B has the same magnitude as B but points in the opposite direction.

    7. What are the key properties of vector addition? Vector addition satisfies several important properties:

    • Commutativity: The order of addition does not matter. For any two vectors A and B, A + B = B + A. This is because scalar addition of their corresponding components is commutative.
    • Associativity: When adding three or more vectors, the way they are grouped does not affect the result. For any three vectors A, B, and C, (A + B) + C = A + (B + C). This follows from the associativity of scalar addition.
    • Identity Element: There exists a zero vector (0) such that for any vector A, A + 0 = 0 + A = A. The zero vector acts as the additive identity.
    • Inverse Element: For every vector A, there exists an additive inverse, denoted as -A, such that A + (-A) = (-A) + A = 0 (the zero vector). The inverse -A is obtained by negating each component of A.

    These properties make the set of all vectors in a vector space under the operation of vector addition an abelian group, which is a fundamental concept in linear algebra.

    8. Explain scalar multiplication of a vector and the concept of a linear combination of vectors. Scalar multiplication involves multiplying a vector by a scalar (a number). If we have a vector A = [A₁, A₂, …, A<0xE2><0x82><0x99>]ᵀ and a scalar c, the scalar product cA is a new vector where each component of A is multiplied by c: cA = [cA₁, cA₂, …, cA<0xE2><0x82><0x99>]ᵀ. Scalar multiplication effectively scales the magnitude (length) of the vector by |c|. If c is negative, it also reverses the direction of the vector.

    A linear combination of a set of vectors {A₁, A₂, …, A<0xE2><0x82><0x99>} is a vector that is obtained by multiplying each vector in the set by a scalar and then adding the results together. If c₁, c₂, …, c<0xE2><0x82><0x99> are scalars, then a linear combination of these vectors is given by: L = c₁A₁ + c₂A₂ + … + c<0xE2><0x82><0x99>A<0xE2><0x82><0x99>. The scalars c₁, c₂, …, c<0xE2><0x82><0x99> are called the coefficients of the linear combination. Linear combinations are fundamental to understanding concepts like span, basis, and linear independence in vector spaces. Any vector in a vector space can often be expressed as a linear combination of a set of basis vectors for that space.

    Understanding Linear Combinations of Vectors

    A linear combination of vectors A₁ up to A<0xE2><0x82><0x98> using scalars β₁ up to β<0xE2><0x82><0x98> (also referred to as coefficients) is a vector formed by multiplying each vector by its corresponding scalar and then adding the results. Formally, it is expressed as β₁ * A₁ + β₂ * A₂ + … + β<0xE2><0x82><0x98> * A<0xE2><0x82><0x98>. The scalars β₁, β₂, …, β<0xE2><0x82><0x98> are real numbers.

    Here’s a breakdown of the key concepts:

    • Vectors: A linear combination involves a set of vectors, for example, A₁, A₂, up to A<0xE2><0x82><0x98>.
    • Scalars (Coefficients): Each vector in the set is multiplied by a scalar, such as β₁, β₂, up to β<0xE2><0x82><0x98>. These scalars are real numbers. The choice of these coefficients determines the resulting linear combination.
    • Scalar Multiplication: Multiplying a vector by a scalar scales the vector’s magnitude. If the scalar is negative, it also reverses the vector’s direction.
    • Vector Addition: The scaled vectors are then added together element-wise to produce the linear combination. The resulting vector has the same size as the original vectors being combined.

    Examples of Linear Combinations:

    Let’s consider two vectors A = and B =. Some linear combinations of A and B are:

    • β₁ = 0, β₂ = 0: 0 * A + 0 * B = 0 * + 0 * = + = .
    • β₁ = 1, β₂ = 1: 1 * A + 1 * B = 1 * + 1 * = + =.
    • β₁ = 3, β₂ = -2: 3 * A + (-2) * B = 3 * + (-2) * = + [0, -6] =.

    Importance of Coefficients:

    The coefficients (β₁, β₂, …, β<0xE2><0x82><0x98>) are crucial because they define how the vectors are combined. By choosing different sets of coefficients, we can obtain different linear combinations of the same set of vectors. Finding these coefficients is often the goal in many applications of linear algebra.

    Linear Combination of Unit Vectors:

    Any vector B in an N-dimensional space (Rⁿ) can be expressed as a linear combination of the standard unit vectors E₁ up to E<0xE2><0x82><0x99>. The coefficients in this linear combination are the entries of the vector B itself.

    For example, in three-dimensional space (R³), a vector B = [-1, 3, 5] can be written as a linear combination of the unit vectors E₁ =, E₂ =, and E₃ = as follows:

    -1 * E₁ + 3 * E₂ + 5 * E₃ = -1 * + 3 * + 5 * = [-1, 0, 0] + + = [-1, 3, 5] = B.

    In general, for a vector B = [B₁, B₂, …, B<0xE2><0x82><0x99>] in Rⁿ, the linear combination is:

    B₁ * E₁ + B₂ * E₂ + … + B<0xE2><0x82><0x99> * E<0xE2><0x82><0x99> = B.

    Span and Linear Combinations:

    The span of a set of vectors is defined as the set of all possible linear combinations of those vectors. For instance, if the span of vectors A and B is R², it means that any vector in the two-dimensional plane can be expressed as a linear combination of A and B.

    In the example with A = and B =, it was shown that any vector X = [X₁, X₂] in R² could be represented as a linear combination of A and B by finding appropriate coefficients β₁ and β₂. This demonstrates that the span of A and B is R².

    However, if two vectors are linearly dependent (one can be written as a scalar multiple of the other), their span will be a line rather than the entire R². For example, if A = and B = (where B = 3A), their linear combinations will always lie on the same line.

    Linear combinations are a fundamental concept in linear algebra, providing a way to understand how vectors can be combined to generate other vectors and define vector spaces and their properties like span and linear independence.

    Understanding the Span of Vector Sets

    The span of a set of vectors is the set of all possible linear combinations of those vectors. If you have a set of vectors, say V = {V₁, V₂, …, V<0xE2><0x82><0x98>}, then the span of V, often written as span(V), encompasses every vector that can be created by taking a linear combination of V₁, V₂, …, V<0xE2><0x82><0x98>. This means any vector in span(V) can be expressed in the form c₁V₁ + c₂V₂ + … + c<0xE2><0x82><0x98>V<0xE2><0x82><0x98>, where c₁, c₂, …, c<0xE2><0x82><0x98> are any real numbers (scalars).

    We can explore the span of vectors through several cases, as discussed in the sources:

    • Span of the Zero Vector: If you have a set containing only the zero vector (e.g., a = ), then any linear combination of this vector will always result in the zero vector (c * = ). Therefore, the span of the zero vector is just the zero vector itself.
    • Span of a Single Non-Zero Vector: Consider a single non-zero vector, for example, a =. The span of this vector consists of all its scalar multiples (c * = [c, 2c]). When visualized in R², these scalar multiples will all lie on the same line passing through the origin and in the direction of the vector a. Thus, the span of a single non-zero vector in R² is a line passing through the origin. You can move along this line by choosing different scalar values for ‘c’, but you cannot reach any point off this line.
    • Span of Two Perpendicular Vectors: Let’s take two perpendicular vectors in R², such as a = and b =. The span of these two vectors is the set of all linear combinations of the form c₁a + c₂b = c₁ + c₂ = [c₁, c₂]. Since c₁ and c₂ can be any real numbers, this linear combination can produce any vector in R². Therefore, the span of two perpendicular vectors like and (which are the standard unit vectors E₁ and E₂) is the entire R². Any point in the 2D plane can be reached by some combination of these two vectors.
    • Span of Two Vectors Where the Span is R²: Consider two vectors V₁ = and V₂ =. It can be shown that the span of these two vectors is also R². This means that any vector X = [X₁, X₂] in R² can be expressed as a linear combination of V₁ and V₂ (C₁V₁ + C₂V₂ = X) by finding appropriate coefficients C₁ and C₂. This was demonstrated in the source by solving for C₁ and C₂ in terms of X₁ and X₂.
    • Span of Linearly Dependent Vectors: As mentioned in our previous conversation and implicitly in the source, if two vectors are linearly dependent (one is a scalar multiple of the other, like a = and b = where b = 3a), their span will be a line through the origin. All linear combinations of these vectors will lie on the same line because essentially, you are only varying the magnitude (and possibly direction) along a single direction.

    In summary, the span of a set of vectors defines the subspace that can be reached by taking all possible linear combinations of those vectors. The number of vectors and their linear independence play a crucial role in determining the nature of the span (e.g., a point, a line, a plane, or the entire vector space). If the span of a set of vectors is the entire vector space, then that set of vectors is said to span the vector space. This concept is closely linked to linear independence and the basis of a vector space. A basis is a set of linearly independent vectors that span the entire vector space.

    Linear Independence in Vector Spaces

    Linear independence of a set of vectors is a fundamental concept in linear algebra that describes whether any vector in the set can be expressed as a linear combination of the others. Conversely, if at least one vector in the set can be written as a linear combination of the remaining vectors, then the set is said to be linearly dependent.

    Formally, a set of vectors {V₁, V₂, …, V<0xE2><0x82><0x98>} is linearly independent if and only if the only solution to the vector equation:

    c₁V₁ + c₂V₂ + … + c<0xE2><0x82><0x98>V<0xE2><0x82><0x98> = 0

    is the trivial solution, where all the scalars (coefficients) c₁, c₂, …, c<0xE2><0x82><0x98> are equal to zero. In other words, the only way to get a linear combination of these vectors to equal the zero vector is by setting all the coefficients to zero.

    If there exists a set of scalars c₁, c₂, …, c<0xE2><0x82><0x98>, where at least one of them is non-zero, such that the linear combination equals the zero vector, then the vectors {V₁, V₂, …, V<0xE2><0x82><0x98>} are linearly dependent. In this case, the non-zero coefficients indicate that at least one vector in the set can be expressed as a linear combination of the others.

    Examples of Linear Dependence:

    Consider two vectors a = and b =. We can see that b is a scalar multiple of a (b = 3a). Therefore, we can write the linear combination:

    3a – b = 3 – = – =

    Here, we have a non-trivial solution (coefficients 3 and -1 are not both zero) that results in the zero vector. Thus, vectors a and b are linearly dependent. Geometrically, linearly dependent vectors in R² lie on the same line passing through the origin (they are collinear). The span of these vectors is a line, not the entire R².

    Examples of Linear Independence:

    1. Consider two vectors a = and b =. To check for linear independence, we set up the equation:
    2. c₁ + c₂ = [6c₁, 0] + [0, 7c₂] = [6c₁, 7c₂] =
    3. This gives us two equations: 6c₁ = 0 and 7c₂ = 0. The only solution to this system is c₁ = 0 and c₂ = 0. Since the only solution is the trivial solution, vectors a and b are linearly independent. Geometrically, these perpendicular vectors span the entire R².
    4. Consider the standard unit vectors in R³: E₁ =, E₂ =, and E₃ =. The equation for linear independence is:
    5. c₁ + c₂ + c₃ = [c₁, 0, 0] + [0, c₂, 0] + [0, 0, c₃] = [c₁, c₂, c₃] =
    6. This directly implies that c₁ = 0, c₂ = 0, and c₃ = 0. Therefore, the standard unit vectors in R³ are linearly independent. Furthermore, their span is the entire R³.

    Linear Independence, Span, and Basis:

    As discussed in our previous conversation, the concept of linear independence is crucial for understanding the span of a set of vectors and the basis of a vector space.

    • A basis of a vector space is a set of vectors that satisfies two conditions:
    • The vectors must be linearly independent.
    • The vectors must span the entire vector space.

    For example, the standard unit vectors E₁ and E₂ form a basis for R² because they are linearly independent and their span is R². Similarly, E₁, E₂, and E₃ form a basis for R³.

    If a set of vectors spans a vector space but is linearly dependent, it means that there is some redundancy in the set (one or more vectors can be removed without reducing the span) and it is not a basis. To form a basis, you need a minimal set of linearly independent vectors that can generate all other vectors in the space through linear combinations.

    In the example of linearly dependent vectors a = and b =, they span a line in R², but they do not form a basis for R² because they are not linearly independent. A basis for the line they span could be just the vector a (or b), as it is a linearly independent set that spans that specific line.

    Understanding linear independence is essential for many concepts in linear algebra, including finding the dimension of a vector space, performing matrix operations, and solving systems of linear equations.

    Fundamental Matrix Operations

    The sources discuss several fundamental matrix operations, which are essential for working with matrices in linear algebra. These operations include matrix addition, matrix subtraction, scalar multiplication, and matrix multiplication.

    Matrix Addition

    The sum of two matrices A and B of the same dimensions is obtained by adding their corresponding elements. If A and B are both M by N matrices, their sum, denoted as A + B, will also be an M by N matrix where each element (i, j) is the sum of the elements (i, j) of A and B.

    For example, if matrix A is $\begin{pmatrix} 1 & 0 & 2 \ 0 & 1 & 3 \ 1 & 0 & 1 \end{pmatrix}$ and matrix B is $\begin{pmatrix} 1 & 2 & 3 \ 0 & 0 & 1 \ 2 & 1 & 3 \end{pmatrix}$, then their sum A + B is calculated element-wise:

    $\begin{pmatrix} 1+1 & 0+2 & 2+3 \ 0+0 & 1+0 & 3+1 \ 1+2 & 0+1 & 1+3 \end{pmatrix} = \begin{pmatrix} 2 & 2 & 5 \ 0 & 1 & 4 \ 3 & 1 & 4 \end{pmatrix}$.

    The order of addition does not matter (A + B = B + A), which is known as the commutative law for matrix addition. Also, matrix addition is associative, meaning (A + B) + C = A + (B + C). Adding a zero vector to a vector has no effect, and similarly, adding a zero matrix (a matrix where all elements are zero) to another matrix A results in A.

    Matrix Subtraction

    The difference of two matrices A and B of the same dimensions is obtained by subtracting their corresponding elements. If A and B are both M by N matrices, their difference, denoted as A – B, will also be an M by N matrix where each element (i, j) is the difference between the elements (i, j) of A and B. Subtracting a vector from itself results in the zero vector, and similarly, subtracting a matrix from itself results in the zero matrix.

    Scalar Multiplication

    Scalar multiplication of a matrix A by a scalar (a real number) $\alpha$ results in a new matrix where each entry of A is multiplied by $\alpha$, effectively scaling the vector’s magnitude. If A is an M by N matrix, then $\alpha$A is also an M by N matrix where each element (i, j) is $\alpha$ times the element (i, j) of A.

    For example, if matrix A is $\begin{pmatrix} 1 & 2 & 3 \ 4 & 5 & 6 \end{pmatrix}$ and the scalar is 3, then 3A is:

    $3 \times \begin{pmatrix} 1 & 2 & 3 \ 4 & 5 & 6 \end{pmatrix} = \begin{pmatrix} 3 \times 1 & 3 \times 2 & 3 \times 3 \ 3 \times 4 & 3 \times 5 & 3 \times 6 \end{pmatrix} = \begin{pmatrix} 3 & 6 & 9 \ 12 & 15 & 18 \end{pmatrix}$.

    The scalar multiplication law for matrices states that for a scalar R and matrices A and B, R(AB) = (RA)B = A(RB).

    Matrix Multiplication

    The product of an M by N matrix A and an N by P matrix B results in an M by P matrix C, where each entry $c_{ij}$ of C is computed as the dot product of the i-th row of A and the j-th column of B. For matrix multiplication to be defined, the number of columns in the first matrix (N) must be equal to the number of rows in the second matrix (N). The resulting matrix C will have the same number of rows as A (M) and the same number of columns as B (P).

    To calculate the element $c_{ij}$, we take the i-th row of A, which consists of elements $a_{i1}, a_{i2}, …, a_{in}$, and the j-th column of B, which consists of elements $b_{1j}, b_{2j}, …, b_{nj}$. The dot product is then calculated as:

    $c_{ij} = a_{i1}b_{1j} + a_{i2}b_{2j} + … + a_{in}b_{nj} = \sum_{k=1}^{n} a_{ik}b_{kj}$.

    For example, if $A = \begin{pmatrix} 1 & 2 \ 3 & 4 \end{pmatrix}$ and $B = \begin{pmatrix} 2 & 0 \ 1 & 2 \end{pmatrix}$, their product C = AB is a 2×2 matrix:

    $c_{11} = (1 \times 2) + (2 \times 1) = 4$ $c_{12} = (1 \times 0) + (2 \times 2) = 4$ $c_{21} = (3 \times 2) + (4 \times 1) = 10$ $c_{22} = (3 \times 0) + (4 \times 2) = 8$

    So, $AB = \begin{pmatrix} 4 & 4 \ 10 & 8 \end{pmatrix}$.

    Unlike scalar multiplication and matrix addition, matrix multiplication is generally not commutative (AB $\neq$ BA). However, it is associative: (AB)C = A(BC). Matrix multiplication also follows the distributive law with respect to matrix addition: A(B + C) = AB + AC (left distribution) and (A + B)C = AC + BC (right distribution).

    Understanding these basic matrix operations is crucial for more advanced topics in linear algebra, such as solving systems of linear equations, finding determinants, and performing matrix factorization.

    Properties of Determinants

    Based on the sources, here are the key properties of determinants:

    • The determinant of an identity matrix is one. The source explicitly states that if you have an identity matrix, denoted as $I_n$ for an n x n identity matrix, then its determinant, det($I_n$), is equal to 1. A specific example of a 2×2 identity matrix ($I_2 = \begin{pmatrix} 1 & 0 \ 0 & 1 \end{pmatrix}$) is given where its determinant is calculated as $(1 \times 1) – (0 \times 0) = 1$.
    • Swapping two rows or columns of a matrix changes the sign of its determinant. If you take a matrix A and create a new matrix $A’$ by interchanging two of its rows or two of its columns, then the determinant of $A’$ is the negative of the determinant of A, i.e., det($A’$) = -det(A). The source provides a notation where $A’$ is referred to as $A_{not}$ when it’s a manipulated version of A through swapping rows or columns.
    • If a matrix has a row or a column of zeros, its determinant is zero. The source explains that if a matrix contains a row or a column where all the elements are zero, then the determinant of that matrix is zero. An example is given with a 2×2 matrix A = $\begin{pmatrix} 0 & B \ 0 & D \end{pmatrix}$ where its determinant is $(0 \times D) – (0 \times B) = 0$. Similarly, a matrix B with a column of zeros, like $\begin{pmatrix} 1 & 0 & 3 \ 1 & 0 & 4 \ 1 & 0 & 5 \end{pmatrix}$, will have a determinant of zero. This can be understood through the calculation method where if you expand along a row or column of zeros, each term in the determinant calculation will have a factor of zero, resulting in a total determinant of zero.
    • The determinant of a product of matrices equals the product of their determinants. For two square matrices A and B of the same size, the determinant of their product (AB) is equal to the product of their individual determinants: det(AB) = det(A) $\times$ det(B). The source provides a detailed example with two 2×2 matrices A = $\begin{pmatrix} 1 & 2 \ 3 & 4 \end{pmatrix}$ and B = $\begin{pmatrix} 5 & 6 \ 7 & 8 \end{pmatrix}$. First, the product AB is calculated as $\begin{pmatrix} 19 & 22 \ 43 & 50 \end{pmatrix}$, and its determinant is found to be $(19 \times 50) – (43 \times 22) = 4$. Then, the determinant of A is calculated as $(1 \times 4) – (2 \times 3) = -2$, and the determinant of B is $(5 \times 8) – (7 \times 6) = -2$. Finally, it is shown that det(A) $\times$ det(B) = $(-2) \times (-2) = 4$, thus proving the property for this example.

    These properties are fundamental for understanding and working with determinants in linear algebra. The determinant provides crucial information about a matrix, such as whether it is invertible.

    Linear Algebra for Machine Learning

    The Original Text

    machine learning is at the Forefront of the Innovation powering the most advanced and transformative systems for the companies like apple Tesla Netflix Amazon open Ai and many others it enables the creation of the intelligent systems that can predict Trends personalized user experience and automate complex tasks to develop this practical applications a deep understanding of the underlying mechanics is important this require is a solid grasp of mathematics behind the machine learning so all these technical details with a particular focus on linear algebra this all-encompassing course explores the linear algebra in an interactive and machine learning Focus manner welcome to the linear algebra for machine learning course you will acquire the critical principles needed to build optimize and analyze sophisticated machine learning models from designing algorithms to enhancing curent Technologies this course provides the mathematical foundations with vital interest for those for pioneering advancements in machine learning for those dedicated to mastering the mathematical aspect and the technical details behind machine learning our extensive 26 plus hour course of fundamentals of machine learning within the mathematics boot camp as well as a separate course offers an in-depth exploration this extensive program includes certification and is tailored for individuals that are serious about advancing their career in the field of machine learning nii engineering this crash course in mathematics will serve you as a great starting point by establishing a robust foundation in linear algebra you will be well prepared to excel as machine learning practitioner equipped with a mathematical knowledge that drives the innovation and efficiency in this field so if you’re ready I’m really excited and without further Ado let’s get started welcome to the course on the fundamentals of linear algebra presented by lunch Academy my name is D Vasan and today we are going to start with some basic concepts that are important for understanding linear algebra linear algebra is one of the most applicable areas of mathematics it is used by pure mathematicians that you will see in universities doing research publishing research papers but also by the mathematically trained scientists of all disciplines this is really one of those areas in mathematics that you will see time and time again appearing in your professional life if you want to become a job ready data scientist or you want to do some handson machine learning deep learning nii stuff but also linear algebra is used in cryptology it is used in cyber cber security and in many other areas of computer science and artificial intelligence so if you want to become this well-rounded professional you want to go beyond using libraries and you want to truly understand the uh mathematics and the technical side of these different machine learning algorithms from very basic ones like linear regression to most complex ones coming from Deep learning like architectures in neural network how the optimization algorithms work how the grad descent Works in all these other different methods and models then you are in the right place because you must know linear algebra such that you will understand these different concepts from very basic ones to most advanced ones in data science machine learning deep learning artificial intelligence data analytics but also in many other applied science disciplines so before starting this comprehensive course that will give you everything that you need to know about linear algebra first I’m going to tell you what we assume that you already know because linear algebra it comes from about third year of Bachelors of different highly technical studies and here we are assuming that you already know certain Concepts so to ensure that this course stays really on the topic of linear algebra and that you understand all these Concepts really well for that we need to be able to know different topics so before we dive into this Concepts let’s familiarize ourselves with the basic prerequisites and notations used throughout this course and you will really need to know this in order to understand this Concepts really well such that instead of memorizing you will actually just hear me once or maybe twice and then every time you hear uh later on or you see it in the papers or in some algorithms you will recognize this is something that we already learned so some key prerequisites overview is here first of all to fully grasp the upcoming material you should be familiar with some basic concept like real numbers Vector spaces so you don’t need to know this idea of vectors though you already most likely are familiar with this given that you know how to plot different lines you know the idea of x’s and y’s and how to plot these different graphs but here we are going to based on this every time when we come close to this Concepts I will refresh you your memory and we will go through this numbers the idea of norms and distance measures because when it comes to the vectors when it comes to the magnitude and all these different topics that we are going to discuss as part of linear algebra knowing the what Norm is and what is the definition of distance what is the length between two points when we plot it in the two dimensional space or three dimens commcial space those are all very basic concept that usually you see as part of a basic pre-algebra or just common algebra courses and lessons in order to truly understand what the new algebra is about to understand this direction of vectors the angle and then the dimensionality reduction how linear algebra is applied for instance in different algorithms in machine learning deep learning data science statistics you really need to understand this Cartesian coordinate system so this is not only important for linear algebra but I assume you already know it given that you have passed those other courses like calculus or usually they are covered as part of pre-algebra or algebra so the Cartesian coordinate system I mean here understanding what is for instance the the common description of them for instance when you when we write like X and then y on the vertical axis and then we can we have here zero and then we can always plot this different plots you know we have a clear understanding what is this Y is equal to X line we understand how by knowing certain points we can plot different plots for instance that this is the Y is equal to X line that here it means that if we have here one then this is just one two this is two so we understand when we have the function of the line and we have a certain value whether it’s our y coordinate or x coordinate then the corresponding coordinates can be be found then you also need to know some basic things that I just didn’t mention right now so for instance that the numbers here can be like one 2 three up to Infinity so you understand this concepts of infinity and then here the same story then here we have minus one you know minus 2 uh and then this is then used later on and we will be touch basing this one we will be describing our vectors and how we can visualize our vectors e the two dimensional space La we have here because this is two dimensional so we have X and Y but we can also of course visualize it in three-dimensional Etc so this idea of basic coordinate system is really important usually covered as part of algebra if not pre-algebra then we have basic triog genetry which means that you need to have a clear understanding what sinus is what cosine is what tangent is and their recip foros and here I mean that you know for instance what is cosine function what is s function you know that you have an understanding for instance that what is this line you know whether it’s a sinus line or cosine line you have also an understanding what this Pi is one thing that I didn’t mention but it it just goes around all these topics some basic things that you understand what is X what is why why we use them and this idea of variables and also you need to understand this idea of square or you know 90° angle and then Pythagoras Theorem here we have the same so what is this relationship between different sides of a triangle uh that is a very unique triangle and that has one of the angles as 90° and this idea of you know the sides how this relates to the signus cosinus tangent cotangent and also how the Pythagorean Pythagorean theorem applies when we have a triangular but it is no longer with angle that is 90° what is the sum of all the angles of a triangle so those are basic stuff that are com commonly covered as part of trigonometric lessons or part of General geometry then another prerequisite is this understanding of identities and equations in triog genometric lessons something part of which I already covered and this just goes around of basic having a basic understanding of algebra and geometry those are super important to understand more Advanced Techniques from linear algebra then we have finally this idea of orthogonality perpendicularity in vectors so this also comes from geometry and from trigonometric lessons so you understand that if we we have for instance these two lines that don’t have any intersections then we are talking about two orthogonal lines and otherwise for instance if we have the two lines like this then we are talking about perpendicular vectors when you have two lines that are actually parallel so they don’t have any intersection and you won’t find any point that is common for the tube so when it comes to this R so as part of real numbers and Vector spaces R represents the set of all real numbers so you can be dealing with for instance and integers like 1 2 three this can Al this will also cover all the negative numbers like min-1 – 2 – 3 but also the floting numbers like 1. 223 and all the other numbers that you can think of those are the set of all real numbers so this is in onedimensional space right so you can see that I’m writing just one number you know two three and other numeric numbers then we have the idea of R2 R3 up to RN where all these numbers they represent in this case the N it represents the N dimensional aidian space so when it comes to this idea of n dimensional numbers so for instance R2 here we just mean 2D plane so I’m pretty sure you are familiar with this idea of for instance x-axis and Y AIS here we are dealing with two dimensional plane so for every point that we can find here we can describe them by assigning them a value X so coordinate X and a coordinate y that’s exactly what we mean by saying that the number can be represented in a 2d plane so here we are dealing with this two dimensional space this is our two dimensional Alan space and every number in here that is part of this R2 can be pictured here can be represented in this visualization so for instance if I have this number and let’s assume that the value on the x- axis is two and we can see here that the corresponding Y is zero I can describe this number which I will call a I can describe this by writing down first the x coordinate which is two and then the y coordinate which is zero so I’m then saying that a which is a point with x coordinate 2 and y coordinate zero it is part of my R2 and it’s part of my two dimensional Alan space when it comes to R3 similar thing we can do with that only in that case we need not just X AIS and Y AIS but we need to add our third dimension so here for instance when it comes to the r Tre then we need to do y AIS we need to have x axis but also we need to have some Zed AIS so such that every time every point in the space we can then describe by x y and Zed coordinates so if we write it in terms of the vector something that we will see very soon as part of our first unit of this course we will then need to write represent every number in this threedimensional Alan Space by writing down first the x coordinate let’s say one and then y coordinate let’s say another one and then Z coordinate which is one or even better even easier let’s do 0 0 0 which means that we are dealing with this initial number which is the center of this three-dimensional Elan space when it comes to the nend dimensional or higher dimensional spaces it’s much harder to visualize therefore usually when it comes to visualizations we do usually we usually only visualize the onedimensional two dimensional and three-dimensional spaces above then it just no longer does make sense to visualize it but we definitely deal with them and they are part of Applied linear algebra so understanding the spaces is very important for analyzing vectors for their interactions and this holds not just for this two dimensional and three-dimensional but really for multi-dimensional spaces let’s Now quickly Define this idea of Norm so the norm of a vector denoted by this V which you can see kind of like similar to the absolute value from pre-algebra you can see here that we have this double straight lines like from absolute value and then we have the name of the vector or the variable name that we are assigning to our vector and then you might notice here on the top of this this Arrow this basically says that we are dealing not with just a variable but really we are dealing with a vector this is really important because you can see that there makes a huge difference if we have for instance just V or V1 I have to say or just V those are really important and things that you need to keep in mind when it comes to linear algebra and trying to differentiate vectors from a point you will notice that when it comes to Norm we can represented it either by this notation or this usually it’s a common notation in machine learning or in data science with this two bars and when we do this we automatically also know that we are dealing with Eline distance we call it also L2 norm and this is something very common and usually used as part of retrogression which is an application of linear algebra and it’s used in regularization so we are regularizing our machine learning algorithms so when you get into machine learning you will see time and time again this notation so next time when you see this then you know automatically that you are dealing with L2 norm and L2 Norm which is also used a lot in machine learning it is referring to the usage of L2 Norm to uh in the retrogression and retrogression or L2 regularization is a very popular regularization techniques as part of machine learning so right now even you can see this intersection of linear algebra or this idea of norms in machine learning all right so now let’s see why we call it actually L2 Norm or often referred as Elan distance so in distance you can see here which is also the in this case this V which describes the norm of the vector v is equal to square roof and then we have all these coordinates assuming that the vector comes from an N dimensional space so you can see here the RN the V Vector the idian distance or the norm of this vector v is equal to square roof and then V1 2qu plus v2^ S Plus and all this in between numbers plus VN s so here basically it means take the square root of V1 squ then V2 squared plus V3 s blah blah blah plus VN squ so basically take all the units that form this vector and then so are on this vector and use them Square them and then add them and then take the square root of that that’s the distance or I have to say the norm of this Vector why this is important this idea of norms and Al IND distance beside of being used in machine learning and why is it chuse so Norms they provide a way to measure the size or the length of a vector in Vector spaces which means that when we want to measure a distance a similarity relationship between for instance vectors then it becomes much easier to use this idea and Alan distance is not only used in regularization techniques like L2 regularization or retrogression but it’s also used in other machine learning or deep learning algorithms as a way to measure the distance or the relationship or the similarity between two different entities those can be variables those can be two people that we want to compare in our algorithm or two entities um for instance the Norms or the Al and distance they are also used as part of K algorith something that you might have heard and if you follow later on the machine learning and the clustering section of machine learning you will see that aladan distance is used as part of C’s algorithm that aims to Cluster observations into different groups so this also yet another highly applicable uh topic that you must know in order to understand different linear algebra top topics but also machine learning topics let’s now talk about simple topic that we must know about and refresh our memory very quickly before moving forward to our next topic that is a prerequisite for this course so the cartisian coordinate system is just a fancy word of describing this idea of X and Y or XY Z when we just want to visualize them and showcase this numbers related to the space so we just learned the and I just quickly was talking about this idea of EX and and Y and how we can visualize that in Plaine so the cortesian coordinate system is a framework for specifying points in a plane or a space using ordered list of numbers so we know for instance when we plot this then here we need to put X and the Y in our two dimensional space or two and we know that here in the middle we have zero and here we have 1 2 3 4 and the same here one two and then three four which means that everyone that is in the indust whether it’s in mathematics in physics in data science or ml or AI we all universally agree on this system we know that this is this ordered list of numbers and we know that if we have for instance a point here then for this point we know that the xaxis and Y AIS is definitely positive even if we know don’t know the corresponding numbers and then once we have more General lines here so not General but specific lines then even know the exact coordinates and values here and we definitely know that this number should be so the x coordinate should be between two and three so first we have the two and then three and not the other way around so this ordered nature helps us to understand how we can put all these different numbers and organize them in our two dimensional space and we also know the corresponding y so we know that for instance our Y is not minus three because it’s lying in here in this part of our coordinate system and not somewhere here where the Y AIS are negative and why do we know that because it’s an ordered list of numbers that we can visualize in this 2D plane and here you also need to keep in mind and we need to remind ourselves about this idea of these four different parts that we got so we have our here the first part the second part the third part and then the fourth you know part of our coordinate system and and here we we are dealing with a two dimensional plane but if we were to deal with the threedimensional plane we no longer have just x-axis and Y AIS where x axis were on the horizontal and y- axis on the vertical but we have our third line which is the Z so we have now three different dimensions so X Y and Z and we are basically extending our two-dimensional plane to threedimensional so this system is fundamental for visualizing and working with vectors geometrically so then we can just use this two-dimensional uh plane in order to visualize this Vector for instance knowing what are all these points that appear on this Vector what is its direction where is it headed you know what is the beginning and then we can also find out all the so the relationship of these vectors with all the other vectors for since if we have not Vector here then we can use the coordinates of them and information about the vectors to understand that we are dealing with two parallel vectors that don’t have anything in common so no intersection points whereas just if we have another Vector like this and we know that here we are dealing with perpendicular you know orthogonal vectors so this is why those this coordinat Cartesian coordinate system is important and it’s not just important for linear algebra but just in general for mathematics and for data science and for AI and you will see this coordinate system time and time again in different visualizations even when you want to visualize the mean of your data or you want to visualize the probability distribution function describing your population from statistics or from data science you want to visualize for instance how your optimization is working or you want to visualize how your model is performing in terms of its Evol ition Matrix for all these cases and for any visualizations this idea of the Cartesian coordinate system is going to become very handy let’s now talk about this idea of angles and the idea of circles radian the pi as well as this degree sign so this comes usually from geometry or tonometry and this is very important when it comes to the vectors because when we have two different vectors then we want understand their relationship do they form this less than 90° or so are we dealing with sharp corner sharp angle or we are dealing with 90° angle so we are dealing with this type of vectors where we have you know 90° or we are dealing with um this type of vectors when the angle is 180° which is by the way uh something that we are referring as pi and here is one thing that is important here is that it’s not just Pi but it’s Pi radians why because in mathematics we also have this idea of Pi which is usually a number that is 3.14 so we should not confuse this Pi with pi radians so the relationship between the two is something that we have also seen as part of our pre-algebra and algebra corses so if it’s something that you want to just refresh your memory on this will be super helpful to check out very initial course on um all these Basics so pre-algebra so this number comes from prealgebra and then this idea of P radians and just in general all this information about what is 180° what is this angle what is 360° and all the information that comes from triog gometry and geometry can be found in our corresponding course so the next topic is the unit circle unit circle is highly related to this idea of radians degrees cosine s but also understanding the cartisian coordinate system will help you to understand the unit circle so this also comes from tonometry and geometry and it’s basically a fancy way of saying we have x-axis we have y AIS we have here zero so our common Cartesian coordinate system only we are trying to focus on this part of the system where we have here one we have here one so on the x-axis we have one and then here minus one here minus one for y AIS and here y the Y is equal to one so we have here all these points and then we have the circle with radius of one so here is this you know this is the radius and here we plot this circle and this will help us to understand this concepts of sinus cosinus you know this Theta is just variable that we use to describe the angle and for instance here we are dealing with 45° this angle is 90 de this entire thing is 360° and half of it so this part only is 180° so those are all important part of understanding this idea of unit circle so you might have already guessed that unit circle refers to this idea that we have here one unit here one unit one unit one unit forming this entire circle so with the radius that is equal to one all right so this is something that is very easy and this comes from the geometry and pre and tri gometry uh you also need to understand this concept of sinus and cosinus and how sinus and cosinus are related to this what do we refer by the sinus and cosine you know what is this what are these points so one Z for instance we understand that here the x is equal to 1 and Y is equal to Z so here this point is simply 1 Z so this point and then we have 2 p radians so what is this idea of P so we know that a p radians so P radians is simply the 180° which means that you also need to understand this concept of P2 which is simply the 90° so you can see here one thing that I forgot to mention you need to understand this concept the relationship between the pi and so Pi radians and radians and this unit circle you need to know that here the Pi / 2 is simply this angle and then the entire Pi is this angle and then this entire thing the entire angle with 360 degrees is equal to 2 pi so 2 pi radians is simply this entire thing so those are very easy Concepts that come from geometry and trometry and if you want to refresh them then had to work those courses because this will help you to understand all these concept from scratch let’s now continue our refreshment when it comes to geog genometric identities and we just spoke about this unit circle we talked about the sinus cosinus it’s really important to relate this back to bit more advanced topics coming from the same do domain and from the same area of mathematics and here we we need to know this concept before learning the your algebra few other things that um would be really great if you know but it’s actually not a must to understand all these different topics it is the idea of Pythagorean identity so don’t confuse this with Pythagoras Theorem this is the Pagan identity so this one that the square of the sign of an angle plus the cosine squared is equal to one and all these different rules that go around the sign and cosine and also the what is for instance the sign 2 Theta which is equal to 2 sin of theta and cosine of theta you know those are all different rules that would be handy to know and if you are so far I assume that you also know geometry and fundamentals to triogen ometry which means that you also know this trules but this might be just a great time to go ahead and quickly refresh your memory on this Concepts because those might become handy in your applied linear arge Applied Mathematics Journey but for now I would say this is not one of the most important things to know to learn this and to go through this course but just something to keep in mind so when it comes to the triog genometric equations uh this can become very handy later on when we want to prove something in linear algebra so to follow along it’s actually a good idea to know for instance what is how you can solve this different equations and this will go back and refer to the unit circle that we just saw for instance if the sinus Theta is equal to 1 / 2 then you will need to quickly remember what is that angle for which the sinus is equal to 1 / 2 then you realize that is actually the angle where you take the p and remember that Pi is equal to 180° and that is the one corresponding to and then Pi / to 6 is simply 180 / it to six so this is basically the 30° so those are things that you can do when you know for instance all these different sinus and cosinus so you have memorized for these different angles so what is the sinus and cosinus for 30 degree for 60° um let me actually remove this to make it easier so this type of problems is very easy to solve when we keep in mind and we memorize what are these different values for sinus and cosinus when it comes to different angles for instance for the angle equal to Z let me actually remove this and clean this part for better understanding so if we have for instance Z degrees then we know that the sinus for this is zero and the cosine of this is one so we are basically dealing so if I plot a unit circle we are dealing with this number so remember that sinus and cosinus those refer to the Y and X on our unit circle so keep this one in mind so if the cosine Theta is then equal to 1 and the sinus so Y is equal to Z we are dealing automatically this number with this number and you can see that here the angle is also zero so here we are dealing with one and zero coordinate so this is our cosine of zero angle and this is then our sinus of zero angle so we automatically even from this graph can see very easily that the S of 0° is equal to 0 and the cosine is equal to 1 all right so let’s quickly also refresh our memory on few other degrees so for the 30 deges which is simply the Pi / 2 6 so this is 30 ° then the sinus or the Y AIS is equal to 1 / 2 and the cosine or the XX value x coordinate is equal to square root of 3 2 so we are dealing with this this corner or angle so 30° so even from here you can see that the coordinates make sense make sense then we have the pi for another famous value which is corresponding to the 45° it simply this angle and for this angle the X AIS which is the cosine so this number is equal to one/ to 2 and then for the sinus the so the y coordinate is equal to 1 / two as square root of two as you might have guessed because in this number the xaxis and y axis is equal to is the same so you can see that this distance and this distance is the same because we are dealing with this type of figure so here we have 45° here we have 45° so this values are the same and this is something that you would know knowing the Pythagorean Pagan theorem so then you can go ahead and refresh your memory for the 60° so here I’m referring to the Pi / to 3 and then the 90° which is the very easy casee this one obviously the xaxis is equal to zero so here you should have zero and the y- axis is equal to one so here you should have one and so on all right so we went into quite detailed here but I think this is a very important topic knowing this idea of a trigonometric equations identities this idea of unit circle are super important because they are highly applicable to different fields in artificial intelligence data science machine learning and will definitely set you apart all right let’s now talk about the law of signs and cosiness those are things that I won’t be going on into too much details I just wanted to quickly showcase to you if you want to get the proof of those definitely check out our corresponding courses but for here I’m assuming that you already know so you know the law of signs which means that if you have this triangle you know you have this different sides so you have an angle a the corresponding side is a and then you have angle B corresponding side is B and then here C and the corresponding side is C then you know that a / to sinus of that angle is equal to B / to the S of that angle and then is equal you see divided to the sign of that angle so basically take this value divided to the sinus of this angle you know right in front of it is equal to taking this value and then dividing into the sinus of this angle so the proof of this low is outside so out of the scope of this course but knowing this will help you to understand different concepts and then the law of cosine is simply saying take the side of a Target angle so in our triangular we have here a we have here angle B and the C and if we go and look into this specific angle so angle C just randomly picking one of the three angles then the side right in front of that angle so the C c^ squ is equal to if we take this you know the other two sides forming that angle so A and B is equal to a s so this is just a constant a distance of this side a 2 + b 2 so this side squar minus 2 * a * B * the cosine of that angle this is what we are referring as the law of cosin quite easy we are not going to prove it again if you want to get the proofs make sure to check our other fores on the geometry and triogen ometry we’re almost done with the prerequisites just a quick refreshment we saw already the norm here is just a notu example what Norm is and on a specific two dimensional Vector when we have for instance that a vector is equal to three and four which means for the First Dimension let’s say on xaxis we have three and then on Y axis is equal to four then the norm or the Alan distance so this is equal to we take the X vol so three and then we Square it so V you can see here this is the case when n is equal to 2 this is simply equal to square root of V1 2 + v2^ 2 and as V1 is equal to 3 so this is our maybe I can make this just V1 and this is my V2 then the norm or the equid in distance for this Vector so this thing is equal to V1 2 + V 2^ 2 which is equal to 3 2 + 4^ 2 and this value is sare root of 25 and it’s equal to five so let’s now see the difference between aladine distance and the norm so you could see here the norm here we have just one vector like here and this Norm it has just two corresponding values into two dimensional space you see here we have just three and then four so this is V1 and V2 when it comes to the Alan distance this is kind of the generalization of this idea of Norm so the Alan distance between two points A and B in RN so in the N dimensional space is the norm of the vector connecting a to B so we see that the norm and the elidan distance are highly related to each other only we are talking about the norm when it comes to one vector but when we have this Vector a a and the vector B this is simply the Alan distance so for the aladine distance we know already this idea of distance how we can measure it and you can see that this comes very similar to what we see here notation and here we are saying well we have this vector and then it has the two coordinates in N is equal to 2 in two dimensional space when it comes to the A distance Elan distance helps you understand what is this distance between two points in an N dimensional space so the aladan distance between two points let’s say A and B in N dimensional space is the norm of the vector connecting a to B so for instance if we have a point a and we have a point B we are connecting this and this is the vector connecting these two points then the El distance is simply the norm of this Vector so this is the Alan distance so we can see that the norm and the distance they are highly related to each other in the Alan distance we are using this idea of norm and specifically the norm two as I mentioned before so here you can see that the definition of alodine distance so the distance between A and B the two point is equal to square root of A1 – B1 2 plus a and then here we have basically A2 – b 2 2 and then plus A3 minus B3 s those are things that we cover as part of this dot dot dot and then plus after to the last point when we have a nus bn^ 2 so here what we mean basically is that if we have two points here is a and here is B and this s vector and we know all these different points so A1 B1 A2 B2 A3 B3 blah blah blah and then here a n BN we know all these points lie in here in this distance then we are taking them and using them to calculate the L in distance so here for instance if we have point A and B so in this example let’s do a quick one specific example when we have a point a which has coordinates 1 and two so this is basically A1 A2 and then point B with points in it like B1 B2 you can notice that the da AB so the distance or the eiding distance of these two points which is equal to the norm of this vector or here this is a and this is B and this is this Vector this is equal to square root of 4 -1 so it takes the B1 so this is B1 and this is A1 takes the square and then says plus B2 – A 2^ 2 takes the square root of that and says this equal to 5 now you might be wondering but hey why do we do then instead of 1 – B1 2 we do B1 – A1 2 and the answer to this question lies in the uh properties that we learn as part of prealgebra because it doesn’t matter when we we take A1 – B1 2qu or B1 – A1 squ because this squared ensures that it doesn’t matter which one we take first and subtract the other now the proof of that is outside of the scope of this of course this is part of pre-algebra but I just wanted to put this out there to ensure that you are seeing what we are seeing here because here it says A1 minus B1 but in this example we are taking instead depth B1 and we are subtracting A1 this is a common thing that we do in P algebra and just in general in different culating distance or distance related cases so I just wanted to put this here to ensure that later on this is something that can be clear from the first view right and in here we will quickly refresh our memory on the Pythagorean theorem which basically says in the right angle triangle so if we have this type of triangle so here we have 90° this is a right angle triangle the square of the length of the the side opposite to the right angle so this side this we of refer C and this as B uh and then a those two are not very important but this is commonly referred by C so the the side opposite to the right angle then we know that the square of the C so C squ is equal to a 2 + B2 this is super important theorem and a fundamental principle for defining the Norms the distances in equity and spaces in and in many other applications so the angles play a crucial role in understanding the direction of the vectors and you know how they can be measured in degrees or in radians we saw also the pi radian this idea of you know that the pi radian is equal to 180° those are all very important when it comes to linear algebra and just in general application of mathematics in machine learning in Ai and other applications the relationships between these angle measurements and the triog genometric functions is foundational in solving different problems that are about these vectors and their orientations for instance this angle of sign cosine you know what is this idea of tangent they are very important just to give you an idea the um a t a tangent is specifically used as part of the activation functions we call tank activation function and knowing this tank will help you to understand the activation functions that I use as part of deep learning which are more advanced machine learning type of models and they are fundamentals in all these different new and Cutting Edge techniques large like large large language models Transformers encoder and decoder based algorithms Etc they’re also important in this idea of computing dot products so very important and a must know when it comes to linear algebra so this is just an simple example when it comes to this right angle triangle and Pythagorean theorem and how it is applied I will skip this for now it’s also important to understand this idea of orthogonality so the two vectors let’s say A and B they are orthogonal to each other if their dotproduct is zero so later on as part of the vectors when we will talk about dot product we will see what we mean when we say that the dot product is equal to zero and here you can even see that if the a norm if the a vector so you see here and B Vector if those vectors if we multiply them to each other their dot product is equal to zero it means they are orthogonal so this angle that they form is equal to 90° orthogonality implies that the vectors from the from a right angle with each other they are in you know we we are dealing with that in our2 in our tree so they are super important way it comes also to visualizing them correctly this concept is visually represented all this uh you know Vector a and then Vector B and they are perpendicular in the 2D uh coordinate system all right so when it comes to the applications of orthogonality orthogonality plays a crucial role in various aspect of linear algebra it’s fundamentally in defining Vector spaces subspaces in solving systems of linear equation later on when we pass the vector ideas and we go on to the matrices solving linear systems so equations with many unknowns and then we use this idea of reductions or gaussian reductions we will see how this idea of orthogonality can be important and how also it relates back to the norm of two vectors so it’s fundamental in defining all these different Iden ities and solving system of linear equations and also orthogonal vectors are used in finding the shortest distance from point to the plane um something that is important when it comes to the optimizations and here you can see an example the vector a which is equal to 2 three and then Vector B which is equal to minus 3 and 2 you can see that when we multiply 2 by minus 3 so we obtain basically the dot product by the way this is something that we are going to cover also part of the squares but for now you can see that if we take this number we multiply with this so 2 * – 3 we take this number multiply with this so we take three and multiply with two you can see that this equal to minus 6 this is equal to 6 so – 6 + 6 is equal to zero so you can see that the dotproduct of these two vectors is simply equal to zero and this is what we are referring as orthogonality this means that these two vectors form a right angle where we see here this angle is equal to 90° why this prerequisites matter and why I mentioned those understanding this concept is very crucial they underpin this geometric interpretation of linear algebra they will help you to better understand these Concepts and not just to memorize them but really understand and later on when you go into your machine learning and AI journey and your data science Journey seeing these Concepts will help Q to better understand those different algorithms this optimization techniques what we mean when we say we want our optimization algorithm to move towards local minimum Global minimum this idea of movement this idea of vectors later on will you will also understand this different concepts in deep learning how these models work how the neural networks work and those are essential Concepts that you need for solving different systems of linear equation a core part of this course they also help you in visualizing vectors spaces which are critical to understand this concept of linear algebra the applications of linear algebra when it comes to the real world applications so those are things that you can definitely Master by following some of our other courses but for this course I assume that you are already familiar with these Concepts right so now we are ready to actually begin and with this prerequisite it in mind you are prepared to start your linear arbra Journey we are going to learn everything in the most efficient way in such a way that you will learn the theory you are going to see many examples we are going to learn everything in detail but at the same time you’re going to learn the must know Concepts and I’m not going to overwhelm you with this most difficult concept that you will not be seeing in your career I’m going to give you this bare minimum when it comes to really knowing the must know for linear algebra such that you will be ready to apply linear algebra in your professional Journey whether you want to get into machine learning deep learning artificial intelligence data science knowing these different concepts in linear algebra you will be a pro in your field going to give you everything that you need the theory examples implementations everything in detail but at the same time you will be doing that in the most efficient and time saving way so without further Ado let’s get started let’s Now quickly Define this idea of Norm so the norm of a vector denoted by this uh uh V which you can see kind of like similar to the absolute value from pre-algebra you can see here that we have this double straight lines like from absolute value then we have the name of the vector or the variable name that we are assigning to our vector and then you might notice here on the top of this this Arrow this basically says that we are dealing not with just a variable but really we are dealing with a vector this is really important because you can see that there makes a huge difference if we have for instance just V or V1 I have to say or just V those are really important and things that you need to keep in mind when it comes to linear algebra and trying to differentiate vectors from a point you will notice that when it comes to Norm we can uh represented it either by this notation or this usually it’s a common um notation uh in machine learning or in data science um with this uh two bars and um when we do this we automatically also know L2 norm and this is something very common and uh usually used as part of uh retrogression which is an application of um linear algebra uh and it’s used in uh regularization so we are regularizing our machine learning algorithms so when you get into machine learning you will see time and time again this um notation so uh next time when you see this then you know automatically that you are dealing with L2 norm and L2 Norm which is also used a lot in machine learning it is referring to the usage of L2 Norm to in the uh R regression and R regression or L2 regularization is a very popular regularization techniques as part of machine learning so right now even you can see this uh intersection of linear algebra or um this uh idea of norms in machine learning the norm of this vector v is equal to square roof and then V1 squ plus v2^ squ plus and all this in between numbers plus VN squ so here basically it means take the square root of V1 squ vs2 squ plus V3 squared blah blah blah plus VN squ so basically take all the units that form this vector and then so are on this vector and use them Square them and then add them and then take the square root of that that’s the distance or I have to say the norm of this Vector we saw already the norm here is just a not example what the norm is and um on a specific two-dimensional Vector when we have for instance that a vector is equal to three and four which means for the First Dimension let’s say on x axis we have three and then on Y axis is equal to four then the norm or the Alan distance so this is equal to we take the x value so three and then we Square it so V you can see here this is the case when n is equal to 2 this is simply equal to sare root of v1^2 + v2^ 2 and as V1 is equal to three so this is our maybe I can make this just V1 and this is my V2 then the norm or the equ in distance for this Vector so this thing is equal to V1 s + v2^ 2 which is equal to 3^ 2 + 4^ 2 and this value is square root of 25 and it’s equal to 5 let’s now see the difference between aladine distance and the norm so you could see here the norm here we have just one vector like here and this Norm it has just two corresponding values into two dimensional space you see here we have just three and then four so this is V1 and V2 when it comes to the Alan distance this is kind of the generalization of this idea of Norm so the aladan distance between two points A and B in RN so in the N dimensional space is the norm of the vector connecting a to B so we see that the norm and the Alan distance are highly related to each other only we are talking about a norm when it comes to one vector but when we have this Vector a and the vector B this is simply the aladine distance so for the aladine distance we know already this idea of distance how we can measure it and you can see that this comes very similar to what we see here notation and here we are saying well we have this vector and then it has the two coordinates in N is equal to 2 in two dimensional space when it comes to the Aline distance aladine distance helps you understand what is this distance between two points in an N dimensional space so the aladan distance between two points let’s say A and B in N dimensional space is the norm of the vector connecting a to B so for instance if we have a point a and we have a point B we are connecting this and this is the vector connecting these two points then the aladine distance is simply the norm of this Vector so this is the aladine distance so we can see that the norm and the distance they are highly related to each other in the Alan distance we are using this idea of norm and specifically the norm two as I mentioned before so here you can see that the definition of aladine distance so the distance between A and B the two point is equal to square root of A1 – B1 2 plus a and then here we have basically A2 minus B 2^ 2 and then plus A3 – B3 2 those are things that we cover as part of this dot dot dot and then plus up to the last point when we have a n minus BN 2 so here what we mean basically is that if we have two points here is a and here is B and this s vector and we know all these different points so A1 B1 A2 B2 A3 B3 blah blah blah and then here a n BN we know all these points lie in here in this distance then we are taking them and using them to calculate the L in distance so here for instance if we have um point A and B so in this example let’s do quick one specific example when we have a point a which has coordinates 1 and two so this is basically A1 A2 and then point B with uh points in it like B1 B2 you can notice that the da AB so the distance or the equid distance of this two points which is equal to the norm of this um Vector but here this is a and this is B and this is this Vector this is equal to square root of 4 minus 1 so it takes the B1 so this is B1 and this is A1 takes the square and then says plus B2 – A 2^ 2 takes the square root of that and says this equal to 5 now you might be wondering but hey why do we do then instead of 1 minus B1 s we do B1 – A1 2 and the answer to this question lies in the um uh properties that we learn as part of prealgebra because it doesn’t matter when we take uh A1 – B1 2 or B1 – A1 squ because this squared ensures that it doesn’t matter which one we take first and subtract the other now the proof of that is outside of the scope of this um course is this is part of pre-algebra but I just wanted to put this out there to ensure that uh you are uh seeing what we are seeing here because here it says A1 minus B1 but in this example we are taking instead depth uh B1 and we are subtracting A1 this is a common thing that we do in um pre-algebra and just in general uh in different um Alan distance or distance related cases so I just wanted to put this here to ensure that uh later on this is something that can be clear um from the first view why this is important this idea of norms and equ in distance beside of being used in machine learning and why is it used so Norms they provide a way to measure the size or the length of a vector in Vector spaces which means that when we want to measure a distance a similar ility uh relationship between for instance vectors then it becomes much easier to use this idea and El IND distance is not only used in regularization techniques like L2 regularization or retrogression but it’s also used in other machine learning or deep learning algorithms as a way to measure the distance or the relationship or the similarity between two different entities those can be variables those can be two people that we want to comparing our algorithm or two entities um for instance uh the um Norms or the Al and distance they are also used as part of K algorithm something that you might have heard and if you follow later on the machine learning and the clustering section of machine learning you will see that elidan distance is used as part of C’s algorithm that aims to Cluster observations into different groups so this also yet another highly applicable uh topic that you must know in order to understand different linear albra top topics but also machine learning topics welcome to the course on the fundamentals of linear algebra my name is D Vasan and today we are going to start with some basic concepts that are important for understanding linear algebra linear algebra is one of the most applicable areas of mathematics it is used by pure mathematicians that you will see in universities doing research publishing research papers but also by the mathematically trained scientists of all disciplines this is really one of those areas in mathematics that you will see time and time again appearing in your professional life if you want to become a job ready uh data scientist or you want to do some handson machine learning deep learning and AI stuff but also linear algebra is used in cryptology it is used in cyber security and in many other areas of computer science and artificial intelligence so if you want to become this well-rounded professional you want to go beyond using libraries and you want to truly understand the uh mathematics and the technical side of these different machine learning algorithms from very basic was like linear regression to most complex ones coming from Deep learning like architectures in neural network how the optimization algorithms work how the gradient descent works and all these other uh different methods and models then you are in the right place because you must know linear algebra such that you will understand these different concepts from very basic ones to most advanced ones in data science machine learning deep learning artificial intelligence data analytics but also in many other applied science disciplines so before starting this comprehensive course that will give you everything that you need to know about linear algebra first I’m going to tell you what we assume that you already know because linear algebra it comes from about third uh year of Bachelors um of different uh highly technical studies and um here um we are assuming that you already know certain Concepts so uh to ensure that this course stays really on the topic of linear algebra and that you uh understand all these Concepts really well for that we need to uh be able to know different topics so before we dive into these Concepts uh let’s familiarize ourselves with the basic prerequisites and notations used throughout this course and you will really need to know this in order to understand this Concepts really well such that instead of memorizing you will actually just hear me once or maybe twice and then every time you hear uh later on or you see it in the papers or in some algorithms you will recognize um this is something that we already learned so so uh some key prerequisite overview is here um first of all to fully grasp the upcoming material you should be familiar with some basic concept like real numbers Vector spaces so you don’t need to know this idea of vectors though you uh already most likely are familiar with this given that you know how to plot different uh lines you know the idea of x’s and y’s and how to plot these different graphs but um here here we are going to touch base on this every time when we come close to this Concepts I will refresh you uh your memory and we will go through this numbers the idea of norms and distance measures because when it comes to the vectors when it comes to the magnitude and all these different uh topics that we are going to discuss as part of linear algebra knowing the what Norm is and um what is the definition of distance what is the length between uh two points when we plot it into two-dimensional space or three-dimensional space those are all very basic concept that usually you see as part of a basic pre-algebra or just uh common algebra courses and um lessons in order to truly understand what the algebra is about to understand the direction of vectors the angle and then um the uh dimensionality reduction how linear algebra is applied for instance in different algorithms in machine learning deep learning data science statistics you really need to understand this Cartesian coordinate system so uh this is not only important for linear algebra but I assume you already know it given that you have passed those um uh other courses like uh calculus or usually they are covered as part of pre-algebra or algebra so the Cartesian coordinate system I mean here understanding uh what is for instance the the common um description of them for instance when you when we write like X and then y on the vertical axis and then we can uh we have here zero and um then uh we can always plot this different plots you know we we have a clear understanding what is this um Y is equal to X line we understand how by knowing certain points we can plot different plots for instance that this is the Y is equal to X line that here it means that if we have here one then this is just one two this is two so we understand when we have the function of the line and we have a certain value that is our y coordinate or x coordinate then the corresponding uh coordinates can be found then um you also need to know um some basic things that I just didn’t mention uh right now so for instance that the numbers here can be like one 2 three up to Infinity so you understand this concept of infinity and then here the same uh story then here we have minus one you know minus 2 um and then this is then used later on and we will be uh touch basing this one we will be describing our vectors and how uh we can uh visualize our vectors either two dimensional space like we have here because this is two dimensional so we have X and Y but we can also of course visualize it in three-dimensional Etc so this idea of basic coordinate system is really important um us usually covered as part of algebra if not pre-algebra then we have basic triog gometry which means that you need to have a clear understanding what sinus is what cosine is what tangent is and their reciprocals and here I mean uh that you know for instance um what is cosine function what is s function um you know that you have an understanding for instance that um uh what is this line you know um whether it’s a sinus line or cosine line you have also an understanding what this Pi is um one thing that I didn’t mention but it it just goes um around all these topics some basic things that you understand what is X what is why why we uh use them and this idea of uh variables uh and also uh you need to understand this idea of square uh or you know a 90° uh angle and then uh pagas theorem here we have the same so what is this relationship between different sides of a triangle uh that is a very unique triangle and that has one of the uh angles as 90° um and uh this idea of um you know the sides how this relates to the sinus cosinus tangent cotangent um and also um how the Pythagorean um pagan theor applies when we have uh a triangular but it is no longer with a angle that is 90 degree what is the sum of all the angles of triangle so those are basic stuff that are com commonly covered as part of uh trigonometric uh lessons or part of General geometry then another prerequisite um is this uh understanding of uh identities and equations in triog genometric um lessons something part of which I already covered and this just goes around of basic having a basic uh understanding of algebra and geometry those are super important to understand more Advanced Techniques uh from linear algeb then we have finally this idea of orthogonality perpendicularity in vectors for instance if we have um two lines like this then we are talking about uh perpendicular vectors is when you have two lines that are actually parallel so they don’t have any intersection and you won’t find any point that is common for the TU hi there so let’s get started with our first module which is foundations of vectors in this module we are going to talk about fundamentals of linear algebra vectors we are going to make a differentiation with between scalars and vectors we are going to Define them so first we will learn the theory then we will Implement them into practice by plotting them by looking into different examples then we will look into this representation of vectors by looking into the magnitude and the direction of it and the representation of them just in general we are going to plot them in our coordinate system then we are going to see the common notational vectors and indexing of them vectors are super important when it comes to linear algebra and application of it and uh they matter not only in mathematics but beyond so uh vectors help us in many ways from figuring out how objects move to solving math problems in science and just in general in technology including in data science machine learning artificial intelligence Etc they are super useful tool so uh let’s start our journey with looking into scalers so scalers they are displaying numbers and by definition a scaler is a single numeric volume often representing magnitude or quantity for example uh scalers can be describing um the temperature outside for instance the temperature of um 22° uh can be represented by a scaler or a height of a person can be represented it’s a scaler so let’s assume we have a scaler that we will Define by a letter s is just a variable this scaler is then equal to 22 for instance and we are measuring Dr it in degrees so it means that uh if this s measures a room temperature then the scaler s which is equal to 22° which represents the room temperature it can be for instance 18° or 9° if it’s very cold uh it just measures a single volume it represents just a single number or it can be for instance 17 100 2.22 so all this they are just scalers they represent a single numeric volume they often represent a magnitude or a quantity very soon we will see that scalers they are a value that represent the magnitude of a vector so uh now when we are clear on this very basic concept of scalers let’s actually move to this idea of vectors so by definition a vector is an ordered array of numbers which can represent both magnitude and direction in space so uh vectors they are bit more they represent bit more than scalers they are numbers that also show direction like a car speeding down the highway or a ball uh being thrown for instance uh when it comes to our previous example where we were using this uh uh room temperature as a way to uh think about the scaler a scaler for instance scaler that we just saw was this room temperature room temperature which was 22° when it comes to the vector vector is different for Vector for instance we can have an example when a bird for instance bird it flies flies at 10 kilometer per hour and I I also add here another information which will make this as a vector which is that it flies South so here as you can see what I’m doing is that I’m not just oh let me actually remove this part to make it easier to understand okay so uh in this example let me write it down that the example Birds flies South at 10 kilom per hour so you can see that I’m not just adding the scaler which is in this case the magnitude we will see very soon the formal definition of it so I’m writing down the speed I’m defining the speed but also the direction so I’m saying I know that the bird is is flying south that’s the direction and I know also the speed of it which is the magnitude so 10 km hour so here in the vector I have much more information than in the scaler because in the scaler I just got temperature room temperature single value but in case of a vector I not only have a magnitude or speed like 10 kilm per hour but I have extra information which is the direction of it for instance flying to the South so let’s now look into some real examples and plotting them to make more sense out of this ideal vectors and what is this magnitude what is the direction so let’s assume we have a 2d plane so we have x-axis we have y AIS here like usual we have our z0 Center and we want to plot a simple Vector so uh usually the way we represent Vector in tutorials just writing down is by writing the name of the vector this can be just a a random name let’s assume that it’s a v letter V and then on the top we are always adding this Arrow so this Arrow it says and it tells the person who is reading that we are dealing with the vector arrow on the top is that reference so let’s assume this uh vector v it starts from the center of our coordinate system and it goes to this point so let’s say in here this is our vector v so let’s assume that this point in here is equal to 4 which means that the x coordinate is four and the y coordinate is zero as the uh uh Arrow it just as the point in here it has a a y value of zero so you can see that it goes straight from zero to to this one to this point okay so what tells this Vector uh to us is that we have a value that describes the length of the vector so it goes from 0 to 4 which means that the length is equal to unit 4 so it’s equal to four um and we have just learned and we were just talking about that the magnitude is the length in this case so the length describes the magnitude in this case so this means that the magnitude of this Vector is equal to four and then um what else we can see here we can see the direction of the vector which means that the direction is also something that we can see here this is the direction of the vector so this going straight from this point to this point in a horizontal Al way so independent whether I plot this Vector from 0 to 4 in here or in here or in here or in here or in here in all cases as long as the length is this I’m dealing with the same Vector because I am basically in this entire R2 space I have exactly the same Vector all I care is about the magnitude and the Direction Where will this Vector start and where will it end I am not interested I’m interested that the uh that the magnitude in this case the length is equal to the direction of the vector so let’s now look into another example where we go a bit more difficult on our coordinates and on our Vector we already saw that we had this Vector where we went let me change the color so this was our vector v and it went from zero till four so this point to be more specific is so this Vector it goes the vector B it goes from 0 0 to 4 0 so the coordinate X was four and the Y was Zero now let’s plot another one um where the direction is no longer horizontal for this Vector let’s call it Vector W and for this vector w we will again start with Z 0 so we will start again in here but this time we will go bit like this so let’s say we go all the way to this point so this point has a value for an x- axis of three and for y axis it has a value of four which means it goes from this point to this point and this is the direction of our vector v so it goes 2 3 4 because this point is 3 0 and this point is 04 so xaxis is 0 x coordinate and y coordinate is four so now you can see that the direction of this Vector is like this while the direction of the vector B was like this and like in case of vector v i again no longer care about where exactly my Vector W starts and ends but all I care is about its magnitude so the length and the direction so for instance I can have the same Vector in here the same Vector in here as long as the length the magnitude is the same and the direction I am dealing with the same Vector that’s all I care so the magnitude and the direction is all that you care about all right so now about the length um that’s uh something that you can see very easily from this specific example because by using the Pythagoras Theorem or P Pagan theorem we can see very quickly that as the length of this side of our right angle 30° so right triangle we can see that this side is three this side is 4 which means that this side is five because 4 2 + 3^ 2 then we take the square root of that is square root of 25 and it’s equal to 5 so the length or the magnitude of this vector v is simply equal to five all right this was about this uh specific vectors let’s now look into the uh common representation of the vectors so we always use the magnitude as well as the direction you know to represent the vectors and they commonly are represented by two different uh ways let’s now look into the first way that the vectors can be represented and then we will move on to the next one so when it comes to the vector v so we saw that vector v was moving from 0 till uh to the point of 40 so we can represent the vector B by 4 and Z when it comes to the vector w we can represent that uh Vector so Vector w we can again do the parenthesis and we can say that it’s equal to 34 so by using the coordinates from the coordinate system we can then represent our uh vectors so this is just one way of representing a vector another way of representing these vectors is by using this Square braces given that we are in a two dimensional space first we will mention here the four then we will mention the zero in here two so we can say three and four this is yet another way of representing the vectors in a two dimensional space so if we were to have a three dimensional space so let me actually show it on a new page so if we were to um if we were um to have vectors in three dimensional space so we are dealing with R3 so we have have points that can be described by X Y and Z so coordinate space like this so X and then Y and then the Z then every point so let’s say we have this Vector then we had to represented by a value let’s say x uh X1 y1 and Z1 or um better let me actually use a different letters a b and C and this would be my vector v and I could also represent this vector v is the same so vector v can be represented as a b and c so one thing that you can notice is that unlike the R2 now I have three different entries what we are also referring as rows and we just got one column so um we can uh of represent and usually that’s a common way of representing vectors by using this um columns so columns help us to represent our vectors and you can see very clearly then when it comes to the two-dimensional space so when we have R2 so then our vectors have just two rows so three and four 4 Z like in here when it comes to three dimensional space we have three entries and so so the same holds of course also for for instance R5 therefore for R5 our vectors so coordinate space can be for instance X Y Zed and then GMA and then let’s say Delta and then the coordinates of a vector in that space can be V and then arrow is equals sh and then we would have uh let’s say A B C D E you get the idea so depending on the space the coordinate space and and the dimension of that space then the corresponding vectors can be represented accordingly so the vectors are quantities that have both magnitude and direction as we just so distinguishing them from scalers which only have magnitude so we saw that the scalers got only magnitude while in case of vectors we saw both for the vector v and for the vector w we didn’t we didn’t only have the magnitude so the length of Vector but also the corresponding Direction so uh when it comes to the um vectors so this is exactly what we just saw in our example a vector in a two dimensional space so in R2 uh can be represented by using this Square braces and the corresponding entries for X and Y where X is basically the x coordinate in our coordinate system so in our X and Y system whenever you have this x and y coordinate then uh this x coordinate Will then describe your magnitude and the y coordinate Will then describe your second entry that you need to put when representing your vectors so here the X and Y indicate the movement in the horizontal and in the vertical Dimensions respectively so for the X’s it’s always the x coordinate so how far you move towards the horizontal Direction in here in here or independent in here so always take the x coordinate that is the value that you need to put first and then the Y need to be put it in here so indexing in vectors when it comes to the um indexing the standard mathematical notation uh indices in the N vectors goes from I is equal to 1 to I is equal to n so the um notation here can be a bit ambiguous so AI uh could mean the E element of AI uh the a vector or the each Vector in a collection so let’s start with a simple one and then move on to this next part so what this means and what this means we will look into now so uh usually uh when we have a um n dimensional space we are having hard time visualizing it therefore we use this two dimensional space or maximum threedimensional space in order to get an understanding of what these vectors are so we just saw examples of them uh when uh creating our vectors in um V and V uh and W in uh R2 and also in R3 but we can have similar vectors also in R4 in R5 or all the way down to RN where n can be 100 200 500 any number as large as you want the thing is is that visualizing R4 R5 RN is very hard but we can still benefit from this great properties of the vectors metrices and in general linear algebra in order to describe different things that have more than three dimensions therefore we have this a bit more ambiguous notation where we use RN and this n can be any real number and it can be all the way to Infinity so very large number and uh let’s say we have a vector in this RN then this Vector is usually described by using similar Square uh brackets like before only with uh more entries so like before we got just one column so that’s something that we didn’t uh change but here we have instead of just two entries or three entries like in the two dimensional or threedimensional spaces now we have A1 A2 A3 all the way down to a n minus one and a n so we got in total n elements in our column and this describes our uh single Vector so this Vector in an N dimensional space this we can call also a so one thing that we just so is that it was saying in our definition and notation that uh we might also be dealing with the E Vector in a collection which means means that sometimes you will see this while here the A1 A2 they are vector themselves so here we saw that these are just entries so A1 is a number A2 is a number A3 is a number a n is just a number but it’s also possible uh when you have a much more difficult and complicated case that you got an A let’s write it down with a capital letter A which is equal to A1 or let’s actually remove this so we got let’s say A1 A2 A3 all the way down to a n minus one and a n where you can already see what is going on so instead of having just a number as an entries instead we have vector vors in here so our first element is actually Vector our second element is actually Vector so A2 Arrow A3 Arrow all the way down to a n arrow so while here this can be for instance some numbers let’s say 1 one one all the way down to one one here we have a vector vector another vector and all the way down here you had another Vector where for instance let we remove this part where for instance A1 arrow is actually equal to a11 A1 2 a13 all the way down to A1 n one thing that you will notice here is that unlike in here here I got double indices so I got here a11 and then a12 and then a13 all the way to A1 n so the first index it doesn’t change as I have here a one so I’m writing down the index corresponding to this Vector but the second index it changes per entry indicating which element specifically in the vector I’m talking about so from the first index you can identify the Vector that I’m referring to which is A1 and from the second index you can see the corresponding um entry or the value that that um element is positioned in this Vector so you can see that this values for instance in the um Vector one so A1 to be more specific but then it is in the first position this is in the second position in the third position all the way down to the end position so so this is something that is really important to understand well because this notation is going to appear time and time again across various applications of matrices and vectors so is really important to understand well therefore I want to go one more time through this to make sure that we are clear on what this indices represent so whenever we have an index uh an a vector that we want to uh represent and it’s um it has just um it is just a vector which means that it’s not a nested vector vector in a vector then um we can Define it by let’s say a and then on the top an array and it’s equal to and here we can have A1 A2 all the way down to a n so you can see what we are also referring as dimension of this Vector is equal to n by 1 so I got n entries and just one column so n by one which means that this already gives me indication that most likely this A1 is a number this A2 is a number this a n is a number so let’s say this equal to one two uh three blah blah blah and then here I have let’s say 100 but if I’m dealing with the nested Vector later we will see that this can be repres represented by a matrix then um I can also Define this by Capal letter A which is a common way to refer to either matrices or nested vectors and then this is equal to A1 Arrow A2 Arrow A3 Arrow this already sends a message to the reader that we are dealing with no longer a constant within a vector but rather vectors in a vector and uh what can we see here is that the dimension of this nested vector or which we can also refer to as a matrix here the number of rows so the number of entries this elements we can see is equal to n but then this time the number of values that form these vectors is no longer one because we’re are not dealing with just a constant this is not some constant but rather this is yet another Vector so let’s assume this Vector has a length of M so let’s say this has a length of M then the dimension of this Matrix a is equal to M so something that we will see also when talking about matrices so let me actually clarify this bit more for better understanding let’s say we look into one of those um one uh one other example of an entry so let’s say we look into this specific Vector which is in the um the third uh Vector within this Vector capital A so this A3 Vector so one thing to see here already is that I assumed that these vectors they got M elements and keep in mind that all these vectors they should be of the same size so it means that I already know that this specific Vector A3 has M elements so M elements so I’m representing this uh A3 Vector from here I’m taking this out from this entire uh nested a vector and I just want to represent this and now unlike these elements that got an arrow on the top this time I will have uh constants forming the A3 Vector so I no longer have vectors but I have elements in it so in here I will have a a let me actually write down all the A’s but to refer and to make sure that I recognize that I’m dealing with the third a vector so a tree Arrow here I will put tree tree all the way here three so they all come from the same third A3 Vector but then their positions is different because this is let’s say uh one two and then all the way down to M position so this indices help us to keep track what are the um position that these values are taking part in the vector A3 errow this might seem bit complicated at the moment but whilst we move on onto bit more complex material like uh matrices it will make much more sense this is bit of an extra I just wanted to Showcase this but this is what uh is at its core and what you need to uh understand at the moment to understand this concept of vectors so you need to know that vectors can be represented by this arrow on the top so let’s say Vector a and it has let’s say n elements then you can write this square brackets and then you will need to mention A1 A2 all the way to a n which means that you have n different entries describing your vector so you have A1 which is the first element in your vector A2 the second element all the way to a n which is the end element but here you can see for instance so if I add here A3 that uh A1 is simply equal to 1 A2 is equal to 2 A3 is equal to 3 all the way to a n is equal to 100 so these numbers I’m basically taking and I’m representing them I’m putting them in here here within Square braces in order to get a representation of my Vector so my Vector a has all these different entries and different entries and it starts with one and it ends with 100 this is a vector and then when it comes to the vectors within vectors here we need to be a bit more careful cuz here we not just have uh constant values forming a vector but we have vectors that form yet not vectors so our Vector a our nested Vector a which we uh later will refer as Matrix a has actually entries that also are vectors so we have A1 Vector A2 Vector A3 Vector they are not just constants but on their own they are vectors so here for instance we have defined also an example of it we have said let’s look into this third specific Vector that is part of a which is A3 uh vector and uh that one has M different elements here we have then the index referring to the which Vector from the nested Vector a it is which is the third one because we have taken it from here but then on its own this Vector has different members and different members to be more specific therefore we have also an index to keep track of the position of this value one to up to M and this can be yet another uh this time it can contain some elements an example of which is for for instance 0 1 2 all the way to let’s say 500 and this can be different numbers it doesn’t need to be ordered it doesn’t need to have a specific pattern they can be just random numbers describing this A3 Vector so hopefully this makes sense if it doesn’t don’t worry because we are going to see this time and time again I just wanted to give you a brief of an intro such that you can uh remember this when we come uh back to bit more uh complex topics like uh indexing in matrices so now let’s talk about special vectors and operations here we are going to talk about zero vectors unit vectors the concept of sparcity in vectors as well as vectors in higher Dimensions like we just saw about this nend dimensional space we will also talk about different operations we can apply when it comes to vectors like uh addition subtraction and then later on in the next module we will also talk about multiplication we will also be looking into the properties of vector addition after we have looked into some detailed examples when it comes to operations on vectors all right so let’s start with the zero vectors and unit vectors when it comes to the zero vectors you can see here already that U the zero and arrow on the top it basically refers to the vector like we saw before only with the difference that all its me numbers are zero so you can see here that we have zero and then an arrow and then underneath here we have some number three and then this is described by this common representation with the square braces and then three different members 0 0 0 so all zero and then it says in R Tre okay so why are we doing this well uh when it comes to uh different linear oppr sometimes we just need to add zero vectors or we just want to create zero vectors it’s just easier to work with we want to uh just create an empty uh Vector we want we know the length but we want to keep it empty such later on we can add something on the top or knowing that when we add a zero on a number the number stays the same we can make use of this property to uh do different um uh tricks when it comes to programming in Python in color or in C++ Etc so therefore this idea of zero vectors can become very handy now one thing that you need to notice here is that we are not just writing down this zero to emphasize we are dealing with a vector but like uh before we have this error on the top emphasizing that we are dealing with a vector then what we are doing is that we are also adding the dimension of this V Vector so in what dimension in what space are we um uh creating this zero Vector that this Vector is located is it in R2 in RN in R3 in this specific case you can see that in this example the uh index that we got here is three which basically indicates we are dealing with a zero Vector in threedimensional space so in the R3 uh in general we would just knowe this by n sking the uh notation general which means that we are dealing with 0 0 all the way down to zero so it has n by one dimension in our n all right so this is about zero vectors it is just a way to uh make our programming life easier also to use it in different algorithms when it comes to bit more advanced algebra uh the next type of special vectors that we will look looking to is this unit vectors so vectors with a single element equal to one and all the others zero denoted as EI for the E unit Vector in N dimensions are referred by unit vectors so uh what we mean here when it comes to the unit vectors um if we have for instance E1 it means that we have a vector where the is in this case the first element is equal to one so you can see that E1 is equal to 1 0 0 so in the first element we got one and the remaining is zero and this is really important that we are dealing with vectors that contain only element of zeros and ones and the only member that is equal to the only element in that Vector that is equal to one is the E element in the entire Vector all the remaining ones are zero and you can see here that the dimension is no longer specified but just the um index of the entry where the um uh the uh one is located so let’s look at another example in here for instance when it comes to the um uh unit Vector yet another unit Vector is E2 which basically means that in the second element so in the second place uh the uh Vector con contains one and all the other members are zero so here you can see Zero here you can see Zero only in the second element we have one and then in the e3e what we have here is that the third element is one and all the other ones are zero so let’s actually look into uh one um bigger Vector uh in higher Dimension to make it even more sense so first I will Define and assume that we are dealing with a vector in RN so in an N dimensional space this gives me an idea that we are dealing with um so we are not dealing with nested Vector we are dealing with a simple n dimensional Vector so it has n rows and one column so using the square braces I’m going to represent my Vector so I have all these different members and members C so e let’s say it is E5 so what does this mean it means that r is equal to 5 and this I element so the fifth element is equal to 1 and all the other entries the elements in this Vector are zeros so let’s look into this is 0 0 0 0 I’m approaching the fifth element in my Vector so it’s this one this is one and the remaining all zeros so this is a unit Vector in an N dimensional space and I’m defining it by E5 because my fifth element is equal to one now those are very handy when it comes to some other uh techniques in linear algebra and just in general think about techniques like um uh row eum form solving linear equation something that we will see as part of the next unit so many things um we can do by using unit vectors unit vectors are super important so you need to understand this concept uh very well such that later on you will understand uh more advanced concepts in linear algebra so now look into the topic of sparsity in vectors so by definition the sparse Vector is characterized by having many of its entries as zero so its parity pattern indicates the position of a nonzero entries so uh what we are basically saying is that if we are dealing with a vector that contains too many zeros we are dealing with a sparse Vector so uh this sparsity pattern indicates uh also the positions of a nonzero elements so um if we have um unit Vector it means that we are already dealing with a sparse uh Vector this is a concept that is super important when it comes to linear algebra but also in general data science machine learning and AI because having a sparsity in your vector it means that you don’t have much of an information usually a value zero it means you don’t know much about that specific volum and if you got just too many of zeros and too few numbers which do um provide information it means that you are dealing with a factor that doesn’t provide you much information and there’s always a problem when it comes to data science machine learning and AI so sparcity is something that you you need to be aware of you need to know how to recognize it and you also need to know whe there’s a problem in your specific case or not so let’s look into an example let’s say we are dealing with this Vector X that has five different elements so X is a vector coming from um five dimensional space so we have for instance an element of three in the first entry then we have z z in the second and third uh entries then we have an entry um four which coincidentally also contains value four and then the last element in our five dimensional Vector X is equal to zero now what do we see here we see that the majority of elements of a vector X is equal to zero because we got in total five elements and then we got three of it actually uh being equal to zero and only two of them containing information like equal to three and four so only two elements that are not zero so nonzero elements it means that 3 / to 4 which is basically 60% 60% of all the entries in the vector X are equal to zero so the 60% it means that is above half so above 50% 60% of all the information in this Vector um the majority is simply equal to zero this type of vectors we are uh calling sparse vectors and sparsity is really important concept uh that we need to keep in mind later on so uh while we can visualize vectors in two and three dimensions in linear algebra like we just saw in case of this n dimensional vectors visualizing uh the this type of higher dimensional vectors becomes very difficult so uh this mathematical flexibility uh to work with uh this type of uh information so when we can represent uh information many with many entries we can represent it by vectors which we can actually not visualize becomes very handy for complex data structures for different simulations in physics and much more so uh we just saw in couple of examples uh how we can represent vectors in a high dimensional space using this Square braces and this common Vector notation presentation we saw that in an N dimensional space we could uh very easily represent this uh very large Matrix or vectors uh by just um using this Vector representation for instance if we got a vector that had n different entries where n is for instance thousand so let’s say we have thousand then uh we can represent uh this uh vector or this information by using common vector Vector notation so A1 A2 all the way to a th000 so of course we cannot visualize this it just doesn’t make sense we can visualize two dimensional vectors we can visualize three dimensional vectors but we cannot uh visualize thousand dimensional vectors so Vector that comes from uh r Thousand but what we can do is still make use of this very useful information in order to uh do different operations when and later on we will see that uh this property and specifically this part of linear algebra it helps us to work with vectors in any number of Dimensions whether thousands million billions this mathematical flexibility is super important for more complex data structures uh for metrix multiplications when for instance we are doing different uh algorithms including how we can represent very large matrices very large feature spaces all this different information we can represent just by making use of vectors coming from this specific uh part of linear algebra let’s now finish off this module by looking into some applications of vectors so one common application of making use of vectors is uh when we are performing different operations while having words and we want to count those words so this is a super common application of vectors and we can count these words and you can even plot a histogram of how often each of these words appear in a document so a vector of a length n for instance can represent the number of times each of these words in a dictionary of n words appears in a document so uh just for the sake of Simplicity let’s assume that we got um dictionary that contains only three words of course in reality the um dictionary what we also refer often as Corpus it contains much many uh much more many words but for the Simplicity we will assume that we just got three different words in our dictionary so that’s a total now let’s assume that we got a document uh with these different words and we want to count how many times each of those words that we got in dictionary actually appear in our document so uh if our document is described by this Vector so it contains an entry of 25 2 and zero it means that in our document we got 25 word one in our from our dictionary so in the position one 2 * word two and0 times word three so basically we have have a predetermined set of words in our dictionary in this case three words word one word two and word three and they have a specific index specific position in our vector and when we are putting these values in here then the machine or the uh computer the program will understand that if we have 25 in the first position then the word one in the dictionary appear 25 times in our document whereas the second word appeared only two times and the last word for three didn’t appeared at all so zero times in the entire document so let’s look into a practical example actually to make even more sense so um this is by the way a common practice to count different variations of a word they are common application in engrams large language models Transformers they are just a Cornerstone of many language models when we want to count the words in the document to understand how often the word appears because this gives us a idea what this document is about knowing how many time the same word appears in that uh document it gives as an indication of the topic of uh the do document also we can make use of it to do sentiment analysis to understand what this document is about not only in terms of the topic but also is it a positive is it a natural or a negative uh document so to say so uh for instance if we got uh the following words uh that correspond to our dictionary and in our dictionary we got just um let’s say six different words then what we can do is that we can say 3 2 1 let’s say 0 42 and the corresponding words are word row number horse eel and then document what this means is that we have a text what we refer as a document that contains three times the word word that contains two time the word row contains one time the word number zero times the word horse and four times the word eill and two times the word document so uh this is basically a common way representing the uh frequency of the words in the document let me actually give you uh another example and in here I want to emphasize another thing the concept of stop wordss so uh let’s say I make this 10 and then here I say there is a three times the word I two times the word uh reading two times the word library four times the word book zero times the word shower and 10 times the word uh so uh you can see a that in here we are dealing with a document that contains 10 times the word uh which is what something that we refer as a stop word so those are things that actually don’t give us too much information about what the document is about because uh is just used everywhere but it is appearing too often so you can see 10 times the most frequently appearing word this is what we refer as a toop word and then another thing that we can observe the second thing we can observe is that we are dealing most likely with a document that describes library reading uh because you see the words like reading you see the word like book library but another word shower that is totally unrelated to reading book or library is appearing zero times so even by looking at disc counts we can already get an idea what a topic of this document is about out so uh you can see already now from this very basic example where I made too many assumptions regarding how small the uh dictionary should be uh you can even see now how we can use this counts in our dictionary from our text in order to get idea about the topic of the document or topic of the conversation it can be topic of the uh tweets if you have a tweet data it can be topic uh regarding book if you have many book um uh book texts it can be for instance the topic of the review if you got uh product reviews from uh Amazon for instance using discount can help you to get a topic regarding topic from that text then you can also use it to remove the stop words because usually the stop words are the most frequently Pi words it can also give you an idea about the sentiment for instance here we are dealing with natural sentiment it’s not positive it’s not negative it’s just reading a book in library that kind of topic so all this can be super helpful when it comes to natural language for processing that’s a field where this uh text processing text cing and then using that for modeling purposes is what uh what plays a central role it also plays a super important role in the large language models in the Transformer models and uh in simple matters like uh B of words or uh in the uh tfidf all these they are based on this idea of counting words and how we can use this information and you can see how vectors come into play in these different applications of linear algebra in data science natural language processing in artificial intelligence in machine learning so they are super important another application of vectors can be representing customer purchases for example an N Vector P so let’s say p can record a customer purchases over time with pi being the quantity or dollar value of an item I now what does this mean so let’s say we have Vector P that represents the customer’s purchases and we are dealing with a single customer and we are just saving over time that information how many times customer has made purchases over time so the quantity is in the um dollars so the dollar value of item I purchase so we are basically keeping track of uh what is the value of the item I that the customer has purchased so what we can do is we can assume that in here actually it already makes that assumption it says n Vector which means that the number of rows or number of um items that the customer purchases is n now what the um the problem says that it represents is that in each entry and here we have in total n entries we got a dollar value of item I which means that here if I have P1 P2 all the way to PN and here somewhere in the middle I got Pi I in the East position it means Pi represents the value of item I so for example if I’m dealing with a CER that buys um let’s say uh cores and uh the first item that the customer is buying is a mathematics course so I’m writing mathematics course and this is the first course that it buys e is by the way just a um way to refer to the E purchase so let’s say um here somewhere in the middle the um customer decides to buy a deep learning course deep learning learning course and then it continues buying uh the customer continues buying courses and the last course that the customer buys is let’s say um career coaching course now let’s say the mathematics course cost uh around $1,000 let’s say the uh deep learning course costs $3,000 and then let’s say the career coaching service which is usually one of the most applied and personalized one can cost all the way to $5,000 now we see that in the East position this is the East position let me change the color by the way so let’s say this is the East position this is the first position and this is the last position so those are just indices we can see that in the East position we got the 3,000 which means that the p e is equal to $3,000 so this indicates that in the East purchase the customer purchased deep learning course and the value of that item was equal to $3,000 all right so now we are ready to go on to next major topic which is about vector addition and subtraction so we are going to do some operations and apply this operations to vectors so let’s first formulate Define this ideal of vector addition so uh two vectors of the same size are added by adding their corresponding elements the result is a vector of the same size so uh let’s unpack this it says two vectors of the same size are added by their corresponding elements so here it refers to two different vectors let’s say vector v and Vector W and it says let’s add them what we refer as vector addition and says for that what we need to do is to take all the elements of v and then all the elements of w and using their corresponding elements so indices that helps us to understand where those elements are located we are using in order to add each element in the vector v to the element of the vector W in the same position and do note that in the second part it says the result is a vector of the same size because we are adding two different vectors of the same size mentioning here it means if we add two different vectors to the same uh that have the same size we are going to end up with a vector that has the same size now once I go into the examples it will make much more sense let’s quickly also look into this concept of substraction so on its own uh subtraction is very similar to this idea of addition so if we have a substraction let’s say we have vector v We substract Vector W then we are doing basically uh what we just did to the addition only instead of doing add we are doing subtract so again we are just uh we are just substracting from vector v Vector W they have the same size so we end up having the result uh which is a vector of the same size only one thing that you can see is that this can be also Rew written as V Vector plus and then minus W so we basically can represent substraction um on its own as a way of adding only we take the negative so the um opposite directed Vector so this will make even much more sense uh once we go on to the examples so let’s look into our first operation example where we are adding two different vectors this a basic example we got just two dimensional two vectors we got Vector a that has entries 2 three and Vector B that has entries 1 4 and what we are doing is is that we are adding Vector a to Vector B we just learned that a we need to have the same size of vectors so you can see that Vector a has a dimension 2 by one vector B has a dimension of 2 by one so their sizes is the same both they got two entries only two elements and at the same time we just learned that what we need to do is to take their corresponding elements and add them to each other now what does this mean it means that we take from a the first element two and then we take the first element of the second Vector which is the B so we take the two from here and one from here the first element of a and the first element of B and then we are adding them to each other 2 + 1 is equal to tree and then the same holds for the second ENT tree so tree which is the second element of vector a and then 4 which is the second element of vector B we are saying 3 + 4 is = to 7 so let me write it down even in a simpler manner such that it will make much more sense so Vector a has elements 2 three in the first element we got two in the second element we got three so a then we want to add B which has in the first element element equal to one and the second element is equal to four this means that if we want to add these vectors 2 3 + 1 4 this is equal to we need to take two we need to add one so this element and this element and then we need to take three we need to add to four so this one and this one which is equal to 2 + 1 is equal to 3 3 + 4 is equal to 7 so we got uh Vector 37 do note that this Vector the result vector contains again two elements and just one column so 2 by 1 so you notice that the sign that the size is the same of this result Vector now let’s actually generalize this concept before moving on to the next example so if we got let’s say Vector a that contains n elements A1 A2 all the way down to a n and it is from n dimensional space and we got Vector B that also has n elements so remember that they both need to have the same size so B1 B2 all the way to b n so they come also so B comes also from n dimensional space so then when we add a to B this is equal to A1 A2 all the way to a n plus B1 B2 all the way to BN so n by one n by one the sizes this is equal to let me actually use this color to make it even more visible so I for the first entry for my result factor I will get A1 Plus B1 then A2 + B2 so all the way down onto the end element which is a n plus then we is a different color A1 B1 B2 b n so you can notice now in general terms what we are doing here so we are taking the A1 coming from the vector a we are adding in the same uh position the value that comes from Vector B which is B1 we are saying take the A1 Plus B1 this is the uh first element so the position stays the same and then in the result Vector so we take all the corresponding values that are have the same position in the corresponding Vector first from Vector a and then Vector B we are adding them and this forms our new vector and this new Vector will again have a size n by one so you can see that a the sizes of the two vectors are the same both have n elements and then we are using their corresponding elements to add them to each other element wise and then we are getting the result that has the same size so n by 1 so this is a more General description of how you can add two vectors let’s now look into this specific example so we have a vector with the entry 073 so this comes from R3 you can see so three dimensional vectors the second Vector is 1 2 0 and then the final result is 1 193 so how we got this we took Zer we added 1 seven we added two and then three we added zero so you can see all these elements element wise and then this is equal to 0 + 1 is 1 7 + 2 is 9 and then 3 + 0 is 3 exactly what we got here so again the same sizes and the result is from the same size so quite straight for forward now when it comes to the vector substruction what are we doing that um so what are we doing here so we are doing kind of very similar thing we are taking this element one we are subtracting the other one in this first element then we are taking the nine in the second position and subtracting this again from the second position of the second vector and we are putting in here 1 and then 1 – 1 is equal to0 0 9 y – 1 is = to 8 so we get result Factor 08 like in here and you can see that the sizes stay the same so also in this case let’s write more General um this ideal subtraction if we got a vector a from RN so n dimensional space and it can be represented by A1 A2 all the way down to a n so it has n elements n by one and then we got B also from RN so coming from the uh n dimensional space which means that it got n elements so B1 B2 all the way down to BN again with the same size n by one then a minus B is simply equal to a A1 let me actually show use the same colors to make it easier to follow so let me first draw my Square races and then here I will use blue for a and then red for the uh color for second Vector which is B here I will use black minus then given that the same size should be for the result Vector I already know that I expect n different elements for this and then here I’m taking this first element that comes from Vector a i subtracting from this the first element that comes from Vector B so element wise substraction B1 and I’m already getting the result for the first element in my result Vector so you can see A1 minus B1 I’m taking this element and this element as subtracting them from each other to get A1 minus B1 and then the same holds for all the other values only coming from different elements from Vector a sub substracting from this the corresponding values element Wise from the vector B so B2 B3 all the way to a n so you can see that in my result Vector a vector minus B Vector in the first element I get A1 minus B1 then A2 – B2 then A3 – B3 in the third element all the way down to the end element which is equal to oh this should be b a n minus BN so um this already should makes uh much more sense so every time we take the element in the same position from one vector than the other we subtract from each other in order to get the corresponding element in the final Vector all right so let’s now uh before moving on to the properties um I wanted to show you um this only in a coordinate space so what this means in terms of visualization in a coordinate space so uh let’s say we have a coordinate space this is my Y axis this is my x-axis so this is X and the Y and this is my Center so 0 0 and what I’m doing here is simply I want to have Vector a let’s say this is just um Vector a simple one with the coordinates um let’s say four and – 2 and I got Vector B let me use a different color Vector B that has coordinates let’s say minus 4 and four so let’s actually visualize them let’s first start with the vector a uh which has a x value four three and 4 1 2 3 and 4 and the Y value minus 2 so this is my Vector a and let’s now visualize the vector B so Min – 4 and four which means that let me actually extend this this is min -4 so the x coordinate is min -4 so it should be here and then the y coordinate is four so 1 2 3 and 4 it’s this one which means that my Vector B is this one all right so you can see now that the vector a is in here and the vector B is in here now what I want to do is to add this two vectors to each other so what I want to do is to take this Vector a and add to this the vector B which is is equal to 4 – 4 it was 0 and then – 2 + 4 is = to 2 so zero and then two it is zero and two two so this is my result Vector so now when we are clear on how we can add vectors how we can perform these different operations and what it means in practice when it comes to looking at the vectors in a coordi space and adding them or subtracting them we are ready to look into the properties of vector additions so this is something that will definitely seem familiar to you uh from pre-algebra where we are basically using all these properties that we already know that holds for uh numeric values for the scalers that being transferred to this Vector space so we are going to talk about this four different properties that a vectors uh have the first one is the cumulative property which says that if we add a vector a to Vector B then this is the same as adding a vector B to Vector a so basically the order of the vectors doesn’t really matter when it comes down to adding them so formally a plus b is equal to B+ a for any vectors A and B of the same size then we have associative property which says a plus b + C is equal to a + b + C we can write both as a + b plus C now what does this mean we know from prealgebra that this parenthesis me means first do this addition and then do the rest of operations in here it basically says if you add a to the B first and then you add the C is the same as first you add B to the C and then on the top of that you add the vector a so then the third property is addition of zero vectors which says if we add a zero Vector to Vector a then this is equal to adding a vector 0 to a and this is equal to Vector a so adding the zero Vector has basically no impact on the vector whatsoever then the final property is subtracting a vector from itself which means if we take the vector we substract the same Vector from itself so a minus a and we get a zero Vector so a minus a is equal to Zer vector and this heals the zero Vector now let’s look into each of those properties one by one and Let’s uh look into specific examples uh in some cases we will prove this on the example that we have to make this Concepts much more clear so let’s start with this cumulative property of vector additions so we want to see whether a plus b is equal to B + a so let’s say we have a vector a that has coordinates or magnitude and direction that is equal to one one and two then we have a vector uh let’s say B that has a magnitude and direction of Min – 2 and three so the first thing that we want to check is indeed whether the A + B is equal to B + a so therefore let’s first calculate this part and then we will calculate this part that I will def by one and two and we will see whether we are indeed having the same value the same vector or not so let’s see so we have here a so a plus b which is the first value that we want to calculate a + b is = to 1 2+ – 2 3 and we learned before that this is simply equal to take this value and then add this one so 1 + – 2 and then 2 + 3 so this gives us a vector 1 – 2 is = – 1 and 2 + 3 is = 5 so we get that A + B is = -15 this Vector now let’s look at the second quantity so B Vector B plus Vector a this is equal to – 2 3 + 1 2 and this is equal to – 2 + 1 and then 3 + 2 this gives us – 2 + 1 is = to min-1 and 3 + 2 is equal to 5 so we can already see from here that the quantity 1 is indeed equal to quantity 2 which proves that indeed the A + B is equal to B + a what this basically means is that adding two different VOR the direction or the order is not important whether you add a on the top of the b or B to a it doesn’t matter at the end is the same and actually you can also see it if you uh combine this or if you do this in a more general terms so let’s say if we have a vector a which is equal to in an N dimensional space A1 A2 up to a n so it has n by one dimension and you have a vector B with the same size from the same RN Dimension and it has elements B1 B2 up to BN and the dimension is equal to n by one then if we calculate first a plus b and this is equal to Simply A1 + B1 A2 + B2 up to a + BN and if you calculate the second U amount which is B + a and this is equal to B1 + A1 B2 + A2 up to BN + a n you can see that A1 + B1 is equal to B1 + A1 simply from pre-algebra you know that if those are constants for instance 2 + 3 is = to 3 + 2 in the same way a 2 + B2 is = to B2 plus A2 and then here up to a n plus BN is equal to BN + a n what this means is that all these elements they are basically the same which means that we already have a proof so we get this proof and we can see that even for the general term independent what is Vector a is what this Vector B is that a + b is equal to B + a this is exactly what we saw before in the first property which is called commutative property of the vectors that A+ B is equal to B + a now let’s move on to the other property which is called associative property of the vectors now what this property does and says is that a plus b so first we do this plus C is equal to a + b + C and this is then equal to a + b + C now let’s then see um this specific property on an actual example so what this basically says is that if we have this example where a is equal to actually I had this before let me simply just remove this part let’s then add our third vector which is C and let’s call it let’s say it has a representation of four and five then the idea behind this property is that what we need to prove here that A + B within the parentheses plus C is equal to a plus B+ C and then this is equal to a + b plus C so let’s see actually whether this is indeed true for this specific case now this should come very intuitive so I’m going to do it very quickly so first we have this quantity this one then we have this one and the third one let’s do it very quickly so so A + B + C is equal to one two plus and then we have C so it is simply 4 five and then this is equal to we saw before when doing this that we were getting one Min – 2 2 + 3 and then we add this four five this is simply equal 2 1 – 2 is -1 and 2 + 3 is 5 + 4 5 now given that it doesn’t really matter no longer that do we have uh here parenthesis or not this basically means that this volue is simply equal to -1 + 4 so here -1 + 4 here 5 + 5 so this is then equal to three and then 10 all right let’s then now quickly do the second amount which says first add the vector B to Vector C and only then add the vector a on the top what this means is that we need to take one two this is Vector a and we will only add this once we have added the minus 23 the vector B plus to the vector 4 five okay so we can see that we are just leaving this in here let’s first add this two – 2 + 4 3 + 5 so this gives us 1 2 + – 2 + 4 is two and then 3 + 5 is 8 so this gives us let me remove this calculations so this gives us 1 + 2 is = to three and then 2 + 8 is = to 10 okay great so now we got already the quantity one being equal to quantity 2 let’s check whether this is all equal to this one it should already be um something that you see now given that um we know just from mathematics that parenthesis doesn’t really matter when it comes to the scalers and adding two vectors is basically very close to this idea of edited property um of the edited property of the scalers but just let’s quickly do to be 100% sure so when we take this Vector a to the B and to the C we had all this this is equal two want to added to minus 2 three and then added this to four and five now what this is equal to let me actually write this in be sure to way such that it can be all fitting in the small place so one cu plusus 2 3 + 45 this is equal to basically 1 – 2 + 4 and then 2 + 3 + 5 and what is this number 1 – 2 + 4 is simply equal to 1 – 2 is = to -1 and then + 4 is = to 3 so first element is 3 2 + 3 + + 5 is equal to 5 + 5 which is equal 10 perfect so now we get the confirmation that indeed A + B + C is equal to a + b + C is equal to a + b + C so let’s quickly also look into this addition of zero vector and the subtracting a vector from itself properties and uh the detailed explanation of this or example of this I will leave it to you so when it comes to this a plus um 0 is equal to 0 + a is equal to a so this property let’s say if a is equal to this 23 and then we are adding on this a plus some zero Vector which basically means take two threee and then added the same size of zero Vector you can see that this is the same as adding this zeros on these values now what do we get we get add that this is equal to 2 + 0 is 2 and then 3 + 0 is 3 there we go so we already see very quickly that it doesn’t really matter whether we add a zero Vector to this original a vector or not we in all cases it just adding a zero Vector has no effect and seeing from the commutative property that a plus b is equal to B+ a we already know that if um a + 0 is equal to uh a and is equal to this then also 0 + a will be the same and we can see indeed that we just saw that a + 0 is simply equal to a so we basically have quickly proven all this now when it comes to the subtracting a vector from itself I think this is a very nice one just to see how we um uh take the same Vector I subtract from that value and we get zero and this is very similar to working with just real number numbers in the same way as 3 – 3 is equal to Z also when we have a vector consisting of the scalers like a is equal 2 23 in the same manner if we take this a and we subtract it from itself so a minus a then what we will get is 23 minus 23 and this will give us 2 – 2 is0 and then 3 – 3 is z so we get Vector zero so zero vector so now when we are clear on how we can perform different operations on our vectors and also we know uh what are the properties of uh adding and subtracting uh different vectors we are ready to move on to a bit more advaned topics so uh in this module we are going to discuss this idea of scalar multiplication we’re going to look into the example how what happens and how we can do the uh Vector multiplication with the scalar then we are going to uh look into the span of vectors what it means to have a span of vectors uh what is this IDE of linear combination and the relationship between the span and linear combination and the unit vectors now we are going to look into the application of scalar Vector multiplication in audio scaling uh example and then finally we are going to finish off this module by looking into the length of a vector and a DOT product and we are going to uh go back to this idea of distance understanding vector magnitude and understanding Vector length so let’s get started now before we look into this idea of span and linear combination I quickly wanted to look into this idea of scalar multiplication and the um specific definition of it so formally the scalar multiplication involves multiplying each component of a vector by scalar value effectively scaling the vector’s magnitude so what do I mean here let’s say we have a vector and I will write it in the general terms to keep everything General so let’s say we have a vector a let me pick up my pen a and this Vector a is from n dimensional space so it is from RN and it can be represented by A1 A2 up to a n and I have this magnitude um of a vector and now I want to scale this Vector for which I know the magnitude and the direction I want to scale it with a scaler and we learned before that the scaler is just a number so um scaler in this case I will be uh referring it to uh by C so c will be my scalar and uh this comes from R which means that it’s a real number let me actually use a different col color to make it easier to follow okay so my scaler will be with the color uh red so C and C comes from R so what do I mean by scalar multiplication I mean that I want to find what is this c times a this is what we mean by scaler multiplying with Vector now what does this definition say it says when we are multiplying scalar with Vector so the scalar multiplication meaning multiplying Vector with the scalar it involves multiplying each component of a vector by a scalar value so if we translate it to this specific example it means that this amount so this amount is equal to taking C and multiplying it with each element of this Vector so each component of a vector and what are the components of my Vector the A1 A2 a up to the point of a end so all these components so that means that the first element of this new Vector the scalar multiplication a result will be C * A1 C * A2 dot dot dot so all this middle elements and at the end again c times and then a n and then in both cases of course the number of elements doesn’t change so the so the number of rows of my Vector doesn’t change it’s n so here also n and then number of columns is the same so it’s just a column Vector so one column so what we see here is that we go from A1 to C * A1 we go from A2 to C C * A2 up to the a n transforms into C * a n so we see very easily that I keep all the elements from this Vector I take them in here and instead what I’m doing is that I’m multiplying every element from this vector by the scaler C so this is exactly what this definition says and let’s actually go ahead and do a Hands-On example with some real numbers to have this um method and to have this uh definition very clear in our mind because we are going to make use of this fundamental operation scalar multiplication on and on in the upcoming lectures and just in General in your journey in any applied sciences so this is an example of scalar multiplication uh here what we are doing is that we want to multiply this Vector C so in this case the vector is defined by a letter C and then on the top we can see the arrow indicating that this is the vector now and here we refer the scalar by a letter K we are saying we want to perform scalar multiplication which means that we want to multiply the uh Vector C by the scalar K so how we can do that so what we want is to multiply K by C and we just learned that for that what we need to do let me write this over so this equal to minus 2 multiplied by 4 – 3 this is my Vector so this is the k a and this is the C this is equal 2 so I take my scaler and I multiply it with the each of the element of the C so – 2 * 4 and then -2 * -3 so – 2 * 4 is = to – 8 and then – 2 * – 3 so– it goes away it becomes a plus and the 2 * 3 is 6 so my end result the K * C is equal to – 8 6 this is my final result so let’s quickly also do yet another example and this one is a unique one because it’s relating to this idea of U multiplying something with a zero uh which is something that we also uh know from our high school that when we multiply number let’s say seven by zero we’re getting zero and here in this example exle the uh problem is describe the effect of a scalar multiplication by zero on any Vector which means what we are doing is that in this example is we want to know what is this result of any Vector let’s say Vector uh C so we will use the same example C only this time instead of multiplying it with the scalar K = to minus 2 our scalar will be zero which means that c is equal to 4 – 3 and then K is now equal to zero and we want to find out what is this K * C let me actually write down the K with a different color k is equal to zero so what we want to find out is K times and then C and this is that equal to zero so I’m taking the K 0 times then I’m taking each of the elements of C which is four and then minus 3 and I know that when multiplying the number with a zero it gives me zero which means that I end up with 0 here 0 * 4 is 0 0 * – 3 is also zero so I end up with a zero Vector now this gives me an idea already that I can make a general conclusion that independent of the type of vector that I have independent what are these values in my C uh if I have any Vector C and I’m multiplying it with zero then this will always give me a vector of zero because all the members of this final Vector will be just zeros so if for instance the C comes from uh let’s say r n so it has n different elements it comes from uh n dimensional space then my final result of 0 time C so this zero Vector this one so zero that this one will come also from our end so you will be having a vector so zero time c will then be equal to 0 0 blah blah blah blah zero so n time zeros so this is then the idea of multiplying so scaling a vector with zero and this is our example two all right so let’s now move on on to our application of scalar Vector multiplication and then after this we will go back to this idea of linear combination and dispense so in this specific application we have a scalar Vector multiplication and we are looking into application of audio scaling so the scalar Vector multiplication audio processing uh this can change the volume for instance of an audio signal without altering its content so um you might have noticed that um when uh when you are listening to video you can simply increase the volume of that video or decrease it but you will notice that the content doesn’t change you are just increasing the volume or decreasing it even on the TV when you are watching a show you are increasing The Voice or decreasing now what you’re basically doing behind and this is super interesting is that behind the scenes what is happening is that there is simply um audio that um contains that show and audio of that show is being multiplied with a scaler and that scale is simply the volume scale if you scale it in such way that you want to decrease the volume so the audio will then have a lower volume then you are simply multiplying it uh your vector containing the audio information in such way that those newer volume indications they will be they will be containing lower numbers hope this makes sense let’s look into the example this make uh this will definitely clear this out so um let’s let assume we have an a vector a that represents the audio signal and we want to multiply Vector a by scalar B to adjust the volume so B is some sort of number it can be so B comes from our so is a real number while a is simply a vector given that it doesn’t mention it here I’m assuming that a comes from RN so it comes from our uh n dimensional space so imagine of a as this Vector A1 HQ blah blah blah blah up to a n and each of these values it basically describes uh an uh the audio signal so it represents um uh an amount so it contains an amount that represents the audio signal of your uh video or uh your uh show and then the B in this case for instance in this example you can see that the B is then uh equal to for instance 1.2 1id 2 or B is equal to Min – 1 / 2 so you can see that b is equal to 1 / 2 which basically is offensive saying that b is equal to 0.5 or B can be equal to min-1 / 2 which is – 0.5 now then it says then the B * a which basically means multiplying our um scalar beta by the vector containing the audio signal a so this B * a is perceived as the same audio signal but at the lower volume now why lower because you can see that b is equal to 0.5 or minus 0.5 it means that once you take all these elements of your a and you multiply it with a number that is smaller than one in this case 0.5 then all these numbers will decrease which means that also your audio volume will decrease so let me actually uh show you an example so let’s say our talk show is very short and you know the audio variation is very low you have a vector a that is quite small it comes comes from a three dimensional space so R three and it has numbers like three uh six and then five so 3x one vector and then we have our audio adjustment scaler beta which is equal to 0.5 now when we take the beta we’re multiply it by our audio signal then what we do times this clear so times what we are doing is that we are simply taking all the elements of our a so Three 6 and 5 and what we are doing is that we are multiplying it by 0.5 0.5 and 0.5 or you can also say 1 / 2 so what this is equal is that 3 * 0.5 is 1.5 6 * 0.5 is 3 and then 5 * 0.5 is 2 2.5 and you can see that all these numbers 1.5 3 and 2.5 they are smaller and specifically two times less than all the original values in the um original audio so original audio is a which was 3 6 and 5 and the new audio the scaled one is so audio scaled so B * a is equal to 1.5 3 and 2.5 so you can clearly see this transformation where uh this element three is larger than 1.5 6 is larger than three and then the last element five is larger than 2.5 which means that this audio audio is much at a higher volume so the Volume Two Times Higher then this audio so this is basically the idea of uh applying scalar multiplication to our audio preprocessing I will leave the other example to you that will show that when your scaler is equal to minus 0.5 you again will end up with a lower volume only that time the volume will be much much lower than the original one so now that we know how we can perform scal multiplication in theory as well as we have looked into an example how we can do it in terms of the numbers and multiplying them and we have also seen uh applying scale multiplication in practice uh so we have seen in this audio processing stage the uh multiplication process we are ready to look into the visualization of it this will help us to get a better understanding on uh what exactly happens when we are scaling different vectors let’s look actually in the following example so let’s assume we have a vector oh let me remove that so let’s us show we have a vector and that Vector is let me get a color this one for instance a vector a and this Vector a consists of elements one and two so where does this Vector like the vector is with um one so here in our coordinate system this is our xaxis this is our y AIS and here we got uh let me actually pick another color let’s say black one and then we got one and then two right this is two this is one so it is this one so the line that we get here it is this one so this is our Vector a now let’s assume I want to multiply my Vector a so I want to scale my Vector a by a constant Tree by scaler tree so I have a scaler let’s say I call K and this k a different number let’s say k is equal to three so what I want you to do is to perform a scale multiplication so I want to obtain K multiplied by a and we learned that this is simply equal two three times and then one two and then this is equal to 3 * 1 3 * 2 which is equal to 3 and then six so let’s also visualize the scaled uh Vector so let me pick this yellow color this will be our scaled Vector so we have that scale multiplication and we are going to visualize that so we have three and six so this is three one 2 three and this is six so we have this point so you should already see what is going on here so we got 3 a here so you can see that this part is our Vector a and this longer one is 3 a and even visually you can see that this longer Vector is simply the three times of the shorter Vector so we got this and then if you add on the top of this the same three times you will then end up with the original so scaled version of that so basically this is a this is a this is a we combine three different so we scale a three times and we simply get a three * longer version with the same direction so you can see that when we are scaling even visually it makes sense so we are scaling our Vector a three times and we are just getting that Vector so we are transforming well let me remove this so basically we are taking this vector and we are scaling it up to this point if I would do it on only two times then it would be something like this or one and a half times it would be something like this so only half of it so now this should make much more sense let us actually do yet another example to uh make sure that we are clear on this visualizations because we are going to make use of it when uh looking into this idea of linear comp combination in a spin so let’s say we have a vector B and this Vector B has elements Z and three so let’s visualize and uh plot this Vector so it contains elements Z and Zer and three so0 and three so this is the X element and the Y element on the Y AIS we can see this is three which means that our Vector B is this vector all right perfect so this is our B let’s now multiply so scale our Vector B by scalar 2 so let’s say we want to get 2 * B so what is this amount this is equal to 2 * 2 * and I’m simply taking each of those elements zero and then three so this is then equal to 2 * 0 is 0 and then 2 * 3 is equal to 6 so this is my new skilled Vector 2 * B Vector this one so let’s visualize this the x-axis value is zero so we are still here and then the Y AIS value is sixth so what is sixth this thing all right so you already should see that this is very similar what we had before so this is 2 B all right so this all uh should make sense uh also we learn as part of the um High School when visualizing different plots so this is quite similar to this idea of having Y is equal to X and then scaling it getting like Y is equal to 2x so in this case only we know exactly where the vector starts and ends uh so we have uh much more specific definition instead of having all this infinite number of points on the line but the idea stays the same so we are taking this vector and we are then scaling it two times so we get 2 B vector and I could do the same only instead what I could also do is I could do like uh 0.5 or 1 / 2 * B so I take the half of it which means I would get this vector or I could multiply with minus one so minus – 1 * B so I will scale with minus one and then I will simply get the negative version of my original Vector so this thing this would be minus b or min-1 * B so this is basically the idea of uh scal multiplication when visualizing it in our coordinate system cartisian coordinate system and now when we know all this we are ready to move on on this idea of linear combination and now when we know all this we are ready to move on on this idea of linear combination so let’s now formally Define this ideal of linear combinations a linear combination of vectors A1 up to a m using scalers B1 up to BM or what we also refer as beta 1 to Beta m is the vector beta 1 * A1 Plus up to Beta M * a m and the scalers are called the coefficients of linear combination and any Vector B in N Dimensions can be expressed as a linear combination of the standard unit vectors E1 up to n the coefficient in this combination are then the entries of B itself well this is whole bunch of information uh let’s unpack them one by one firstly um I want to mention about this m so far we have seen this idea of n so I just wanted to experiment with a different one just to ensure that we are clear that you can use any source of identifier to describe the size of your um uh number of vectors that you got and uh in this case we got M different vectors because so far we were using this n in order to describe the size of a vector and now we are no longer talking about the size of a vector but the number of vectors therefore I specifically didn’t use the letter N so here m is simply the number of vectors so don’t confuse this with this thing where we were plotting this and we were saying this A1 A2 up to a n because in here we basically mean that we are dealing with some Vector a and this has n different elements whereas in here we are already moving from this IDE of one vector and now we are talking about multiple vectors so we have M different vectors they all look like kind of this only with bit more complex indexing that we also saw before all right but we will learn this um that’s not an issue I just wanted to mention this to ensure we are at the same page so then let’s move on to this idea of using scalers beta 1 till beta M so it’s a common uh practice in linear algebra in just in general in mathematics but also definitely in data science statistics and in artificial intelligence to use beta 1 as a way to describe the coefficient so what do you mean by coefficient it is just a scaler so it’s just a constant or number so in this case for instance this beta one can be 0.5 beta one can be uh two beta one can be let’s say 100 it just describes how much we are multiplying scaling this Vector A1 so so far we have done lot of scaler multiplication already a lot of details there and we have seen different times different scalers that we use we can use um zero as a scal we can use any other number as long as it’s a real number so this beta 1 should belong uh in the real number space so it’s a real number and of course the same holds for uh all the other betas so we have M different vectors which means we are going to have M different scalers because each of those vectors we are going to multiply with their corresponding or respective scalers so beta 1 is basically the scaler uh or the um uh coefficient that we are using to scale A1 maybe I can actually write this down on a new page such that we can save this as a slight page for you let’s write it down so what do we have as this idea of linear combination so a linear combination simply involves taking several vectors uh to go from this uh formal definition to more practical uh terms so we got this A1 A2 up to am and what we want to do is to take the linear combination of this m different vectors so we got m is the number of vectors and to get a linear combination we need to uh scale each of those vectors which means that we need to have these different scalers let’s say beta 1 for A1 and then plus beta 2 for A2 so each time we are scaling each of those vectors where beta 1 is the uh scalar or the coefficient of the vector A1 and we are multiplying we are performing scalar multiplication of our scalar beta 1 with the vector A1 and then we are adding to this our beta 2 which is the coefficient corresponding to the vector A2 and then adding beta Tre times A3 and then dot dot dot so all these different uh vectors up to the point of beta M time a m and all this so A1 A2 up to a m those are all vectors belonging to the m space so those are all vectors coming from the um m diamension space so um in here this is the linear combination of our M different vectors and the uh beta 1 beta 2 up to Beta M those are all constants so those are scalers or real numbers that belong to R so those are real numbers all right so now when we are clear on that let’s also unpack this idea of coefficients so the scalers are called the coefficients of linear combination so basically all this members so beta 1 beta 2 of two beta M that belong to real number space they are called coefficients this is what we are referring as coefficients and this coefficients this ID and the name is super important because you will see this time and time again appearing in your uh very basic machine learning models or some other applications of linear algebra because the end goal is always to find these coefficients so this coefficients those are numbers that we are using to scale these different vectors and uh the idea of coefficients is very Central because those are numbers that Define how exactly we are combining all these different vectors because this beta 1 beta 2 Beta 3 they can be different numbers real numbers and every time when we are choosing these coefficients or these betas we will then end up with a different combination of these vectors so we’re basically mixing all these vectors and the way we mix it and how we will mix it it will depend on the values of this beta 1 beta 2 Beta 3 up to Beta M so these coefficients so therefore coefficients are super important and they Define the end results from our linear combination so any Vector B in N Dimensions can be expressed as a linear combination of a standard unit vectors E1 up to e n so when looking into this um idea of unit vectors uh we saw already what this E1 is what is E2 is up to e n and we saw that E1 is for instance if it’s from an N dimensional space and it says from n dimensions then E1 simply means 1 0 0 do dot do do0 then E2 means 0 1 0 dot dot dot dot zero so we already saw this this is not something new that we are seeing so 0 0 blah blah blah and then one at the end and what this definition basically says is that any Vector b as long as the B comes from n dimensional space we can represent this by using this uh unit vectors and by linearly combining them so this is get another part of this definition and we are going to by the way um go through each of the parts of this definition one by one going through each of their examples as well as visualizing them so now I just want to quickly unpack all the parts in this definition before moving on to step bystep examples and explanation so this is about this linear combination of any n dimensional uh Vector B that we can uh create by using a link combination of these unit vectors I will come to this in a bit so then the final part of this definition is that the coefficients in this combination are the entries of B itself so it says that the coefficients so beta 1 up to Beta m in this linear combination that we can create are the entries of B itself so we will come to this section once we are done with the first part so first let’s have a good understanding of what this linear combination is and we will also touch base and we will also formally Define the idea of span and after that we will move on on uh representing and expressing any Vector B in N dimensional Space by using standard unit vectors E1 up to e n and this idea of coefficients and then entries of B so let’s start with the first one so let’s assume we have two different vectors we have Vector a and this Vector a is equal to one 2 so let’s plot this one and two in our coordinate space that is this one which means that our Vector a is this one and let’s assume that we have a vector B and this Vector B is equal to 03 so 0 is here and then three is here which means that our Vector B is this one this is Vector B now I want to create a linear combination of this Vector a and Vector B so we just learned from the formal definition that in order to do so I need a beta 1 to multiply the vector a and then I need beta 2 which is the coefficient corresponding to to my second Vector in order to multiply the second vector which is B Vector B okay so I’m getting the linear combination of A and B by taking any beta 1 and beta 2 which are real numbers so beta 1 and beta 2 belong to R so they are real numbers and then I’m getting a linear combination of the two so let’s look into a few examples of a linear combination of vector A and B dependent on the different choice of the co efficients like beta 1 and beta 2 so example one is that beta 1 is equal to zero and then beta 2 is equal to Z Now what is the linear combination of A and B when my coefficient beta 1 and beta 2 both are zero it just means that I’m getting 0 times a plus 0 * B which is of course 0 * 1 0 * 2 plus and then multiplying Vector B with a scaler 0 which is 0 * 0 0 * 3 so let’s quickly do this what this value is this is equal to 0 * 1 is 0 0 * 2 is 0 0 * 0 is equal to 0 0 * 3 is equal to 0 and this is then equal to 0 + 0 0 0 + 0 is 0 so I’m basically getting a vector zero all right so this is then equal to zero so this equal to Vector is zero so I can also say that this vector or it’s actually a point so this point is simply a linear combination of these two vectors now this is super basic case let’s look at another case when our in our second example the beta 1 and beta 2 so our coefficients they are actually not zero there are some other nonzero real numbers so in this example I will then take beta 1 = to 3 and then beta 2 is equal to two and then what I will do is that I will take actually I will take the um minus 2 then I can also get rid of one of the elements and I can get actually a zero for one of the elements I will show you in a bit so then the linear combination of A and B using this coefficients beta 1 and beta 2 where beta 1 is equal to 3 and beta 2 is equal to minus 2 is then equal to so this amount this amount is equal to 3 * 1 2 and then plus we got – 2 times 0 and three now what does this give us 3 * 1 is = 3 3 * 2 is = 6 Plus and then – 2 * 0 is = to 0 and then – 2 * 3 is = to – 6 so you might have already noticed why I picked the beta to equal to minus 2 I wanted these two numbers to actually cancel each other so you see because 6 + – 6 is equal to Z so what do I get in my final result as a linear combination of these two vectors I get 3 + 0 so 3 + 0 so 3 + 0 and then 6 + – 6 and this gives me 3 + 0 is 3 6 + – 6 is 0 there we go so this is my linear combination of the vector A and B when using the coefficients equal to 3 and minus 2 respectively so this value is actually equal to three and zero in this case all right so let me actually clean this up because I also want to visualize this idea and then we will go uh back to this uh linear combination let’s just summarize uh what we got before moving on to the plotting part so if we simply take a and we add to this B so this is the first case so this is as you might have already guess this is also linear combination here we are saying take 1 * a and take a 1 * B and this is yet in our linear combination here the beta 1 is equal to 1 and then beta 2 is equal to 1 so this linear combination gives us a vector that is 1 + 0 is = to 1 and then 2 + 3 is = 5 this is our first linear combination when the beta 1 and beta 2 is equal to 1 this is a basic case so doesn’t require too much explanation here we have seen already this let’s now look into the other example that we saw when we use uh the zeros as our coefficient so that is 0 * a + 0 * B then this gave us 0 0 this was our second linear combination when beta 1 and beta 2 were both equal to zero and then the third linear combination that we saw was that 3 * A+ – 2 * B this gave us three and zero this was our third linear combination where beta one was three and then beta 2 was minus 2 so so then the linear combination of these two vectors is basically all the possible combinations of these two vectors that I can get when scaling or when multiplying these two different vectors by different sorts of uh vector by different sorts of scalers so in all these different cases what I’m simply doing is I’m taking different sorts of code coefficients beta 1 and beta 2 and then I’m getting the linear combination of these two vectors we saw that in the simple case when we take a and we had to B so basically the coefficients are equal to 1 so 1 * a + 1 * B then the corresponding linear combination is equal to 1 and five it means that we are getting this Vector so one and five is in here which means that we are getting this one this Vector if we get if we take the zero as scal so beta 1 and beta two are both equal to zero then the linear combination of these two vectors is simply the vector zero which means that it is this point then if we take the linear combination using three and minus two as coefficients then we are getting this so 0o and three so one two and three this is three then this is our linear combination I can also take any other uh like scaled version of my B and of my a and then I will get entirely different sort of vector so let me actually show you a few more times um a couple of other examples so let’s say I keep my a so I just take the beta 1 equal to 1 but instead I scale my Vector B two times so this was at three I’m taking two times of my Beta which means that I’m here then I can take this I can add this to my a so this is 2 B this will give me another linear combination of these two different vectors I can also you might recall that we said that the starting point and the end point doesn’t really matter for for us what matters is that we uh have the same magnitude and the same direction for our vectors so this means that for me the vector being here and the vector being here doesn’t matter when I scale it two with two I can be here with three I can be here so this is the same as my B only three * B this is basically scaling B with three and this in here means that my Beta 2 is simply equal to three and then this means that I can combine this with my a which was in here you remember so this here this means that I get yet another linear combination of these vectors which means that I’m taking 3B and I’m adding on this my a so 1 * a my beta 1 is equal to 1 my Beta 2 is equal to 3 which means that the linear combination of this is equal to one 2 plus and then 3 * B is equal to 0 and then 3 * 3 is 9 this is then the new linear combination which is one and 11 so the new linear combination is equal to 1 and 11 so this thing which is the same as this thing and then you can go on and on you can also calculate the same with a negative B so you can take B and then you can scale it with minus one so this is minus b or you can go in here in here the same holds for a so you can scale it all the way to here or in the negative side so this already uh give us the idea that we will go into to the next point which is the span so when it comes to the linear combination and in this specific case when we have these two vectors we can combine these two vectors in any way and uh we can mix them up by using different sorts of coefficient of beta 1 and beta 2 and we will can we can get any Vector in our R2 so this means that any Vector in our R2 we can represent by using only these two vectors and this is not always the case for this specific case we are dealing with two vectors that we can use to represent any Vector in our R2 so what I mean here is that let me clean this up so independent what kind of vector you will give me in the R2 so it has two different elements it is 2 by one I can use a linear combination of A and B so a linear combination of A and B is beta 1 * a plus beta 2 * B in order to represent this Vector X1 and X2 therefore we are saying and we will come to this um in the next slide too that this pen of the vectors A and B so this is the set of all possible combinations of these two vectors is equal to R2 because any Vector in R2 can be represented as a linear combination of this two vectors so we have a linear combination of A and B and I’m saying that I can represent any Vector so here Vector X and this Vector X I’m representing by X1 and X2 and X1 and X2 can be any real numbers so X1 and X2 they belong to R and X is simply a two-dimensional Vector so X1 and X2 those can be any numers Z 0 1 2 – 100 anything and I’m saying any number in this two dimensional space so whether it is this one any Vector this one this one or this vector or this one any Vector that you give me in two dimensional space I can find a linear combination of this A and B that is equal to that Vector so I can represent that Vector as a linear combination of vector A and B that we saw before so let let’s actually prove that so I’m going to represent this uh X1 and X2 by a linear combination of this Vector A and B and how we can do that so we have beta 1 * a plus beta 2 * B it is equal to X1 and X2 where beta 1 and beta 2 so beta 1 and beta 2 they are constants so they are also real numbers so let’s unpack this which is beta 1 * 1 2 2 + beta 2 * 03 and this should be equal to X1 and X2 now this is equivalent of so beta 1 * 1 beta 1 * 2 plus beta 2 * 0 and then beta 2 * 3 and this should be equal to X1 X two so this is my beta 1 a this is my Beta 2 B and this is my X all right so now what we get is that and this is equivalent beta 1 * 1 is equal to beta 1 beta 1 * 2 is 2 beta 1 plus then here beta 2 * 0 is z and then beta 2 * 3 is 3 beta 2 so we have learned uh from the uh operations on the vectors that beta 1 uh so in this case when we are adding two vectors so beta 1 plus zero is the uh amount that we need to put as our first element so when we are adding two vectors we just need to take their corresponding elements we need to add them up so this equal to beta 1 + 0 and then 2 beta 1 + 3 beta 2 this is the result and this should be equal to X1 and X2 at least this is what I’m claiming so this zero doesn’t matter matter so we what we are getting from here is that beta 1 is equal to X1 and then 2 beta 1 + 3 b.2 is equal to X2 this is the two expressions that we are getting based on all these different calculations so let me actually remove all this so we have beta 1 is = to X1 and 2 beta 1 + 3 beta 2 is equal to X2 so here given that we have already that beta 1 is equal to X1 and here we have two unknowns I’m going to fill in the value for beta 1 in here so I’m going to take this and I’m going to fill in it in here here so for this volum so remember that beta 1 and beta 2 are two unknowns and X1 and X2 are just uh numbers that we will get when we uh know exactly the vector and we just want to represent that Vector as a linear combination of two vectors so when I take this uh value for beta 1 which is equal to X1 and I’m going to fill that in in here it means that I’m going to get from here that beta 1 is equal to X1 and 2 * X1 because beta 1 is equal to X1 and here I got beta 1 I’m just filling in the value for beta 1 which is equal to X1 so 2 * X1 and then the rest I’m just taking over three bet 2 is equal to X2 let me remember move this and from here what we are getting is that beta 1 is equal to X1 and I will solve this equation for the unknown which is equal beta 2 so I will just take the three beta 2 from left hand side I will leave it there and I will take this and I will take it over to the right so I’m taking X2 over and this two X1 so this part I’m just taking to the right two of the equation so minus 2 X1 which then on its turn is equal to so it goes to beta 1 is = to X1 and then beta 2 is = to X2 – 2 X1 / 2 3 perfect so what do we get here what is our end result and why is it significant so what we are getting here is that based on all this information without knowing beta 1 and beta 2 we got that beta 1 should be equal to X1 and beta 2 should be equal to X2 – 2 X1 / 2 3 this means that independent what kind of ex’s you will give me so what kind of vector we have in our AR 2 so this X1 and X2 they are just real numbers we can always find beta 1 and beta2 that we can use to represent that X1 X2 so our X Vector as a linear combination of these two vectors let me actually give you an example so let’s remove this so let’s assume we have a vector X and this x is equal to 4 and let’s say three so if we got this Vector X and we are saying we can use this Vector A and B to represent X as a linear combination of vector A and B which means that I can find I can find real number beta 1 and beta 2 that I can use to multiply the vector A and B respectively combine them together so they’re linear combination that will be equal to this Vector X so this is my X1 this is my X2 so this is equal to 4 and three Now using this let’s actually see whether that is true So based on this example my beta 1 should be equal to X1 which is 4 my Beta 2 should be equal to X2 which is 3 so beta 2 should be equal to X2 which is 3 – 2 * X1 which is 4 / to three and what’s this number this means that my beta 1 should be equal to 4 and my Beta 2 should be equal to 3 – 8 so 3 – 8 / to 3 and this is equal to- 5 / to 3 so this means that I can use a coefficients beta 1 is equal to 4 and beta 2 = to – 5 / to 3 to represent my Vector X as a linear combination of vector a and Vector B so let’s actually prove that too as a final step so let’s see where four times Vector a which is one 2 plus – 5 / to 3 whether this is indeed equal to Vector X so my Vector B is 03 so this is the first part and I want to prove that this is indeed equal to X and we already know what x is so this is equal to 4 * 1 4 * 2 plus and then here we got – 5 / 3 * 0 and then – 5 / to 3 * 3 this is equal to 4 * 1 is = to 4 4 * 3 is equal to 8 and then here we need to subtract minus 53 5 5 / to 3 * 0 is equal to 0 so this one is zero and then minus 5 / to 3 so 5/3 * 3 this ones are canceling out and we got 8 + – 5 so here the plus and here minus just to make sure we got everything right and this is equal to 4 and then 8 + – 5 is equal to three so you can see already that this amount that we got here is equal to X which was equal to 4 / to 3 and this helps us to uh verify and to know for sure that indeed while given any Vector in a two dimension space in our two x independent what this X1 is or X2 is we can always find a pair of beta 1 and beta 2 that will ensure that the beta 1 a plus beta 2 B is actually equal to this x where X A and B they are part of R2 and a is equal to one two and then B B is equal to 03 so we can represent any Vector in our two dimensional space as a linear combination of this Vector a with elements 1 2 and um Vector B with elements 03 and that’s exactly what we saw here because we could find any vector and we can represent this Vector as a linear combination of this Vector A and B this Vector as a linear combination of this A and B this Vector as a linear combination in any vector or a point in this plane we can represent as a linear combination of this Vector a and Vector B and in this specific case with this Vector a and Vector B we are seeing that Vector a and Vector B they spin R 2 so Vector A and B Spen R 2 now we will come to this definition of the span and just in general for different sorts of vectors we will see what this idea of span is but for now given that we just proved that we can represent any Vector in R2 as a linear combination of these two vectors A and B therefore we can say and we usually say it in linear algebra that the vector a and Vector B they spend R2 before moving on onto this concept of Spence that we just touched upon in our example I wanted to quickly go back to this example that I promised to discuss uh which was part of the definition of the linear combinations and unit vectors because we saw in our definition and let me just show you that uh the uh definition was providing these two highlights these two bullet points and was saying any Vector B in N Dimensions can be expressed as a linear combination of the standard unit vectors E1 to up to E n and the coefficients in this combination are the entries of B itself so let’s look into the example and see what we mean by that in this specific example we have this Vector B it is coming from the threedimensional space which we can see given that we have three different uh three entries so three uh elements in our Vector so it’s three by one and this means that b belongs to R Tre and in here we can see that B can be written as a linear combination of these three vectors so you can see that b is equal to min-1 * this Vector 1 0 0 so this one then we have + 3 * 0 1 0 Vector so this one and plus 5 * this third Vector which is 0 01 now we already know from the unit vectors that E1 is equal to 1 0 0 assuming that we are in three dimensional space E2 is equal to 0 1 0 and E3 is equal to 0 01 you can notice that that’s exactly what we got here this Vector is E1 this Vector is E2 and this Vector is E3 where E1 E2 and E3 belong to threedimensional space okay so another thing that we can see is that here we got coefficients minus one here three and here five so this is basically how beta 1 beta 2 and beta 3 using the common conventions that we saw before when describing the linear combination so let’s actually check that and then we will comment on these values so let’s check whether -1 * E1 + 3 * E2 + 5 * E3 is indeed equal to this B so this is equal to min-1 * this Vector gives us Min – 1 0 0 three times this E2 gives us 0 three and 0 and then 5 * E3 gives us 0 0 5 and this is equal to -1 + 0 + 0 is = to -1 0 + 3 + 0 is = to 3 and then 0 + 0 + 5 is equal to 5 now what do we get here we see that this which is equal to this it is equal to this Vector B indeed okay so now when we have indeed checked that B can be represented as a linear combination of these three vectors these unit vectors E1 E2 E3 another thing that we can notice and I’m sure you already did is that those coefficients they are not just randomly picked coefficients those are the entries of this Vector B so this is exactly what that definition was about it was saying that any Vector B including this example in in this case threedimensional space can be expressed as a linear combination of the standard unit vectors E1 E2 E3 Etc so this coefficients in this combination so you can see that the beta 1 beta 2 and beta 3 which are our coefficients in our linear combination they are the entries so this values of the B itself so the same will hold for four-dimensional Case five-dimensional Case n dimensional case so this means that if we write this down for General case just to ensure that we are clear on this part of the definition so if we got B Vector in N dimensional space so it got be one B2 up to BN as the elements of it comes from RN then we can represent this B as a linear combination of unit vectors coming from the N dimensional space so we got E1 E2 up to n that belong to n dimensional space and we can represent this B as a linear combination of these unit vectors so by using beta 1 times so this this is a common Convention of the coefficient as you might recall time C1 then beta 2 * E2 blah blah blah plus beta n * e n and what is important here is that this beta 1 beta 2 and beta n those are not just some coefficients but we already know what these coefficients are because we can then represent this beta by taking the values so those are the entries the elements of the vector B itself so it is B1 time B1 plus B2 times E2 dot dot dot Plus BN time e n where B1 B2 up to BN they are all real numbers so basically knowing what this Vector is this elements of this Vector we can always describe and express it as a linear combination of the standard unit vectors and if you’re wondering why is this important in some cases when performing different operations or working on different algorithms it just becomes handy to represent your vector as a linear combination of multiple vectors and in those cases exactly you can make use of this property of linear combinations to express your n dimensional Vector b as a linear combination of the standard unit vectors because everything is then down to you by having this Vector B you will already know what are the entri that you can use as your coefficients in this case beta 1 beta 2 so those are all these values coming from your vector itself and then the remaining is also known because you know exactly what these unit vectors are and how they are represented so here for instance the E1 is basically 1 0 0 blah blah blah blah 0 and then this is n by one vector here the E2 is equal to 0 1 Zer blah blah blah and then zero here so n * 1 again up to the point where you have the e n where you have all these zeros only the last element is one again n by one vector so this is the idea behind this second part of this definition which says that any Vector being n dimensional space can be expressed as a linear combination of the standard unit vectors E1 up to e n let’s now talk about other concept which is also super important which is the span of vectors so by definition the spend of a set of vectors is a set of all possible linear combinations of these vectors so if V is equal to V1 V2 up to VK and is a set of vectors then the span of V is written as a span V and it includes any vectors that can be expressed as C1 V1 up to C2 V2 up to CK VK so basically it is a common uh notation uh to say that if we got for instance vectors V1 V2 up to VN so we have n different vectors then we say that the span of V1 V2 up to VN that this is simply the notation that we use in order to describe this Spen of this vectors and we briefly spoke about this concept of span when we were looking into our example that we saw before so you might recall this vectors A and B that we had and we saw and we said that the span of a and b is the entire space in the two dimensional uh real number space so we said that span of a and b is equal to R2 where our Vector a was simply equal to 1 2 and B was equal to 03 so we proved that the span of one two and 03 was the entire R2 and how we knew that because we proved that any Vector in R2 could be represented as a linear combination of these uh two vectors so so you might recall that we solved this equations we saw that independ what kind of X1 and X2 uh one will give us we can always use the um U we we found this amounts let me see where I can find it back I no longer have this so we saw that for uh specific values of um beta 1 and beta 2 we can always get a linear combination of this A and B in order to get our desired vector X so beta 1 * a plus beta 2 * e will always then be equal to X1 and X2 if our Vector a and a vector B are those but of course this doesn’t hold for all the vectors so not for all uh two-dimensional A and B uh we can say that the spend of these vectors is the entire R2 therefore to better understand this concept of span and this concept of span of vectors I wanted to distinguish five different cases one of which we already spoke about and that is the case when we had this Vector a and Vector B and we said that the span of a and b is the entire R2 but we will also look into the case when we for instance have a span of the zero Vector the span of a single vector and the span of perpendicular vectors we might also look if there is time left we will also look into the span of parallel vectors so let’s now look into this cases one by one so let’s say we have a vector of zero so we have zero Vector so this is a very simple case we will start with the simplest case and we will move on WE two more advanced cases if we have a vector a that is a zero Vector 0 0 then independent what kind of scal we will use to scale this so let’s say um we Define it by C so C * Z independent what kind of scalar we will use this will always end up being equal to 0 0 so if C is equal to z c * 0 will be equal to 0 if C is equal to 1 C * 0 will be equal to zero or C is equal to 100 C * 0 will still be 0 0 so independent what kind of scal we will be using what kind of linear combination we will create from our Vector a this will always stay in here so the point the vector will always stay in here in our two Dimension space so this is completely different from what we saw before when we could create and we could take any Vector in our R2 and we could represent it as a linear combination of these two vectors that we saw in the previous example so in this specific case um scaling the zero with independent of any scalers we use this will not change the magnitude nor it will change the direction of our Vector so no matter how we scale it we still get zero this means that the span or zero Vector is just the zero Vector itself so you can see that independent what I scale the zero Vector I always end up with the same zero Vector so therefore the span of the zero Vector is equal to zero because by definition the span of set of vectors is the collection of all possible vectors that I can reach by performing linear combination and in this case I will always Reach This Z 0 Vector so all possible collections of these vectors are the vector 0 0 which is single vector and the same as the input so this is the basic case now let’s move on onto a bit more uh Advanced case so bit more complicated than this one but itself also very easy which is when we got a single Vector a so let’s say a a is equal to 1 and 2 now I want to know what is the span of a in order to know what is the span of a we simply need to understand what are all these possible collections of vectors that I can get when I’m uh combining um a I’m multiplying a with different coefficients so what are the all possible linear combinations of this Vector because I got just single Vector a so a is one two which means one in here and then two here my a is this vector and let’s look into uh different uh scalar multiplications of this Vector so let’s say I want to calculate C * a so the scalar multiplication of this where C is equal to C is = to 2 C is equal to 3 C is = to uh min-1 C is = to Min – 3 and of course C is = to 1 so in all these cases when C is equal to 1 then the linear combination in this case just the scaled multiplication of this single Vector a so 1 * a is simply equal to one and two so the same Vector a c is equal to 2 this will give me 2 and four C is equ 3 this will give me 3 and 6 C is = to min-1 will give me -1 – 2 for my a and then C is = to -3 will give me -3 and then Min – 6 so let’s plot each of those so if we got for instance C is equal to one case you can see that we already got that Vector in here so it is this Vector when C is equal to 2 then we got this one so two and four so where is that it is in here let me use another color it is in here when we got say is equal to three then we got so this one three and six so this is three and this is six so it gives me this vector in the next example so in the next linear combination we have C isal to minus one so we got min-1 and min-2 so where is min-1 it is in here where is min-2 it is in here so I’m getting this vector and then finally when I have let me change the color when I have C is equal to minus 3 so this case then I got minus 3 six which means that here is my minus 3 here is my- 6 so we got this thing so you already should see what is going on here when we got just a single Vector for which we need to know what is a linear combination and that Vector is not a zero Vector it has nonzero elements but um it’s still it is just a single Vector then all its linear combinations given that it is simply uh scaled multiplication of it we are all getting them on the same line so you can see all the linear combinations of this single Vector is just a scaled version of it and it lies on the same line so what this tells us is that essentially you can move along the line defined by this Vector a but you cannot leave it so you cannot get a vector that is in here that is in here that is in here in here here so you cannot leave this uh line you will always stay on this line so this line essentially span of a so when we got a single vector and that Vector is not equal to zero Vector then the span of a is equal to and this can be expressed as C * a given that the C is a real number so we already saw this in depending on what kind of scalar we will take any linear combination of it will end up simply this C * a so therefore we are generalizing this and we are seeing that the span of a so to set of all possible linear combinations of this a is simply equal to C * a given that the C is a real number this is basically the spend of a real uh uh Vector in a two dimensional space let’s now look into the next case the next example when we will calculate or we will Define the span of a perpendicular vectors so let’s now look into another example when we are looking for a case when the um when we want to find out the span of perpendicular vectors so imagine we have these two vectors Vector a and Vector B where a is equal to 1 Z and then B is equal to 01 so we are still in our lovely uh two dimensional space so let’s first visualize the vector a it’s quite basic it is this one and then Vector B it is simply this one so we can already see why they are perpendicular so you can see that they are forming this um 90° angle so right angle here and then we know that the spin so that’s exactly what we want to find out so the span of a and b and this is what we want to find out out and we know that the span of two vectors is the set of all possible linear combinations of these vectors so we want to see what are these all possible linear combinations of C1 so all the possible outcomes that we will get when we get a linear combinations of these two vectors so basically C1 times a plus C2 * B Because those are all the linear combinations of these two vectors C1 * a + C2 * B nothing thing that we can see here quickly is that C1 * a so this part those are all the skill sced versions of a so scaling multiplications of a and this second term in the linear combination those are all the scaled variations so scalar multiplications of vector B which means that and we already have seen this time and time uh again that when it comes to Vector a all its linear combinations they will lie on the same line so let me take this color so if I do 2 a so C1 is equal to 2 then I will be in here if C1 is equal to three then I will be here C1 is equal to 4 I will be here C1 is equal to 10 I will be in here and then the opposite holds as well if C1 is equal to for instance minus uh 2 then I will be in here if it’s equal to Minus 5 I will be uh my Vector will look like this and so on so this means that all the scaled multiplications of vector a will lie on this line so I can also say that the span of C uh the span of a so span of a is simply equal to C1 a so you can see in here so on this line basically so this is C1 a so this basically means independent what kind of C1 I will take with is 1 2 3 0 – 5 – 100 I will always end up on this line so this line so this is about the uh scaled multiplication of a but of course to create this linear combination of A and B we also have the second element which is the all possible scaled multiplications with a vector B so C2 B2 so let’s see what that looks like so if I for instance take C2 is equal to Z I will be in here if I take C2 is equal to uh two I will be in here C2 is equal to 5 I will be in here C2 is equal to Minus 5 I will be here so you are already seeing what is happening here so all the power possible scaled multiplications with Vector B will be on this line so now we are then getting that the span of B will then be equal 2 C2 and then B and here I’m not using formal notation I’m just trying to um I’m just trying to to uh draft the idea of the span of vector a and uh span of vector B because we are not uh done yet we still need to combine the two in order to find the span of vectors A and B when they are perpendicular so when this angle is simply 90° okay so let’s also add this on our plot so this is C2 and then B so this already gives us an idea that all the possible combinations of the two so when we add these two elements to each other the outcome will always lie on this two lines but there is no way that we can find any other coefficient for C1 or C2 that can help us to get a value that will be so a vector that will be in here or in here or in here or in here that’s just not possible so just you can try to go ahead and solve that equations like we did before and you will see that there there is no way that you can pick here a line and you can represent it as a linear combination of these two vectors it just not possible and later on we will see why but just keep in mind for now that once we have this this type of vectors when two vectors are perpendicular then um we cannot find a line a vector that is outside of these two lines so here you can see the x-axis and the Y AIS but it can also be like this it can also be like this but then you cannot find any other line that lies outside of this area that you can uh create a linear combination of these two different vectors and then you say then you cannot say that you can create a linear combination of these two vectors A and B so therefore when it comes to defining the pan of this two perpendicular line we say that the span of a and b given that A and B are perpendicular but also given that this values in this case you know a is equal to 1 is z b is equal to 0 and 1 then their span you might have already guessed is equal to C1 a plus C2 B given that C1 and C2 are of course real numbers so in this case C1 and and C2 as expected are just scalers so they are just some real numbers coming from R and uh this a A and B those are vectors that are being spent and in this case specifically the vector a is equal to this one Z and Vector B is equal to 01 and this expression that we see here this pen this simply describes the set of all possible vectors that can be formed by adding the scaled versions of this A and B so C1 a plus C2 B in order to form this linear combination so this set this set of C1 a plus c2b which is a linear combination all possible linear combinations of these two vectors so um it effectively covers the entire plane illustrating that any point in 2B space can be reached by some combination of A and B let’s now move towards our final example that we saw also as part of our definition for the span of vectors in order to check and to learn how we can usually check uh whether the two vectors they really spend the entire space so in this case we got two vectors we got Vector uh V1 which is equal to one two and Vector V2 which is equal to 34 so in here and also um we uh have in our example that it says the span of V1 and V2 is all over the R2 because any Vector in R2 can be expressed as a linear combination of V1 and V2 so the example basically is saying that if we know that um we can express any Vector in R2 as a linear combination of V1 and V2 then we say that the span of V1 and V2 is the entire R2 so let’s actually go ahead and prove that from our example so we have X which we can represent as X1 and X2 and X1 and X2 are just real numbers and we got V1 which is 1 2 V2 which is 3 4 and we got in our example that uh we need to prove that the span of V1 and V2 is the entire R2 so for that what we need to do is we need to prove that we can express our coefficient C1 and C2 in such way using X1 and X2 that independent of what is X1 and X2 are so what kind of X Vector we have whether this is like one two or this is 04 or this is th000 and uh 5,000 independent what kind of vector we get uh we give here so X1 and X2 values as long as those are real uh numbers we can always find a set of C1 and C2 that we can use as coefficients in order to create a linear comp combination from vectors V1 and vs2 and in that case we say then the span of V1 and V2 is the in R2 okay so let’s go ahead and actually prove that using our previous knowledge that we already gained so keeping in mind that C1 and C2 are unknown numbers for us whereas X1 and X2 are just a way to describe those elements in our Vector X that will be provided to us so X1 and X2 will be basically known and C1 and C2 are the unknowns that we are chasing so for that the first thing that I’m going to do is to describe this linear combination that we got here C1 V1 plus C2 V2 with actual equations unknown equations and the way I’m going to do it is by simply filling in this Vector V1 and Vector V2 um vales so we have C1 and then C2 here and then here I got one two plus and then three and 4 here and what is this amount so this is equal to let me actually go on to the next row so we can create um set of equations for this so This equal to X and we get C1 * 1+ C2 * 3 is equal 2 2 and remember that this is X and we said that the x is equal to X1 and X2 so this basically equal to we can right here is equal to X1 and X2 so this is then equal to let’s not skip all the steps X1 and X2 so here then the second elements need to be added so C1 * 2 and C2 times 4 which is then the same as C1 + 3 C2 and then 2 C1 + 4 C2 and then this we are saying this Vector is equal to X1 and X2 so this is what we have here and let’s move from the vectors to equations so given that we have this we are allowed to say that this gives us actually two equations this means that this element this element from this part should be equal to this and this element should be equal to this now let’s write it done we see that C1 plus 3 C2 should be equal to X1 2 C1 + 4 C2 is equal to X2 this is all that we see in here let’s remove this to keep the space clean now what this means is that we have two equations with two unknowns C1 and C2 and X1 and X2 are the numbers that will be provided to us as part of our Vector so what we want to prove is that we can describe and we can express C1 and C2 which are our unknowns using a X1 and X2 so you see here this is C1 C2 those are our nouns and we want to describe them by using X1 and X2 and very soon we will also see why so for now let’s try to express those two unknowns using our nouns like X1 and X2 so here I already see that C1 is alone so there is no scaler so I will make use of that opportunity to keep the C1 one on the left hand side and I will take this this amount to the right so I will say C1 is equal to X1 minus 3 C2 okay slightly better so I have C1 at the left I do have X1 in the right but I also have 3 C2 in here but another thing that you will notice is that in my second expression here I got 2 C1 + 4 C2 + 62 I want to have the C2 on only because then I will have an expression of my C2 only using X1 and X2 um so numbers that are that will be provided to me that are n so for that what I’m going to do is basically trying to solve uh two equations with two unknowns exactly the same um process so I’m going to take this C1 from the first equation and I’m going to fill in in the second equation so I going to say two * and here I’m going to fill in that C1 expression from here so X1 – 3 C2 so this is my C1 plus just taking over this part so 4 C2 is equal to X2 okay perfect so now what I end up with is C1 is equal to X1 – 3 C2 just taking it over and then here I’m opening parenthesis which is 2 X1 – 6 C2 plus 4 C2 is equal to here I forgot an X2 is equal to X2 okay one step closer why because I in my second equation I no longer have a C1 I only have a C2 which is great which means that this gives me an indication that I can reun the C2 which is unknown with nouns with X1 and X2 so let’s make use of that opportunity the first equation I would just take over so C1 is equal to and then X1 minus 3 C2 and then here I will do 2 X1 and then here we got two * c2s which means we can combine them so minus C uh minus 6 * C2 + 4 C2 it gives me – 2 * C2 and this is equal to X2 all right let’s now solve that so what I want to have is just the C2 in the left hand side which means I need to bring all this to the right and I need to get rid of them such that I can leave the C2 in the left entirely alone so this is what I’m basing basically chasing for that I’m going to once again rewrite C1 is equal to X1 minus 3 C2 and this time I’m going to take them minus 2 C2 here I’m going to leave that in the left but then this one I’m going to bring to the right so X2 – 2 X1 here I need to be very careful to not make a mistake CU that will mess up my entire calculation all right so now we are one step closer just taking over the first equation again so C1 is equal to X1 – 3 C2 and here what I need to do to get rid of this minus 2 is to divide the two sides so both 2 minus 2 cuz that will help me to keep the C2 only in the left alone without any scaler so the C2 is than equal to X2 – 2 X1 / 2 – 2 so this is what I end up with perfect so we are very close stay with me so um here what we are getting is that C2 is equal to this amount we see that now we no longer have any other C’s in here which is great and remember that X1 and X2 will be numbers that it will be provided to us I just wanted to keep everything General and then uh another thing that I want to fix is this C2 because the C2 is an unknown and I want to fill in uh this value of C2 in here such that for the C1 I will have a similar picture so in the left hand side I will have C1 in the right hand side I will Express the C1 with no number so X1 and X2 but not the C2 or others all right so let’s then go ahead and do that first I will write C2 in a simpler way so C2 is equal to here I got a minus I will just write here minus so I will take the minus over here and then I will write X2 – 2×1 2 um be super careful with this minus therefore I’m using parenthesis so now I’m going to use this C2 and I’m going to fill that in in here so C1 is equal to X1 minus 3 times I can also make it plus because minus of here so minus of here and minus of here will cancel out therefore I will do plus three times and then X2 – 3 X1 / 22 and this then gives me C1 is equal to X1 + 3 / to 2 * X2 – 3 sorry 2 almost made a mistake 2 X1 and then C2 is equal to X2 – 2 X1 / 2 2 and here we got minus Perfect all right awesome so now we have expressed X1 and X2 well careful with this X1 and X2 with only noun numbers now what I’m going to do is that I’m going to prove that independent what kind of X we will be taking here we will end up getting the C1 and C2 using this what we just found here that will give us a linear combination of these two vectors that will be equal to that X so for that so to prove that this patter of V1 and V2 is the entire R2 I need to prove that in depend what kind of X I will take so X1 and X2 I can always find the C1 and C2 that I um just calculate in here using that X1 and X2 that I can then use to combine with my V1 and V2 to find the linear combination of these two vectors with that C1 and C2 which will be equal to this X so for that what I need to do first is to take such a uh random X so let’s say my X is equal to 0 and 4 this means that my X1 is equal to 0 and X2 is equal to 4 what this means is that this gives me C1 which is equal to and here X1 so I’m basically filling these two values for here to obtain my C1 so C1 corresponding to this specific Vector X so X1 is equal to 0 which means I end up C1 is = to 0 + 3 / to 2 * X2 is equal to 4 so 4 minus and then 2 * X1 is = to – 2 * 0 which is 0 and then C2 is = 2 minus and then X2 is equal to 4 so 4 and then minus 2 * XY is = to 0 0 and then this divided to 2 now what are those numbers so C1 is equal to 3 / to 2 * 4 which is 3 * 2 so 6 and then C2 is equal to minus 4 and then minus so this is zero this cancels out which means 4 / 2 is 2 and then C2 is equal to – 2 so basically I have calcul calculated the coefficients C1 and C2 by just knowing what is this Vector so knowing X the provided X1 and X2 I have calculated my C1 and C2 using my derivations in here so let’s now get rid of this this calculations to clear some space and to do the final part which is compute the linear combination of vector V1 and vs2 for this specific coefficients well knowing what this given Vector now is this example random Vector so the C1 is equal to 6 which means six times and then Vector V1 is one 2 so this is first part of my linear combination plus and then C2 is equal to minus 2 * then here three 4 what is this this is equal to 6 and then 6 * 2 is 12 plus now let’s calculate the second part – 2 * 3 is – 6 and – 2 * 4 is – 8 so what does this give us 6 – 6 and 12 – 8 this gives us0 and four nice so this confirms that we have done everything also correctly which is great because we have seen that using this C1 and C2 that we have just calculated we have successfully comp uh computed the six V1 so linear combination of this uh two vectors V1 plus minus 2 minus 2 and then V2 and we have seen that this linear combination is equal to 04 which is exactly our X so in this way we have proven that independent what kind of vector we will pick what kind of X we will pick here we can always find and calculate the corresponding coefficients C1 and C2 in the same way as I just did and then by using those when we calculate the linear combination of these two vectors with this specific coefficient this will be exactly equal to X and this proves that inde depending what kind of vector we have in our R2 we can always express that as a linear combination of the vector V1 and V2 and this proves and this concludes our proof that span of V1 and B2 is the entire R2 all right so we are very close to finishing up this unit so the next topic we are going to talk about is a linear Independence and all this important stuff that we learned as part of the previous modules are going to become super handy as part of this specific concept so we just spoke about the idea of span we have plotted a lot of vectors we have seen the linear combination of that and how we can find out whether the span of multiple vectors is the enti space uh for instance the R2 or it is just the line or it’s maybe the zero Vector we have seen many examples and many operations we have also seen this idea of unit vectors and we are finally ready to come to this very important concept which is a concept of linear Independence so by definition linear Independence says that the set of vectors is linearly independent if no Vector in a set can be written as a linear combination of the others otherwise they are linearly dependent so vectors V1 V2 up to VN are linearly independent if and only if the only solution to the equation C1 V1 plus C2 V2 plus CN VN isal to Z is C1 is equal to C2 up to CN is equal to Z in other words in a lar linearly independent set the equation C1 V1 plus C2 V2 plus CN VN is equal to zero has only the trival solution where all CIS are zeros so now what do we mean here there is a ton of information in this definition so let’s unpack them firstly it’s TR important to uh keep in mind this idea of Independence and dependence Independence and dependence there are things that we commonly use in data science in artificial intelligence in statistics so those are really important so we basically have linear independent condition so there is a certain condition that our vectors should satisfy vectors in our set in our Vector space for them to be named as linearly independent and otherwise we are calling them linearly dependent and you can you can see that here there are a couple of Parts as part of this definition first it talks about um being unable to recreate a vector in a vector set while using the remaining vectors in our set so it says if you can use the remaining vectors in your vector space and linear create a linear combination of them so linearly combine them and we have already seen the definition of linear combination so if we cannot create such linear combination from the remaining vectors to get our Target Vector then we are saying that we have a linearly independent vectors so if we want to say that all our vectors in our Vector set they are linearly independent it means that each of those vectors we should not be able to recreate out of the remaining vectors so we should not be able to find coefficients to create linear combination using the remaining vectors in order to get our Target Vector now what do I mean by this target Vector what do I mean by this linear combination uh I will come to this in a bit for now let’s just try to unpack this definition cuz uh with examples uh we will definitely go through this step by step in detail such that this idea of linear Independence and dependence is super clear so in this second part of the definition it says vectors V1 V2 up to VN are linearly independent even only if the only solution to the equation and we have here in the left hand side you might recognize the linear combination of our vectors V1 up to VN so in in the right hand side you have zero so you are saying our linear combination of vectors is equal to zero if and only if C1 C2 up to CN is equal to zero so linear Independence basically claims that we will have linearly independent vectors only if and only in the condition when um the only way we can create linear combination of these vectors equal to zero only if those coefficients are zero there is no other way that we can get a linear combination that is equal to zero while those coefficients are not zero so the only way that we can get a linear combination out of all our vectors equal zero is only when all of the coefficient C1 C2 up to CN is equal to zero that’s something that we will come later to this again there something also that we are going to come back in our next module and the next one so um this one will be also super clear once we go through those modules but for now keep in mind that the uh linear combination of all these vectors can only be zero in case when all these coefficients are equal to zero so and then we have the third part in our definition which says that in other words in a linearly independent set the equation C1 V1 + C2 V2 up to CN VN is equal to zero has only the trivial solution where all CIS are zero so this explanation is basically what we just talk about as part of this second part where we said that only in case the coefficients are all Zer we can have a Lear combination of our vectors V1 V2 up to VN which is equal to Zer and why we would like this linear combination to be equal to zero because it’s a common way to find solution to our linear system so this is something that we will also see as part of the next module when we will be discussing the IDE of solving l your systems we will go into more uh Advanced topics but for now in order to understand this idea of linear Independence we should just keep in mind that we cannot find any CIS so C1 C2 so any coefficients that is not equal to zero and then expect that the linear combination of these uh linearly independent vectors is equal to zero so that’s the uh if and only uh if and only uh if part which means that this holds from both sides on one hand we have V1 V2 up to VN which are linearly independent only if the linear equation so the linear combination of all these vectors is equal to zero if all these coefficients are zero but also the other way around holds as well so if we have a linear combination that is equal to zero only if those coefficients are zero that means that we are dealing with a linearly independent vectors this is the if and only if part which means that we have this uh conditions from both sides if one holds the other one holds but also the other way around all right so let’s now look into specific examples that will make our journey in understanding linear dependence much more convenient so let’s say we have our coordinate system and we have these two different vectors so we have Vector let’s say 2 and three which is our Vector a and we have a vector B that is equal to 6 and nine so those two are our vectors and what we want to understand is whether those two vectors are linearly independent or linearly dependent so one thing that you can quickly notice is that b looks quite similar to a in terms of its scales so there is a way that we can recreate Vector B by using Vector a now you can see that if I take Vector a which is equal to 23 if I take Vector a and I multiply it by three so three * Vector a this is a scale multiplication then what I can get is three times and then I have here 2 3 and this is then equal to 3 * 2 is 6 3 * 3 is 9 this gives me 6 and N which is our uh Vector now another thing that you can notice that that is exactly my B so you can see that those two are similar which means that 3 * a is equal to B now what this means is that I can recreate Vector B by using Vector a so in our definition we saw that a set of vectors is linearly independent if no Vector in the set can be written as a linear combination of the others so here I can take this 3A as a way to write down a linear combination so 3 a + 0 * B is then equal to B which is basically saying 3 a is equal to B so so by using these two vectors in a set I can then create a linear combination of the two and actually even basic way of writing this is saying I can use the vector a to write a linear combination from this so 3A is a linear combination so just a scaled multiplication in this case of course but if we have just two vectors our Target Vector is B and I want to write this uh I want to see whether I can rewrite the vector b as a linear combination of the remaining vectors which is Vector a so I can then write Vector b as a linear combination of vector a because I can say that 3 * a is equal to Vector B so this means that Vector a and Vector B they are linearly dependent this means that I can use Vector a to recreate Vector B and of course I can also do the other way around right what I can do is that I can just take Vector B so I can take Vector B I can multiply it by 1 / to three 1 / 3 is real number so I’m just performing a linear combination using B and this will give me 6 / to 3 is 2 9 / to 3 is 3 and I’m getting exactly what I have under a so I can then also rewrite Vector a by using Vector B so I created a linear combination using Vector B in order to get a vector a and that’s exactly the opposite what we have learned here because we should not be able to write this vectors using the other ones in our set because otherwise we have a linearly dependent set therefore we are saying that Vector a and Vector B they are not a set that is linearly independent but they are linearly dependent before moving on to another example I also wanted to visualize the vectors just to see what is going on with this pen and uh how are the two linearly dependent vectors look like in R2 so this is our R2 we have a vector a which has two three elements so we know already the magnitude and the direction this is two this is three which means here let me actually use another color so 2 three which means this is my Vector a and then my Vector B is simply 6 and N so it is this one so you can already see what is going on so this is Vector a and this entire thing is Vector B and you can see that those two vectors no matter how I combine them I can I will always get the combination so linear combination of the two on this line if I want to get um Vector that is for instance in here I can never find a scalers of C1 and C2 in such way that these vectors so A and B they can form a linear combination that will give me this Vector there is no way that I can do that and that’s why uh we say that the span of these two vectors so span of a and b with this A and B is this line and we cannot express any of these other vectors like this one or this one using a linear combination of these vectors A and B the only linear combinations that we can recreate using these vectors A and B are on this line so you can see that even if I have two different vectors I actually just got um single Vector because I have two three and both of these vectors they are actually um uh scaled multiplication of the other one so B is equal to I’m missing here something 1id 3 so B is simply equal to 3 * a and then a is equal to 1/ to 3 * B so in both cases there are simply a version of scaled multiplication of this Vector 2 Tre so a is simply equal to B time 13 and then B is equal to 3 * a and both of them they are actually based on this Vector two a tree on this Vector a so therefore they both actually form and they span around this single line and they are both linear we also call it collinear and they are linearly dependent okay so let’s now move on to the next uh example where we will have bit more interest in case and we will look into this example when we have linear Independence look into another example bit more interesting one as we want to see whether those two are linearly independent or not so the first Vector that we got is the vector a the vector a is equal to 6 and Z so it is this vector this is Vector a the vector B it is this one and it contains element of zero and seven so it is this Vector this is the vector B now in our definition of linearly independent vectors we saw that the idea of linear Independence is that the two vectors can only only be linear independent if we cannot rewrite one of them by using the other so this means that we cannot rewrite a in terms of B and we cannot rewrite B in terms of a so there is no way that we can scale the vector a to get Vector B and there is no way that we can scale Vector B with vect with some uh scaler in order to get D Vector a so there is no way that we can create a linear combination of this one V VOR to get the other one and the other way around so let’s see whether this is the case just from uh trial and error we have a vector a which contains elements 6 and zero for us to go from A to B that has elements from so we need to go from 6 to zero in this case and we need to go from 0 to 7 now we can automatically already from the second element that there is no way that we can go from 0 to 7 you cannot find any scaler C that you can multiply with zero in order to get seven there is no way that you can do that because any number any real number that is a real number if you multiply it with zero it will never become seven and of course another thing that you can notice here also very quickly is the other way around right so here if you go from this zero to six there is no way you can go from this 0 to six because there is no such C that you can take this zero and multiplying it with that so here our scaler and you get this equal to six this is just not possible so what we are seeing here is that there is no way that we can somehow change these vectors so there is no way that we can scale them in such way so this is minus B so all the scales scaled version of this so all the um scaled multiplications of vector B they will always be on this line and then the same holds for a as well so all the scaled multiplications of a will be on this line so then one thing we can quickly see here is that given that those two are perpendicular this pen of A and B is the entire R2 so we can see that by using those two lines we can recreate any other line in this R2 and this is highly related to this idea of linear Independence and given that we cannot come up with a linear combination using the other vectors to recreate the other one in this case given that we cannot recreate a using B and we cannot recreate B using a so no linear combination that exist that we can use to rec create Bay using a and the other way around we are saying that Vector a and Vector B are linearly independent let’s now look into another example that will uh clarify this linear Independence concept so we have three different vectors and the first Vector is Vector vect a 1 0 0 Vector B uh 0 1 0 our second vector and the third Vector 0 0 1 you can notice that we are in R Tre and then the example goes on and it says that those three vectors are linearly independent and as an explanation we have that there is no way to add these vectors together with any scalar multiples to equal the zero Vector unless all scalers are zero now before even going on to next part it’s actually very quickly um uh provable that those three vectors are linearly independent and you cannot create a linear combination of one using the remaining of the two let’s look into this example in more detail so we have three vectors A1 A2 sorry B so we got a B and C which are 1 0 0 0 1 0 and 0 01 now you can quickly see that if we are in R3 and this is actually our unit Vector E1 this is our unit Vector E2 and this is our unit Vector E3 because in that positions we got our ones and the remaining there are all zero and this is actually very similar to the previous example because we can quickly see how we are we will not be able to recreate one vector using the OD on by even looking at the positions of the zeros so for us to recreate Vector a which is equal to 1 0 0 it means that we should be able to find a linear combination C1 C2 and then using these vectors this is the vector B 0 1 0 plus C2 * Vector C which is 0 0 1 so so in here basically we are already seeing a problem because we have here an element one and we somehow need to be able to find C1 and C2 in such a way that 1 is equal to C1 * 0 + C2 times 0 but we know that there is no C1 and C2 that we can find so this uh expression actually is true because C1 and C2 they should be real numbers and there are no real numbers that we can find to multiply with zero such that this will end up to one because this is always equal to zero and we basically get one is equal to zero which is not true and of course the same holds the other way around you can prove that B can never be um recreated by using the linear combination of a and c and also the C can never be recreated by using a linear combination of A and B therefore we are saying given that a can’t be written as linear combination of B and C B can be written so the same only this time A and C and then C hun be written as linear combination of A and B those vectors A B and C they are linearly independent and even stronger you can actually go ahead and prove that this pen of these three vectors is the r Tre but that’s outside of the scope of this example so we will just pass but I will leave that um to you to prove all right so now when we are done with that let’s actually move on to the last module which is the dot product and its applications so uh the length of a vector and Dot product is a concept that um we um are familiar from the high school so the length of a vector is deeply related to this dot product idea the dot product of a vector v WID itself gives this a square of the length of V what basically um it means is that this dot product of vector v so this thing which means take the vector v and multiplying it with the with the other vector v is simply equal to the square of a length of B so this is way to express the length of the uh of the vector v and once we square that that is the dot product so that’s basically this definition what is about about so we know what this definition of the distance is and we Define it by this and then we take the square of that distance and that is our DOT product and we are going to see this idea of dot product a lot especially when it comes to uh matrix multiplication Vector multiplications also in many applications of linear algebra you will see this idea of thatt product coming again uh and coming back to us so uh this is a concept that we really need to understand so in the two Dimension space let’s say we have a vector B which is um consisting of the two elements X and Y then the dot product and the link are related by V by V this is the way we denote the dot product so we just simply use the dot and the name also makes sense because we are saying we are using the dot to perform dot product so we are multiplying to we are creating the product of this Vector with itself and this is equal to x² + Y 2 which is equal to the um square of the distance of this Vector now you might recall from the high schol that we have learned this idea of distance so if we have xaxis y axis then we basically use this uh x² + y sare to uh get the uh you know the formula for from our Circle and then uh we have the x² + y Square we take the square root of it and then this is our distance so once we take the square root of that square of that from this uh square root of x square + y Square then we are simply getting this two cancel out which is equal to x² + y^2 So This is highly related to this idea because we are again talking about distances and we are simply taking the distance since we are squaring them up and then we are getting the dot product so this the double uh straight lines this is just a notation that we use and we spoke about this also before this comes um from the prealgebra and this um this is highly important related to this idea of PAG theorem and how we compute the distances so for instance when we have this uh Square triangular so we have this um uh rectangle here and we have here the 90 uh uh gr so here we have the rate uh right um angle and here we have our C which is uh the side right in front of this uh 90° angle and here we have the A and the B and we say that c² is equal to a sare + b sare and if I were to actually write this in terms of X and Y so if this side is X and this side is y and this is my Z let’s say then z s would be equal to x² + y² and this is something that we can see here too and the two terms are highly related so the Z squ is equal to x² + y s and this is simply equal to Z * Z right and this is something that we know from High School welcome to the module one of this new unit when we are going to talk about about mates as as linear systems so those are all fundamental concepts that you will see time and time again when applying linear algebra not only in mathematics but also in applied sciences like data science artificial intelligence when training different machine learning models and trying to see what is this mathematics behind machine learning models different optimization techniques when you want to solve different problems using linear algebra so in this first module as part of found found ations of linear systems and matrices we are going to introduce this concept of linear systems and then we are going to talk about the general linear systems we are going to uh see this common labeling all the coefficients this idea of indices that refer to the rows and the columns we’re going to see what is this differentiation between homogeneous and nonhomogeneous systems so without further Ado let’s get started so uh the linear systems form the um bedr of linear algebra modeling this area of problems thanks to this advancements in this linear systems and solving it in Computing we can now solve a large amount of problems in a very efficient and a fast way so uh the general linear systems can be represented by this uh set of M equations with n unknowns in the previous unit when we were looking in to this uh linear combination of vectors we saw this notation which was A1 and then we had C1 multiplied or rather let me keep me uh let me keep the same notation so we had this linear combination of vectors so we had beta 1 and then we had A1 Plus beta 2 and then A2 and those are all vectors Plus A3 so beta 3 * A3 dot dot dot and then beta M time a m this is the notation that we saw before and we said we want to come up we wanted to come up with the linear combination of these different vectors A1 A2 A3 up to a m and then we use that in order to get a sense of whether we are dealing with linearly independent variables vectors or larly dependent vectors and then we also commented on the span that these vectors take now when it comes to um the uh vectors and just in general linear systems we can represent what we had before now in terms of with a bigger system so in terms of M equations and with n unknowns so here what you can see here is that we have M different equations so we have beta one B1 B2 up to BM so you can see it in here and then each of these equations it contains n unknowns so you can see that the unknowns it stays the same so the unknowns are those X1 X2 up to xn so X1 X2 up to xn are the set of all n unknowns and then M equations that you can see in here are all this equations so a11 x1+ a12 X2 dot dot dot and then a1n and then xn is equal to B1 and here one thing that is really important to keep in mind is that the indexing is what we need to focus on so we need to keep this one in mind this a i j and this XI so this is something that we also spoke about when uh discussing the linear combination of vectors we slightly uh touched upon on this topic so let’s now dive into this this indexing and how do we index is a i j what are this A’s what are this J’s and here you can see that we have a11 and then a12 and then up to the A1 n and this is in our equation one and then we have in our equation two A1 2 let may actually write this with a different color so in our equation two we got a 21 a 23 up to a 2N and this a that you see here those are just real numbers so so a11 can be 1 a12 can be three A1 n can be 100 and then the same also holds for this B1 for this B2 and for this BM and all these values A’s and B’s they are just real numbers the only unknowns that we got here are those so the X1 X2 up to xn all right so what about the indexing now so we got a i j and as you can see in this case the first thing that we can see here it stays everywhere the same which is the one so we got here one we got here one and up to the point we got here one whereas the second Index this one it does change it grows grad with one and it becomes it goes from 1 to two and up to n so you can see here that the first index first index or index I it goes from one it doesn’t change it’s just one so it is 1 one and one so here in all cases for this equation I is equal to 1 but another thing that you can notice here is that the index two unlike index I so the second index which is the J so you see here that the second index is referred as J this is a general way of defining the indices so here J is equal to 1 2 dot dot dot and then end so basically the I doesn’t change in the same row but the J changes and then of course we have slightly different in terms of I but then the same for J for our second equation so here I is equal to 2 and then J is again equal to one and then two dot dot dot and then n and then here up to for the last equation our I is equal to M and then our J is again equal to one till two dot dot dot so you might notice that I was looking at this from the row perspective so I was saying pair equation or pair Row the I doesn’t change but then the J stays the same and then it is either one two up to n but the set is the same so is it contains all these different elements here so one one two and then n but it contains all these different real numbers going from one till n because we are combining and we are creating this combination the sum of all this values a11 and then X1 a12 X2 A1 n xn and another thing that you can also notice here is that here with the second index so with this J J is equal to 1 then here the x is corresponding index is also one when the J is equal to two then the ex’s corresponding index is also two and then here the same story and you will notice that while the coefficient contains two indices 1 one 1 2 or 1 n which are the two indices for the coefficients for the unknowns we got just single index which goes from one till n so basically for a for the coefficients so I let me write with the right color so I can be one 2 all the way to m whereas in case of J it can be 1 2 all the way to n and the indices are basically used to help us to keep track of in which row we are and what is the um variable that the coefficient belongs to because knowing this second Index this helps us to understand that we are dealing with a coefficient that corresponds to this first unknown the first variable X1 and then the same holds in here as you can see in here and in here we are dealing with the same variable X1 therefore the second index the index J is then the same B both in the first equation and in the second one in both cases it’s equal to one okay so now when we are clear on that let’s also understand this high level concept because you will see this system of linear systems this m equations and N unknowns appearing a lot not only in terms of calculating and finding the solution to this linear system but this actually has a very common application ation when it comes to um running regression linear regression specifically and one thing that you can notice here is that here we got also this B1 B2 up to BM and you will notice that here the index also uh goes from one but then this time to M so when it comes to the rows we have M rows or M equations therefore we also expect when it comes to Counting from the top that at the bottom we will see an M whereas if we count from this side so kind of like imagine it like a column then we see that it goes from one till n so those are common observations and reference to um number of observations and number of uh features that you will see in your data when dealing with data analysis or modeling data so just this uh just keep those things in mind this uh abbrevation of M and then n m equations n unknowns because this will become very handy and the same also holds for this indexing just to keep in mind that this I and this J what those indices are and how for instance the first you know the I the first index changes when we go from up to the bottom and how the second index J goes and changes when we go from left to the right when we go through the columns but we are going to see this also in the uh upcoming slides so uh we can we will have time to practice it so um this is what we are calling a coefficient labeling the coefficient uh a i j so this thing in a linear system they are labeled where the first index represents the row and the second index denotes the column so when we see a i j we know that this refers to the row and the J refers to the column so this is something that we use in order to understand where exactly in our metrix something that we can we will see very soon where exactly our unit or our member that is part of our Matrix where exactly is that located in which row and in which column the systematic labeling is super important because this helps us to keep the structure and this helps us to understand uh what does this uh coefficient represent what what is this row that it belongs and what is the column it belongs so for which equation and for which unknown we have already solved the problem that say so we can know what this uh coefficient represents so before moving on on to the actual linear systems and this definition of matrices let’s quickly understand this distinction between homogeneous and non-homogeneous because this will help us to also get an understanding how we can solve a system of linear systems so a system is homogeneous if all the constant terms b i are zero otherwise it’s non homogeneous use so identifying this helps us to really understand nature of the solution set that we need to get and to understand what kind of strategy we need to use in order to solve this problem now what do I mean by bi we just saw that we had this system of M equations with n unknowns and we saw that that we have in the right hand side this B1 B2 up to BM which means that we had this m different equations with n different unknowns and to find a solution to the system it means finding this values corresponding to X1 X1 here X2 X2 xn so basically finding the set of X1 X2 up to xn that solves this problem and for us to know how to to solve this problem we need to know whether this B1 is equal to Zer or not this B2 is equal to Z or not and then this BM is equal to zero or not this is very similar to this idea of solving any sorts of um problems that contain unknowns for instance if we have three x is equal to let’s say five solving this is entirely different than if we know that the Tre X is equal to zero so this is a super simplified version of course but the idea is the same knowing that this B1 B2 up to BM this R zero this gives us an idea how we can solve this problem and later on we will see this distinction between non homogeneous and homogeneous system and whenever this B so whenever this B1 B2 up to BM whenever these BS are zero then we are saying that the system is homogeneous and we need to solve a homogeneous system otherwise we are dealing with non-homogeneous system so this means that the bis are not all zero let’s now move on to the second module which is about the matrices so we are going to define the Matrix we are going to see the definition of it as well as the notation decide your rows columns Dimensions uh some of which we have already touched upon but we are going to uh go into the depth of it we are going to learn properly as well as we are going to see many examples then we are going to talk about Matrix types so here we will talk about identity Matrix diagonal matrices and also special type of matrices like matrices containing only zeros and only ones so by definition and a matrix is a rectangular array of real numbers there are array Ed in rows and in columns for example an M byn Matrix a can be represented as follows so let’s look into this definition and this reference to Matrix we call this Matrix or Matrix a and every Matrix it can be described by this rows and columns where where we always have this uh way of describing this Matrix always should be defined by the number of rows and number of columns so this is super important and let’s look into this specific Matrix so we have a matrix a and all these values they are members of this Matrix they form The Matrix and we already saw this labeling of a i j where we said that I is referred to the row so you might recall that those were all these equations that we got so this horizontal lines where I was equal to 1 I I was equal to two I was equal to three up to the point of I was equal to M and then we had this J so this thing and then J was referred to the columns and we had J was here one and then two and then three up to the point of n so one 2 3 and N this is exactly what you can see here so in this Matrix we got all these elements a11 is a number a12 is a number up to a1n is a number those are all real numbers and one thing that you can notice here is that here we got a11 so this is our first row and First Column here we got a12 this is our first row and second column and then we got up to the point of a1n actually let me just write this down even at a bigger scale such that I can make more notes so let’s assume we have this Matrix a and this Matrix a if I’m bigger and we got all these different elements so we start with our first row and here we have A1 1 so here the row that I will write with let’s say with blue the row is equal to one and then the column is one so this is Row one this is Row one row one and this is column one let me write it with red this is column one this is column two this is column three dot dot dot and this is column n and this is row two this is Row three dot dot dot and this is row M so in total I got M rows and N columns I will come to this notation that I’m putting here later for now let’s keep track of the rows and the columns to get a good understanding what this indices were about that we just learned so every time I will also mention this reference to a i j to keep track of this and also let me write it with the right colors so a i this is the row and J which is the column so all the elements I’m just defining by this a because it’s just a way to reference a part that comes from a matrix it’s a just common way to write the entire matrix by capital letter A whereas its members will will write with the um with the lower case a so this is Matrix Matrix a all right so here in the second row But First Column we got a 2 and then one because it is still in the First Column and then when it comes to this element we have here a the row is the first one because we are in the first row but then we are in the second column so this one should be two then we go on to the next next element in our first row so a 1 and then three and then dot dot dot and the last element is an a as we are still in the first row it will be one the I but then given we are in the last column the column index or the J will be equal to n because we got in total n in columns so we are now ready to go into the second row so here given that we already have our first element a21 this is in our second row and the First Column so the I is equal to here 2 and G is equal to 1 let’s now write down the element in the second draw a second colum as you might have already guessed I is equal to here 1 I is equal to here two sorry and then uh the J is equal to two and then we go on to the next element which is in the second row and the third column so it’s a the row index is two so I is equal to two and then the column index is three dot dot dot and then we got a as we are in the second row it is the I is = to 2 and as we are in the last column the J is equal to n now you might have already guessed when I was writing this down that whenever you are in the row and you move on to all the elements in the same Row the I so the row index it stays the same only you need to uh update the column index so here for instance you got one one one here also one so all the way down in the same row or one which logically makes sense because we are in the same row so the row index should not change but instead you should change the column index like here column one column two column three all the way to column n so those are our columns dot dotp so let me make this distinction and those are our rows as you can see so this kind of mentally helps us to understand why we are writing all these indices over time once you practice more with this this will become more natural really quickly remove this so now I will write the rest very quickly so as you might have already guessed we are in the third row so we have a Tre so everywhere I will just write down D Ace so First I write down the A and then the rows the row index will stay the same as I in the same row but then I will increase the columns gradually so we are in the column one and then column two column three up to the column n so now the remaining stuff you can actually write down yourself to just practice let’s now move on onto the last row and last column so in the last row we got a a a up to here and in the last row the uh row index is M which means that here I need to have M M M everywhere I need to have M and then the column index is 1 2 3 all the way to n so this last column is very interesting too you can see here that we have the opposite of what we have here because in the last column we see that the uh column index is the same so it is everywhere n Only the first index the index of the row it changes it goes from 1 2 three up to M which is of course logical because we said that in the last column if we are looking it from the perspective of column so all these values this A’s so the all the ends they are logical because they we are in the last column we are in the same column but then the row changes here we are in the row one here we are in the row two Row three of two row M therefore we have also at the end a m n now let’s talk about this idea of MN we said that our Matrix a has M as a number of rows and n as a number of columns which you can see by the way also here so we always refer the dimension of a matrix so the dimension dimension of Matrix a by these two numbers so first we always write down the number of rows in this case M then as the second element we are writing the number of columns in this case n we are always putting this small X in between to kind of emphasize M by n Matrix and we most of the time use the square braces to Showcase that we are dealing with Dimension and in this case we are saying the dimension of Matrix a is equal to M byn so we are dealing with M byn Matrix this is a common convention used in linear algebra and Mathematics General but also used in data science uh in machine learning artificial intelligence so whenever you are dealing with matrices a it is a common convention to talk about this idea of dimensions and the idea of Dimensions is super important when it comes to the idea of multiplication multiplying Vector with Matrix Matrix with Matrix so this dot product Dimensions play a central rle in here so keep this one in mind once we uh get to the point of that products this one will become very handy so let’s now look into a specific example where we see simple Matrix a so in this case you can see that we are dealing with a matrix that has a 2×3 Dimensions so like we just learned 2×3 means that we got two rows and three columns that’s something that you can also see here very quickly so you have a small Matrix on the small matrix it’s really easy to actually count so you can see that we got Row one and row two and we got column one column two and column three so this basically confirms these Dimensions therefore we are also saying that we have a 2 by three Matrix and like usual we first write down the number of rows and then the number of columns you can see here that here we have this elements for our Matrix so a is equal to 1 2 3 for the first row and then 4 five6 for the second row so from this actually I think it’s a good exercise to just uh verify our understanding of indices and from this um we can write down that for instance all these different elements uh like A1 1 is equal to 1 A1 2 which means that we are in the first row and in the second column so we have this element is equal two two and then we got a and then one Tre so we are in the third column so this one is equal to three and then a 21 is equal to 4 a 22 is equal to 5 and then a 23 is equal to six so this is actually a good way to practice our understanding of IND is our understanding of this Matrix structure and the understanding of dimension of the Matrix which in this case is 2×3 so this is yet another different definition of a matrix structure when it comes to the rows comms and dimensions so this is exactly what we I just spoke about on our example and let’s just quickly look at the formal definition so the rows of a matrix are the horizontal lines of the of the entries while the comms are the vertical lines so basically it’s saying those are let me remove this so the rows are the horizontal line and the columns are those vertical lines those are the columns this helps us to form these columns so col one COL two and colum three whereas this horizontal lines it helps us to create the rows so Row one and row two so then we have the dimensions of Matrix are given by the number of rows and columns it has so an M byn Matrix has M rows and N columns that’s something that we already saw so let’s now look into some special type of matrices one Matrix type is the identity Matrix so we saw before we had this Identity or unit Vector now we have identity Matrix so the two are quite similar so like before for when we had our unit vectors we had this for instance E1 in three dimension we had 1 z0 then we had our E2 which had 0 1 0 and then we had our E3 which was 0 01 so you might recall this about our identity vectors or we were calling it unit vectors you might notice very quickly that we have formed an identity Matrix i n which is a square Matrix with one on the diagonal and zeros elsewhere is basically a matrix that is built using those unit vectors so here we have E1 here we have E2 and here we have E3 so you can also see that this 3×3 Matrix because we got three rows and three columns so you can see that here we have on the diagonal so we call this diagonal on this diagonal we have all ones and in here outside of the diagonal they are all zeros and this is the definition of identity Matrix it is this i n Matrix where n is the dimension of a matrix and given that it’s a square Matrix it means that the dimension of it is n by n so all the rows so the number of rows is equal to the number of columns on the diagonal we have all this ones and everywhere else we got zeros and do note that we are forming this identity Matrix simply by combining these different uh unit vectors so like here E1 E2 and E3 so let me actually uh give you yet another example but of much higher Dimension so of this identity Matrix so let’s say we have I and then this I uh let us actually use this notation i n so let’s say we got i n what this means is that we got actually this large matrix it’s a square Matrix which means that it is n by n so it has n as the number of rows and n as number of columns so the dimension is n by n you got n as number of columns too because it’s a square and let us actually write down that how that Matrix looks like it’s a large Matrix matx the N is the size of that Matrix so here we got on the diagonal we got one here we got one here we got one dot dot dot up to the last point one and the index of this one here so this is the first row this the First Column basically and everything else is simply zero so here we got zero 0 0 dot dot dot Z here we got 0 0 all the way down to zero here also Z all the way down to zero and then here also zero so everywhere here and here we all got zeros only on this diagonal we actually got once so basically by using our common notation we can say that in the DI in the identity Matrix we got A1 1 = to a 22 = to a33 equal to all the way to a NN equal to 1 and then when it comes down to the rest of the cases so all the other observations let’s say a 21 a 31 or a 41 anything so anything that is not um a11 or a22 anything that is not on the diagonal it is simply equal to zero we also say in those cases that a i j is equal to 1 if I is equal to to J because then it means that we are talking about item that is on diagonal because both the row index is equal to the column index otherwise the a i j is equal to Zer if I is not equal to J so this is in the nutshell how a large identity Matrix in general can be defined so let’s now move on to another type of Matrix which is the diagonal matrix so by definition a diagonal matrix is a matrix where all of diagonal elements are zero so what does this mean we just saw um example of a diagonal matrix which was our identity Matrix because identity Matrix is an example of a diagonal matrix and what do I mean by that that in our just seen example we saw that only on the diagonal we had all these nonzero elements but the rest were all zeros so all the of diagonal elements were zeros like in here and in here exactly the same holds for the diagonal matrices only unlike in the identity Matrix we no longer need to have this diagonal elements equal to one those can be any other numbers so as long as we have this um elements D1 D2 D3 that are not zeros but then off the diagonal numbers so all these elements they are zero then we are dealing with the diagonal matrix so in this case we got a 3X3 diagonal matrix because we have uh three rows and three columns and here we can see that the um the first so the a11 the first element from the first draw First Column is equal to D1 so a 22 is equal to D2 and then a33 is equal to D3 so D1 D2 and D3 those are all so D1 D2 and D Tre those are all real numbers now when it comes to the uh this numbers for example it can be that D is let’s say two 2 5 6 on diagonal then we have those zeros this is a diagonal matrix it can also be that D is equal to minus 3 and then 0 0 and then 5 8 and then here we have zeros so again we have on the diagonal all these elements and the off diagonal elements so if all the off diagonal elements are zero then we are dealing with diagonal matrix and if you are wondering well what happens if only the diagonal we got zeros do we still have a diagonal matrix it’s actually a great question but yes indeed we are dealing with diagonal matrix as long as all the off diagonal elements are zero so for instance if we got D is equal to here we have zero here we have 0 0 0 and and then 7 and then 0 and then 8 and then 0 0 so we got this off diagonal elements so here are the diagonal elements and all the off diagonal elements are those given that all the of diagonal elements are zero which is the definition of the diagonal matrix then we can say that our D Matrix in here is indeed a diagonal matrix let’s now look into yet another type of Matrix which is a special type of Matrix and it’s called one Matrix so by definition a one’s Matrix is denoted by 1 M1 so you can see here and here it mentions the dimension of it so the number of rows and number of columns and it’s a matrix in which all the elements are one so this is a very unique Matrix we often use it during the programming so in data science data analytics but also in um uh when creating like data structures when designing algorithms this becomes very handy and this idea of one’s Matrix is that all the elements are just one it means that if we want to create a placeholder in such way that we can then multiply any number in here with some other number and get that number then it can be done very easily because we know that when we multiply y a number with one then we get that number so a * 1 is = a x * 1 is = to X now this is exactly this property exactly is what motivates us to create and to have this type of ones matrices it means that we are defining matrix by its Dimension so it is M by n and here the m is equal to 2 and then n is equal to three because we got two rows and three columns but you can see that all the elements are the same and they are equal to one so a11 is equal to a 1 2 is equal to a 1 3 is equal to a uh 21 and is equal to a 22 and a 23 and they are all equal to one and this is the definition of one’s Matrix you can have um On’s Matrix of the size 4 by 10 one mat Matrix of the size thousand let’s say 10,000 by 100 Etc so any number any real number so M and then n are real numbers you can use in order to create this large M by n1’s matrix let’s now look into our final special type of Matrix before moving on onto the next module which is about zero matrices so similar to this one’s Matrix a zero Matrix denoted by 0 m by N is a matrix in which all the elements are the same with the one difference that this time all the elements are equal to zero so in the once Matrix all the elements were ones but in the zero Matrix all the elements are zero this type of matrices become very handy also during the programming creating um different algorithms during design in coding um but for slightly different purposes usually we create the zero matrices as a placeholder such that in the beginning we can have this uh tuples or we can have this um uh arrays or nested Loops um that we want to perform and then gradually add these values to the existing Mt array so if we create this zero Matrix and um this is a placeholder then next time we can always add on this this new data that we get and then we know that zero plus a number is always equal to number which means that once we have this updated information of a we can add this to the zero and we will then have this new updated information in our system therefore the zero Matrix is often used as a way to uh have this placeholder with the provided Dimension where we can always add new information and the information can be updated so in this specific case we got um a zero Matrix that has two rows and three columns so you can see two rows and three columns so m is equal to two and then n is equal to three three perfect so we are done with module two and now we are ready to go on to our next module which is the core Matrix operations so when when it comes to matrices we often perform Matrix additions metrix subtraction but also Matrix um a scalar multiplication of this Matrix so multiplying Matrix with a scalar and then Matrix um multiplication just in general so taking two matrices and multiplying them we are going to look into this concept in detail we are going to see many examples like before we are going to dive deeper into this such that we lay the ground on uh two to the next module which is solving a system of M equations with n unknown so solving this General U linear system so for the beginning uh we will be looking into this Matrix operations where we are adding or subtracting matrices so by definition the sum of two matrices A and B of the same dimensions is obtained by adding their corresponding elements so by taking the element i j from both matrices and adding them to each other so in this case you can see that Matrix A and B are here and uh the uh definition says we just simply need to take the corresponding elements corresponding elements from the row I and the column J take them add them and this will become an element in our final um Matrix because when we are adding two matrices of the same size the result is yet another Matrix so we will use the Matrix a to add to Matrix B and this will give us a matrix A + B and this IJ simply refers to the indices corresponding to the row and the column we will look into an example in a bit and this will make much more sense and the same holds also for the difference so by definition the difference of the two matrices A and B of the same dimensions is obtained by subtracting their corresponding Elements which means that in order to obtain this Matrix a minus B this is a new Matrix we simply need to look for each element so we are going to index them for a row I and J we are going to do this pairwise element wise subtractions we are going to see what is that element corresponding to the row I and column G in The Matrix a which we say is a i j we are going to subtract from this the element in the row I and column G that comes from Matrix B and this will give us our new Matrix which is a minus B so let’s now look into an example in this Matrix Matrix um uh a and Matrix B are used and Matrix a is of the size 3×3 Matrix 3 Matrix B is of the size 3 by 3 in order to obtain a + b what we are doing is that we are performing element wise additions now let’s verify this so what we are doing here is that we are saying a plus b let me actually get a larger area here so let’s say we have the two matrices I want to add the two in such way that we everything one by one such that this idea of a plus b and addition of the matrices will make sense so we want to find out a plus b for that what we are going to do is that we are going to make use of this definition that A + B and then I J is equal to a i j + b i which is a fancy way or mathematical way or describing that for each element we need to go and look for the row I and column J and take that element from the um column from that uh Matrix a and from The Matrix B so this means that for a plus b this is going to be a matrix that will have the same number of rows and the same number of columns as two matrices because both A and B are 3×3 which means also their sum is going to be 3×3 so this going to be 3×3 and here we are going to do so we are going to take for the first row and the First Column so for a plus b 1 one so first row and First Column we need to go to the first row and First Column of Matrix a and the first row and First Column of Matrix B and we need to add these two elements so we need to do 1 + 1 and then we need to go on to the second column so the first row and the second column which means that we need to be here in both matrices so here we have 0 + 2 and then we got 2 + 3 and then we got 0 + 0 so you can see it in here and then we have 1 + 0 and then we have 3 + 1 0 + 1 and and then 0 + 2 and then 1 + 3 which gives us so 1 + 1 is = to 2 0 + 2 is = to 2 and then 2 + 3 is = 5 0 + 0 is = 0 0 + 1 is = to 1 1 + 0 is = to 1 0 + 2 is = 2 and then 3 + 1 is = 4 1 + 3 is = 4 which means that our A + B is equal to this Matrix that we got in here so you can see that we are getting exactly what we uh what we have here only we have done it manually one by one so the same idea holds exactly when we have a minus B only instead of adding you will have to do here minuses so minus minus so everywhere minus so 1 – 1 0 – 2 2 – 3 Etc so let’s look into another addition so in this case by definition it is defined as this element wise uh of the adding of the two matrices here the only difference in this definition is that it’s saying it’s calling this a plus b as C so this new Matrix that we are getting as a result of adding a to B it’s calling C so basically it’s the same calling this Matrix a c you will see also this type of definitions so in this case The Matrix C is equal to a plus b which basically means that for each row with index I and with each column with index J go and look for row I and index J take the corresponding elements from Matrix a and Matrix B add them in order to get that corresponding element in our new Matrix C and you can see that in this example there’s EXA exactly what we are doing we have a we have B we are taking this element and this one so 1 + 1 we are getting here two and then 0 + 2 we are getting two here 2 + 3 is 5 and then 0 + 0 is equal to 0 1 + 0 is = to 1 and then 3 + 1 is equal to 4 so now we already go to the next topic which is about scaler multiplication of a matrix so by definition scalar multiplication of a matrix a by scalar Alpha results in new Matrix where each entry of a is multiplied by Alpha the idea of scal multiplication matrices is actually quite similar to this idea of scale multiplication in vectors so uh we have already seen in the lecture of the vector multiplication that when we were having the scaler C and we had this Vector a then uh when we are multiplying C which is a real number with Vector a then we simply need to take all the elements of vector a so A1 A2 all the way down to a n and we need to multiply them by this same scaler so see this is what we were doing with vectors and that’s exactly the idea behind matrices and when uh doing the scalar multiplication of matrices only instead of multiplying in only just one vector with the scaler C now we need to apply this to all the rows and all the comms so here we got this one column and Matrix is simply a combination of multiple vectors which means that we need to multiply all these elements of all the vectors of all the columns in this Matrix so let’s actually look into specific example so in this case we have a matrix a and and this Matrix a is this thing and we have a scaler which is three so in here our Alpha is equal to three or you can quote C or anything so you can see that when we are scaling The Matrix with a scaler in this case Tre with this Matrix what we are doing is that we are simply taking each of these elements and multiplying it with the scaler so 1 by 3 is 3 2x 3 is 6 3x is 9 and 4x 3 is 12 this is the idea behind this entire scale multiplication of a matrix in more general terms if we for instance have a matrix a so let’s actually look into a high level General example when we have a DA Matrix M by n so we got M rows and N columns and we want to get a skelet multiplication of this Matrix and um scalar that we have here as in our definition it is defined by this alpha alpha is just a number you can go C you can go B anything so in this case our scalar alpha alpha is coming from R so it’s a real number so Alpha time a is then simply equal to to this new Matrix where all of these elements are simply multiplied by this scum so I will just take over all these values H1 up to a M1 and then A1 2 a 22 all the way down to a M2 and then let me also add the last column just for fun here a 2 N and then here a m and so here this new scaled M multiplies so scaled uh Matrix a so Alpha * a is simply equal to Alpha time all these elements are simply multiplied by this scale it is as simple as that so that’s the simple idea behind uh metrix uh scaling so when you are doing scalar multiplication of this Matrix you simply take all the values and you multiply them element by element perir row and per column by that single scaler Alpha do note that you are multiplying them all without exclusion with exactly the same number which is that Alpha so let’s all look into the definition of matrix multiplication so here we are no longer multiplying a matrix with a scalar but we are multiplying Matrix with a matrix so the product of an M by n Matrix a and an N by P Matrix B results in an M by P Matrix C where each entry cig is computed as the dotproduct of the each Road of a and the Jade column of B now what does this mean firstly let’s look and unpack this part of the definition so we got Matrix a that is M by n and then we got Matrix B which is n by P what this means is that in this case Matrix a has M rows and N columns and Matrix B has n rows and P cups so this is then simply the dimension dimensions of the two matrices so then it’s saying that by definition the product of these two matrices so the product of A and B the product of the two B is equal to toce Matrix C and each entry c i j so c i j is computed as the dotproduct of the each row of a and the Jade column of B now this part might seem bit difficult but once we look into the actual example and we illustrate this on our common high level General expressions of Matrix a b and their multiplication this will make much more sense for now before coming to this one I just wanted to refresh our memory on one thing I said before when discussing also this idea of improving uh this uh different properties of vectors that when we want to multiply a vector with a matrix or Matrix with Matrix or vector with a vector we need to ensure that from the first element the number of columns is equal to the number of rows of the second element this is also very important for this specific case and just in general for matrix multiplication so you can notice here that the number of comms here is equal to the number of rows in here and the order is very important so in case of matrix multiplication the order is really important which means that if you have a matrix a and you want to multiply it with the Matrix B then the number of columns of a should be equal to the number of rows of B otherwise you cannot multiply those two matrices with each other so in case you got a matrix a that doesn’t have the same number of columns as the rows of number of the Matrix B then there are some alternative things that you can do including this idea of the transpose that we saw also doing when Computing the dot product between this Vector a and Vector B that’s something that we also do in programming when we are dealing with this Matrix and we want to compute this relationship between two matrices but the number of columns of one of the first one is not equal to the number of rows of the second one we are simply uh manipulating this matrices or removing some data if that’s not hurting our problem maybe uh flipping so transposing our Matrix or applying any other source of operation to it to ensure that the two matrixes that we are multiplying with each other the first one’s number of columns is equal to the second and once’s number of rows so that’s just the low and that’s something that you should follow if you want to multiply these two matrices all right so now let’s move on onto this idea of multiplying and Dot product let’s look into a specific example and this will um help us to understand this process better so before doing that I just want to quickly show you this general idea so if we have a matrix a that is M by n which means that it looks something like this like A1 1 a 21 up to the point of a M1 and then here we got let’s say a one 2 a 22 up to the point of a M2 and then at the end we got a MN and here we got A1 n so let me also add this one 2 N and we got a matrix B this Matrix B is n by P so it has n rows and P columns so we are fine in terms of Dimension here and we got here b11 B21 up to the point of b m sorry BN in this case let’s not confuse the letters so B N1 B1 2 B 22 up to the point of b n 2 because n now is the number of rows for Matrix B unlike for the Matrix a up to b 1 p and here b 2 p and here after to the point of B and then n p this is the last element in order to perform a multiplication between these two matrices so to obtain a matrix C which is equal to a * B what we need to do is we simply need to take pair case so pair Row for the row I for instance we need to take this element so this row and we need to multiply it with this so we need to find a dot product between this row and this column then we need to move on on to the next one and then for the second element we will then take this row and we will multiply it with this one so this is then something that we need to do in order to obtain these elements and you might have already noticed that we got this m by n and n by P so you might have already guessed what will be the dimension of the C if we got that the dimension of a is equal to M by n and the dimension of B is equal 2 and by P then the results Matrix after M multiplying the two of Matrix c will be will be having a number of rows equal to this and the number of col equal to this so This middle part basically disappears and the number of rows of the first Matrix will be then the number of rows of this result Matrix C and the number of columns of the second Matrix so Matrix B will then be our final number of comms so we will then have a matrix C that will have a dimension so Dimension so dimension of C will then be equal to M by P so we will have M rows and P columns so how we are going to compute this so for c i j which means row I and column J let’s look into the definition of it it’s saying c i J is computed as a dotproduct of the each row and the J column so each row from A and J column of B what is the each Road of a the each Road of a is somewhere here so each Road of a it is uh the A and then I one then a and then I2 and then a and then I3 dot dot dot and then a i and then we got in total n columns n and we always do the transpose right when Computing this um dot product so we then take the transpose so we take this row row I and we multiply it so we do the dot product between this one this this is the a i and the B J this is column J it is somewhere here so it is B and then we got the first element which is one and then J and then B 2J B 3j dot dot dot up to B and then in total we got n rows in B so n and then the J is the column so it stays the same so this is then the dot product between e row that comes from Matrix a and the J column that comes from Matrix P so it’s always like that actually so we always take row by row so we take this different so every time we take just a row and we multiply with the corresponding column and then we get the dot product between this row that comes from the first Matrix and then the column that comes from the second Matrix in that specific order in order to get our DOT product and that specific volume and what is this amount actually so when we calculate this dot product you can quickly see that we have a i1 * by B1 J plus a I2 * b 2 J and then dot dot dot a i n multiplied by b n g and this new Matrix c will then have all this so C11 C 21 and then c31 dot dot dot and then C the last row as the number of rows of C is m c m c here M so C and then here it will be 1 2 C 22 C3 and then two up to the point of cm and then two and then here the last coln will be C1 and then p is the number of coms in C so C1 p and then C 2 p and then C3 P dot dot dot and then c m and then P okay so this is what we get this is our final Matrix C when multiplying Matrix a and Matrix B so let me clean this up c is now if you want to find out what is C11 you can easily fill in this general formula that uh that we just calculated the I is equal to 1 and then J is equal to 1 and this will give you C11 by using this formula if you want to get the CM P then just fill in the I is equal to M and then J is equal to P in order to get this value CNP so you can already see the amount of calculations you need to do in order to get all these elements from these large matrices A and B let’s actually look into a simple example to clarify this so we have a matrix a here and Matrix B here and we want to do a multiplication of the two and we have just learned how to do it let’s actually do it one by one so we got a matrix a which is equal to 1 1 2 3 4 with Dimensions 2 by 2 then we got a matrix B which has values two Z and then one 2 so it is 2x two and I want to find what is c that is equal to a * B and I know already by looking at these Dimensions that c is going to be equal to 2 by 2 so you might recall that I said that when looking look at this final result the number of rows or the final um Matrix will be this so the number of rows of the initial Matrix a and then the number of columns of this final Vector c will be the number of vectors number of colums of this second Matrix B so two therefore I know already before even doing calculations that the uh product Matrix c equal to a * B is going to have a dimension 2x two let actually do a calculation to check this so C is then equal to a * B and it’s equal to 1 2 3 4 multiplied by 2 0 1 2 okay so I expect to have four different elements here here here and here so to obtain the C11 so it is C11 in here what I need to do is that I need to look at the first row and the first column in here so first row from a and the First Column of B and I’m doing the dotproduct which means 1 * 2 + 2 * 1 1 * 2 is 2 2 * 1 is 1 so here I’m getting 1 * 2 + 2 * 1 we which basically gives me 2 + 2 and that’s equal to 4 so here I’m just writing down 1 * 2 + 2 * 1 now when I want to get this value which is C12 this means that I want to get the first row and the second column and that’s exactly what I’m doing so I’m going back and I’m saying let’s look at the first row but this time we will look at the second column coming from the uh from The Matrix B so 1 * 0 * 0 + 2 * 2 and then I do the same only this time for the second row which means I’m picking this row and then this column so it is 3 * 2 + 4 * 1 and for the final element c22 I’m taking the second row and the second column which gives me three * 0 plus 4 * 2 now what does this gives me this gives me this 4×4 Matrix where 1 * 2 + 2 * 1 is 4 1 * 0 + 2 * 2 is 4 3 * 2 + 4 is = to 6 + 4 which is 10 and then 3 * 0 + 4 * 2 is = to 8 so let’s check 4 4 108 that’s exactly what we have here so as you could see here the idea is that every time to follow what element I’m looking for for the CJ and then I just go to the E rows from the first Matrix and the J’s column from the second Matrix and I do the dot product of the A and then I and then K let’s say so I’m going to the E Row from the first Matrix and I’m taking all the elements which means I don’t even need to mention this index it just means the entire each row coming from the Matrix a and then I’m doing the dot product between this row and the column that comes from the Matrix B which means B and then J which then will give me the cig so I’m looking at this and taking this multiplying this do product and this gives me the first element then the first row and then the second column which gives me the uh second element in the first row in my Matrix so this one and so on so hope this makes sense uh if it doesn’t make sure to reach out because it’s a very important concept and uh let’s also look into another example to make sure that we got this right so in this case as you can see we have another matrices so set of A and B matrices again 2x two a simple one and we want to know what is a so let’s say we call this C we already know C should be 2x 2 and what we are doing is basically for C11 we are saying let’s look at the first row so first row and the First Column coming from the second Matrix B and let’s do the dot product so 2 * 1 2 * 1 2 * 1 4 * 5 4 * 5 we get this and then when we want to find what is C oh what is C and then one two so in the first row but in the second element in our final Matrix so I is equal to 1 and J is equal to 2 it means we need to look at the first row from The Matrix a but this time the second column from from The Matrix B so it is 2x 3 2x 3 4 * 7 4 * 7 and this gives us a number 34 even if you calculate you can see that 2 * 1 is equal to 2 4 * 5 is 5 so 2 4 * 5 is 20 so 2 + 20 is 22 in here and then you can do the rest of calculations and this will be a good practice to see how we can do a basic matrix multiplication the idea is actually quite straight forward when it comes to multiplying it it just it comes with a practice when we see all this uh much bigger matrices so um this is another example I will leave this one to you to complete it just uh to keep in mind we always do uh so we always look at the dimension first in here 2 * 2 and 2 * 2 which gives me an impression already what I can expect the result will be 2 by two and when it comes to the uh cross elements just ensure to always look to the eth row and the jth column this comes from Matrix a and this comes from Matrix B take them compute the dotproduct and then you will find your C uh your final result let’s call it um kig J because in this case we have a matrix C already welcome to the module 4 of this course when we are talking about matrices and linear systems so in this module we are going to dive deeper into this uh idea of linear systems with matrices and solving linear systems using different techniques and specifically we are going to learn the uh concept behind solving linear systems using matrices named gausian elimination and gausian reduction welcome to the module one in this unit so in this uh case we are going to talk about algebraic lows for matrices we are going to disc discuss four different properties for matrices uh and the first one is the cumulative low for Matrix addition the associative low for matrices the distributive low for matrices both the left and the right one and then finally we’re going to talk about the scalar multiplication low for matrices so the algebraic laws for matrices they are like in case of real numbers like in case of vectors they help us to do different operations on these entities they are very similar to the real numbers and the vector cases where we for instance um so that if for instance A+ B uh is equal to B + C or a * um b + C is equal to a + a c those are uh all sorts of lows that we uh learn as part of high school pre-algebra and we have applied it to real numbers we know how helpful those can be and similar type of lows we have also for the matrices and we got in this case four different lows that we will be discussing the first one is what we are referring as associative low the second one is the distributive low the SEC the third one is the scalar multiplication low and the fourth one is the communative law for addition so these laws help us to do different metrix operations they help us to manipulate algebraically this metries and then uh this can help us to solve different sorts of problems including solving a system of linear equations so let’s start with the commutative low for Matrix addition so the Matrix addition is commutative um which means that a plus b is equal to B plus a so unlike the matrix multiplication that we have seen in the previous lessons uh where theorder did matter and we said that we um had to uh ensure that the number of columns of the first Matrix is equal to the number of rows of the second matx Matrix in case of addition that’s this is not the case so we should not care about the order whenever we want to add two matrices the other thing that we need to keep in mind though is that the two matrices needs to have the same size so I mean that both Matrix a and Matrix B need to have a dimension so dimension of Matrix a should be equal to dimension of Matrix B and let’s say should be equal to and M by n but for the rest we don’t really need to care uh which one we will put first will we put first a and then add the b or we will do the other way around so we will then First Take B and then we will add a so this is the idea behind commutative low for Matrix addition so first let’s look into all this uh lows and then we will also look into the corresponding examples so for this specific case it might actually also be helpful to write down the general formula which will um make sense out of this um low for the uh uh which is a communative low for the metrix additions so let’s say we got a matrix a which is M by n and this Matrix can be represented as a11 dot dot dot and a M1 so this is something that we saw time and time again so I’ll just quickly write it down the common notation for this and then here we have the last column which is a MN and this is the Matrix a then we got Matrix B which is again M by n and can be represented as b11 and then dot dot dot and then B M1 dot dot dot b 1 n dot dot dot b MN so the cumulative law says that A + B should be equal to B + a let’s check that whether this is the case let’s first compute this part and then we will do this one well the first one means that we get so A + B is and we remember how we add matrices right so we know that we just need to pick their corresponding elements and add them to each other so we get a11 plus b11 then dot dot dot and then a M1 Plus B M1 this is why also the it’s really important that they got um the same Dimension which means that they got exactly the same amount of elements or the same uh amount of columns and the same amount of rows um in terms of the uh Matrix size so then here we have a 1 n and then plus B1 n then dot dot dot and then a M1 and then plus b m here I need to put n we are in the last element of the Matrix so BMN and that is it this is our Matrix A + B let’s now look into the Matrix B+ a so what that amount is so The Matrix b + a will then be equal to b11 + A1 1 dot dot dot and then B M1 plus a M1 then dot dot dot and then b1n Plus A1 n then dot dot dot and then the last element will be B MN and then plus a MN so in here if we remember from the real numbers we know that A+ B is equal to b + a for instance if a is equal to 2 and then B is equal to 1 then a + b is = to 2 + 1 which is equal to 3 and then b + 1 is = to 1 + 2 and it’s equal to three so we know that indeed for the real numbers a + b is equal to B + a and making use of that property we can already state that B1 1 + a11 is equal to a11 + b11 and then the general case is that a i j plus b i j is equal to b i j plus a i j where I is the index of the rows and then J is the index of the columns from the coefficient labeling so using this property from the real numbers given that all these values in The Matrix are real numbers we can quickly see that the Matrix B+ a that we just got in here is equal to this Matrix a plus b which means that 1 is equal to B and this proves that a plus + B is equal to B + a this is the commutative property of the Matrix additions so the next law is the associative law for matrices which says that the in case of Matrix addition a plus b + C is equal to a + b + C so basically this time we go from here to adding one more element which is the third Matrix Matrix C so we are saying a plus b plus C is equal to a + B+ C so it doesn’t matter whether we will First Take The Matrix a and then B and then add them up and then we add Matrix C or if we first take the Matrix B and C add them up and then we add a to this sum it doesn’t matter we will see an example of this in a bit and then the uh second part of this associative law for matrices says that for matrix multiplication a * B * C is equal to a * B * C so again in terms of the um order when it comes to this specific multiplication so it doesn’t matter whether we will first multiply a by B and then by C or we will first multiply B by C and then we add the a at the end we will end up with the same amount so a * B and then * C is equal to B * C and then in the left hand side we add the a so a * B * C so this properties help us to add or multiply matrices without really worrying about this idea of grouping of the terms so we can always group them and perform all sorts of operations so this is this first property that we see in here let’s say we have this uh Matrix a matrix B and Matrix C so let’s prove that indeed the order doesn’t matter and dis associative property holes so let’s prove that so for that the first thing we need to do is to compute a plus b so this part so a plus b plus c what is that first I need to compute this part and then I will add C which is the second part so A + B is equal to my a is equal to 1 2 3 4 plus and my B is equal to 56 78 this is then equal to so 1 + 5 is equal to 6 2 + 6 is equal to 8 3 + 7 is equal to 10 and then 4 + 8 is equal to 12 this is my A + B this is the first part now the second part is then to add to this A + B this C this I can by the way also call some Matrix D so I can say that this is equal to D + C so let’s find out what is this amount so A+ b or what we’re referring as D is 6 8 10 12 we just calculated it in here I’m also adding now my Matrix C which is 911 10 12 so 9 10 11 12 what is this amount it is 6 + 9 is 15 8 + 10 is 18 10 + 11 is 21 12 + 12 is 24 this is my final Matrix so I have checked that D A + B + C is equal to 15 18 20 1 and 24 this is the first part let’s now go ahead and check whether this is equal to the second part which is this part so this is one this is two so this is then A + B + C as you can see it in here let’s now calculate that amount and like previously we will do it in an order so first we need to calculate this part and then the entire thing so B+ C is then equal to the B was 5 6 78 5 6 78 plus and the C was 9 10 11 12 9 10 11 12 what is the S much 5 + 9 is 14 6 + 10 is 16 7 + 11 is 18 and 8 + 12 is 20 this is the first amount let’s refer refer this as a d or we can even call it by some other letter let’s say k this is Matrix K so B plus C is k then the second part is to take this B+ C so B plus C which we have referred as K say K and then we are adding to this the A and specifically just to ensure that we stay with the same order I’m saying I will add from the left side the a to this Matrix K and this obviously means this is equal to so A + B + C this is what I’m referring by just uh in a more simpler notation I’m just using K in here so this is my B plus C or what I’m referring also as a k and this amount is equal to what is my a my a is 1 2 3 4 1 2 3 4 plus and what is B plus C we just calculated that that’s the K so 14 16 18 20 so 1 + 14 is 15 2 + 16 is 18 3 + 18 is 21 4 + 20 is 24 so we have learned that the a + B+ C is this vector now is this Vector equal to the A + B and then plus C well here we got this 15 18 21 24 15 18 21 24 so we have just proved that the first part is equal to second part which means that we have proved that indeed the order doesn’t matter and a plus b + C is equal to a + b + C so this calculation confirms that the both sides of this equations they are indeed equal and this confirms the associative low for the Matrix addition so let’s now look into the distributive law for matrices which says that Matrix addition and multiplication they satisfy the distributive property which means that if we have a left distribution a * b + C is equal to a + a and then in the right distribution we basically have the Matrix multiplying from the right from hence the name right distribution A + B * C is equal to a C + B C you might very quickly see and recognize from here that we have very similar actually exactly uh the same rule only for real numbers we know that a * b + C is equal to and then we open the parenthesis we say this is equal to this times this so AB plus this times this a c you can see that we have exactly the same here only in the capital letters so in the real numbers we have exactly the same low so the same we have also for our left distribution when it comes to Matrix additional multiplication and the same we have only with a different order here you can see the C so this one is basically uh with the different order instead of having the Matrix multiplied in the left here we have from the right and this is similar to the property that A + B * C is equal to C * a which is a c plus c * B which is b c to an example uh where we will prove that the distrib ative law for matrices um is indeed true and I have skipped deliberately the uh example for this one because uh this a b * C is equal to a * b c so the associative low for matrix multiplication it’s something that you can calculate for yourself using the same a b and c matrices only this includes multiplication of the two matrices and it’s something that we are going to to do as part of this example so instead of doing and redoing this multiplication I thought that it’s great to leave that for you as a practice and instead focus on bit more complex problem like this one that one way or the other includes the same matrix multiplication so I need to calculate the a * B in this case which means that by providing you this example I’m also including what is needed to do the previous example example only it would be a great way to practice the material for yourself so let’s now move into proving the distributive law for matrices so we got this matrices a b and c and here I’m going to apply matrix multiplication the same as that is needed for the previous uh case and here what we need to prove is that a * b + C is equal to AB * AC so this is the first part this is the second part so let’s go and calculate them separately so for the first one we need to calculate a * b + C which is then something that we can calculate by first doing the addition so we will first do the addition of matrices B and C and then once we are down with that we will then do a * b + C so that’s the second part so let’s go ahead and do that calculation so first we got B+ C what is B plus C B is 5678 5678 plus and the C is min-1 0 0 minus one so on the diagonal we got min-1 and minus one and then of diagonal lower and upper parts we got zero and what is this Matrix this is equal to 5 – 1 so 5 + – one is = to 4 6 + 0 is = 6 7 + 0 is = 7 and then 8 – 1 is = 7 this is our B plus C which we can refer also as Matrix D so let’s call this D which means that now we are interested in a * D so for this second part we need to take this Matrix a so a * D is then equal to we need to take the Matrix a which is 1 2 3 4 and we need to multiply it with this Matrix that we just got because this is the B plus C or the D that we were referring 4 6 77 okay so let me remove this part cuz we are going to need some space for this and let’s do this calculation this is 2x two and this is 2 by two I will do the calculations in here so we need to end up with the Matrix that is also 2x 2 because we know 2x 2 Matrix time 2x 2 we will pick this part so the number of rows and the number of columns of the second one this will be our resulting Matrix which is 2 by two all right so for the matrix multiplication we know that for the this element in the place of so one a or let’s call this Matrix we don’t even actually need to call this anything we can keep it simple so let’s say that we are in the first draw in the First Column so this is the first draw in the First Column for this what we need to do is we need to take the first row from the first Matrix so Matrix a and then the First Column of the Matrix D so this one and we need to do the dot product which means that we do basically 1 * 4 1 * 4+ 2 * 7 so for this element which is in the second row and the First Column we need to take the second row and First Column in here so we end up with 3 * 4 so 3 * 4 and then 4 * 7 so plus 4 * 7 The Dot product between this one and then this one so for this element which is in the first row and then second column of the final Matrix so first row and second column we need to pick the first row and second column and do a DOT product which means one 1 * 6 + 2 * 7 2 * 7 and then in here in this element we got the second column and second row so second row second column which means that we need to pick the second row and the second colum the dotproduct of the second show of Matrix a and the second column of Matrix D which is 3 * 6 + 4 * 7 4 * 7 so let’s quickly calculate what this amount is so this is the a * b + C basically and this Matrix is 1 + 4 is 4 2 * 7 is 14 4 + 14 is 18 1 * 6 is 6 2 * 7 is 14 and 6 + 14 is 20 3 * 4 is 12 4 * 7 is 28 which means that we got here 40 3 * 6 is 18 4 * 7 is 28 which means we got here 36 and 46 this is our final a * B+ C let’s now go ahead and calculate the second part so the second part says that we got a * b + a * C so a * b + a * C which means that first we need to do this calculation and then this one and then we need to add them to each other so let’s quickly then calculate what is a * B and then a * C and then add them to each other let me clean up some space in here we’re going to knit that then we write this one in a smaller format so this is equal to 18 20 40 and 46 and let me take over the second element which we still need to calculate which is a plus a c first we will do this and then this and then we will add them to each other so a * B is equal to 1 2 3 4 multiplied by 5 6 78 5 6 7 8 now follow following the same approach from the previous example when we calculate this Matrix I will then quickly calculate what is this a * B so in here we got first row and First Column so 1 * 5 + 2 * 7 so the dot product between the first row and the First Column from here now for this element here we got the second row and the First Column we need to take the second row Row in the First Column from here and we do the dot product which means 3 * 5 + 4 * 7 in here we got the first draw and second column so the first draw and second column which means that we need to have 1 * 6 + 2 * 8 then here we got the second row and then second column which means 3 * 6 + 4 * 8 and then this is equal to 1 * 5 is 5 2 * 7 is 14 so this is 19 1 * 6 is 6 2 * 8 is 16 6 + 16 is 22 in here 3 * 5 is 15 4 * 7 is 28 8 so this is then 33 and then 43 so 43 and in here we got 3 * 6 6 is 18 4 * 8 is 32 so we end up with 50 so hope I haven’t made any mistakes in the calculations so this is a * B so a * B is then equal to 1922 4350 let’s clean this piece and let’s move ahead to the second part of the calculation which is a Time C what is a * C well a * C is 1 2 3 4 1 2 3 4 multiplied by -1 0 0 -1 so here we are then getting -1 + 0 here we are getting – 3 + 0 here we have -1 + 0 so no so the first row and second column which is 0 – 2 and then in here we got the second row and the second column which is 0 – 4 which means that we end up with this Matrix and it’s equal to -1 – 3 then Min – 2 and then -4 which means that we are getting as a final step AB plus a which means 19 20 20 43 and then 50 then plus -1 – 2 – 3 – 4 and what is this 19 – 1 is 18 43 – 3 is 40 22 – 2 is 20 50 – 4 is 46 okay so we got that this amount AB + a is equal to 18 20 40 46 and as you can see already here this Matrix that we got in the previous calculation from one is equal to this Matrix that we got as part of second calculation which means that now we have proved that for this specific example indeed 1 is equal to 2 which means that a * b + C is equal to ab+ a there we go so let’s now look into another low which is the the scalar multiplication law for matrices so the scalar multiplication law for matrices says that if we got a scaler R and a matrix A and B then R * a * B is equal to R * a * B and is equal to a * R * B so here the r is just a scaler so it’s a number and then A and B are matrices and what this low basically says is that it doesn’t matter what in which stage you will do your matrix multiplication with the scaler if you have this external scalar you can first take the two matrices multiply them with each other so the A and then B and then multiply it with r or you can take the scalar R multiply with your first Matrix and then multiply with b or you can take your second Matrix multiply with the scaler and then multiply with a it doesn’t matter they will all result in the same Matrix so let us actually prove this by making use of our skills from matrix multiplication and scalar multiplication here I have picked up bit more uh Advanced example where uh a is 2 by3 and B is 3×3 in this way we will train our multiplication skills for matrices and at the same time we will also prove that the scalar multiplication law of matrices holds so let’s go ahead and do the multiplications so first we have a matrix a what is that Matrix Matrix a is 1 – one 2 so 1 – 1 and then 2 then we got 0 2 and then 1 which is 2 by 3 and then we got B which is equal to it is 3x 3 with elements 1 Z 1 1 2 0 one one and then 3 1 0 2 so it is 3 by 4 so it’s 3x 4 not 3x three but 3×4 Matrix now the final part that I need here is this which is R is equal to 2 the scalar value so R is equal to 2 so the first thing that I’m going to do is to calculate this amount which is R * a * B for that what I need to do is to First calculate this a * B so let me quickly go and calculate this for us e so given that the a has Dimension 2×3 and then B has a dimension 3×4 I can see that quickly that my Dimension criteria is satisfied the number of columns of a is equal to number of rows of B so that’s fine and then I know also know that the final dimension of a * B is going to be 2×4 so it’s going to be a 2×4 Matrix and how do I know that well because I I know that from our um all this problems that we have solved we have already seen that we always need to pick the number of rows of the First Column and the number of columns of the second uh Matrix in order to get the final Dimension which is 2×4 so let me then go ahead and do the calculation so we’re going to have a 2×4 Matrix let me write it even bigger so it’s going to be a 2×4 Matrix so for the first row and First Column I need to look in here the first row and the First Column which means I need to take one so it’s equal to 1 * 1 so plus 1 * 1 is 1 -1 * 2 is – 2 2 * 3 is 6 + 6 this is my first value and what is this amount it is equal to 1 – 3 – 1 1 and 6 – 1 is equal to 5 so this amount is five five so what is this amount well this is my second row and the First Column so I need to make use of second row and First Column which is equal to 0 * 1 is 0 2 * 2 is 4 and 1 * 3 is 3 4 + 3 is 7 so this value is seven we are ready to go on to the next column so column number two so then this time I need to look at the first row and second column so we are going to use this one so first we will use this first Row 1 * 0 is 0 – 1 * 0 is 0 0 + 0 is 0 and then 2 * 1 is the only non-zero element 2 * 1 is 2 so I already know that for my second column I got here two and what is this element well for this I need to look at the second row and second column so this thing so 0 * 0 is 0 2 * 0 is 0 1 * 1 is 1 which means that here I get a one let’s now move on to on uh towards the third column so in here first I need to look at the first row so 1 – one and two and then this time remove this I need to look at the third column because I’m here in the third column so 1 * 1 is 1 – 1 * 1 is 1 so here I got 1 – 1 and then 2 * 0 is 0 + 0 1 – 1 + 0 is 0 because those two cancel out this means that here in this element I got a zero and what about this this element where I need to look here in the second row and here I need to look at the third column 0 * 1 is 0 2 * 1 is 2 1 * 0 is 0 so 0 + 2 + 0 is equal to 2 so this is 2 and now we are left with the fourth column so for that I need to look in here so for the first row which means first row in here and then the fourth column here so first row in here and four column here 1 * 1 is 1 – 1 * 1 is 1 and then 2 * 2 is four which means that I end up with 1 minus one and then + 4 and what is this this two cancel out I end up with four which means that here I need to fill in four and what is this final element it is the second row in the fourth column so the second row in the fourth column 0 * 1 is 0 2 2 * 1 is 2 1 * 2 is 2 0 + 2 + 2 is = 4 so now we obtained that a * B is this 2 * 4 Matrix as we have expected so this is then equal to 5 2 04 and then 7 1 2 4 so then the next step would be to take the scaler R and multipied with a * B let me actually keep the colors consistent so a * B this is a * B so the only thing that I need to do is to take that in here and multiply this two with each of those elements so I will end up with the same size Matrix so 2x 4 only all these elements need to be multiplied with the scaler which means that I will get 5 * 2 is 10 2 * 2 is 4 0 * 2 is 0 4 * 2 is 8 and then 7 * 2 is 14 1 * 2 is 2 2 * 2 is 4 and then 4 * 2 is 8 so this is the result of the multiplication so this is the first part this is what we are referring as one so we have then checked in here that the r times actually we have already in here so I won’t be writing again so as part of the first section we have already seen that R * a * B is this Matrix let’s now move on to the next one which is calculating the second part so this is the first part this is the second and this is the third we have this already let’s now move on and calculate this one so for the second case so the second case what we want to calculate is R * a * B so it is R * a and then * B this is what we need to calculate so the first thing that we will do is to calculate this part and then to calculate the entire thing the second point so let’s go ahead and do that first we will take the A and then we will multiply all its elements by scaler two to get the R and then a this amount is equal 2 1 * 2 is = 2 – 1 * 2 is – 2 2 * 2 is = 4 0 * 2 is = 0 2 * 2 is = 4 2 * 1 is = to 2 this is R * a now in The Next Step so this was one the next step we need to take this amount this Matrix 2 – 2 4 04 2 and multiply it with 1 2 3 0 0 1 and then 1 1 0 and then 1 1 2 so basically the Matrix B let’s now move and work our way out with that one actually let me remove this from here and keep the space bit more clean R time a and I will be multiplying this with the Matrix 1 2 3 and then 0 0 1 and then 1 one 1 1 and then 0 2 well I know that this one is 2×3 and this one is 3x 4 which means that the result will be 2x 4 let’s now go ahead and calculate the Matrix which is equal with a dimension of 2x 4 well for the first row and First Column let me actually go and quickly do those calculations let’s now go ahead and do those calculations so we are going to have four columns as previously the dimension is going to be 2×4 so let’s do it column by column in here it means that we are in the row one and then column one so 2 * 1 is equal to 2 – 2 * 2 is -4 and then here we got 4 so 4 * 3 is 12 so we got 2 – 4 and then + 12 and what is this amount 2 – 4 is – 2 + 12 is 10 so here here we got 10 me remove this 10 this is the second row and the First Column which means we got 0 * 1 is 0 4 * 2 is 8 and 2 * 3 is 6 so 8 + 6 is equal to 14 so here we got 14 this is the first row and second column which means that we are looking at this row and second column this time so 2 * 0 is 0 – 2 * 0 is 0 the only thing that we care about is this one and this element which is 4 * 1 so this should be four let’s now do the same for the second row 0 * 0 is 0 4 * 0 is 0 0 + 0 is 0 which means we are left with 2 * 1 so here it comes two let’s Now do the third column so for the third column we got First Row 2 * 2 2 * 1 is 2 – 2 * 1 is – 2 and then 4 * 0 is 0 which means that here we get 0 because 2 – 2 + 0 is Z then we got the second row and third coln which is this row and then third column so 0 * 1 is 0 4 * 1 1 is 4 2 * 0 is 0 0 + 4 + 0 is 4 so this is four and then for the first row and then fourth column so it means that we need to look at this specific column the first row is 2 * 1 it is 2 – 2 * 1 is – 2 and then 4 * 2 is 8 so 2 – 2 + 8 is 8 and then finally for the second TR in the fourth column 0 * 1 is 0 4 * 1 is 4 2 * 2 is 4 4 + 4 is8 this is the final Matrix which means that this entire amount that we just calculated step by step this is equal to this Matrix in here okay so this is the second element let’s check whether the first element is equal to the first one so we see here 104 08 142 248 as you can see we are dealing with exactly the same Matrix which proves that indeed r * a * B is equal to R * a * B so this part we have already proven because we have seen that 1 is equal to two perfect so the only thing that is remaining is to calculate this third part and to see whether this is equal to this matrices because we have seen that the two of those are equal so the remaining thing that is left to prove this theorem is to calculate this third part let’s go ahead and do that so the third element says let’s first calculate the r * B and then multiply it by a so we need to calculate b r * B * a this is what we need to calculate which means first we need to calculate this and then we need to calculate the entire thing all right so let’s go ahead and do that so R * B is equal to so we need to multiply each of the elements of B by two so we end up with this Matrix 2 0 2 2 and then 2 * 2 is 4 2 * 0 is 0 and then 2 2 and then 2 * 3 is 6 2 * 1 is 2 2 * 0 is 0 2 * 2 is 4 this is that first Matrix let’s now go ahead and calculate the second part which is a * Matrix a so it is 1 – 1 2 and then 0 2 and then 1 multiplied by this Matrix which is 2 4 6 0 02 and then 2 2 0 and then 2 2 4 okay perfect so this is then what we need to calculate well this is 3 * 4 this is 2 * 3 which means the result should be 2 * 4 let’s go ahead and do those calculations this first amount will be the first row and the First Column dotproduct of those which means 1 * 2 is 2 – 1 * 4 is 4 – 4 and then 2 * 6 is 12 so here we got 2 – 4 + 12 and what is this amount well 2 – 4 is – 2 12 – 2 is = to 10 so this one this element is 10 then for the second show we need to look in here so 0 2 1 and the dotproduct of the one we the First Column so this thing and that is 0 * 2 is 0 2 * 4 is 8 and then 1 * 6 is 6 so what is 8 + 6 that is 14 and then for the first row and then the second column we need to look to the first row in here and then the second column in here and the DOT product of the two well 1 * 0 is 0 – 1 * 0 is 0 and then 2 * 2 is 4 so that’s what we are left with for and then for the second row and then the second column so this element we got 0 * 0 is 0 2 * 0 is 0 1 * 2 is 2 for the first row and the third column so we need to look in here 1 * 2 is 2 – 1 * 2 is – 2 and then 2 * 0 is 0 so we are left with zero 0 and then once we do the calculation for the second row we will see that we end up with 0 * 2 is 0 2 * 2 is 4 and then 1 * 0 is 0 so we end up with 4 and then here for the final column 1 * 2 is 2 -1 * 2 is – 2 and then 2 * 4 is 8 the first two cancel out and we end up with 8 and then for the second row and the fourth column we look into here again this time the second row 0 * 2 is 0 2 * 2 is 4 and 1 * 4 is 4 and then 4 + 4 is eight so if we look in here this is our third amount we will quickly see that again we have the same Matrix with exactly the same elements so now we have also proved this third part and we have seen that in all cases the r * a * B is equal to R * a * B is equal to a * R * B now we are ready to move on towards the second module in this unit which is about the determinants and their properties we are going to look into the uh determinants at high level we are going to Define them and going to understand why they matter and why they are important then we are going to see how we can calculate the determinants we are going to see the calculation for 2x two Matrix then 3×3 Matrix and then just in general how we can do it and then we are going to see the properties of determinants one by one and then finally we are going to see the determinant interpretation from the geometric perspective so when we visualize it using python so by definition the determinant is a scalar value that can be computed from the elements of a square Matrix so this important Square Matrix and encodes certain properties of the Matrix so the determinant provides a critical information about The Matrix such as whether it’s invertible and the volume scaling factor for the linear transformation it represents so we see that the uh concept of determinant is highly related to many other concept that we have seen before so first here it’s talking about the square Matrix then it’s talking about encoding certain properties so having the determinant it contains certain information that um is related to the properties of the system that that Matrix is is representing and then it provides critical information about the underlying Matrix because the determinant is calculated from a matrix we say the determinant of a matrix so it contains a critical information about that Matrix such as whether it’s invertible or not and this goes back to the concept of inverse we will see this once we learn the concept of determinant because the inverse calculation is dependent on the determinant but keep this thing in mind that the determinant contains information whether we can get um inverse from a matrix or not we will see this concept also in detail in the next section but for now we can remember that the determinant contains important information related to the invertibility of the Matrix so having an inverse or not and then it also contains information about the volume scaling factor for the linear transformation it represents so here we then go back to this concept of a x is equal to B and then knowing the determinant we can then comment on this volume scaling factor for this linear transformation that it represents so let’s go uh on to the next slide to find out bit more about the determinants and specifically how we can calculate the determinant in the mathematical terms when it comes to the 2x two Matrix because the uh determinant of a 2X two Matrix is quite straightforward so for 2x two Matrix a with this elements where a b c and d they are all real numbers the determinant which we Define by this de a so that is a short way of saying determinant and then in here we always write the Matrix of which we are Computing the determinant is then equal to and then we are taking this a * D so we are taking this diagonal elements a * D so they are on the diagonal and then we are subtracting from this this altitud remaining two elements of the diagonal so B * C and this gives us the determinant of a 2×2 matrix this is just a formula that you need to uh remember whenever you want to calculate the determinant of a matrix by hand manually so the calculation for larger matrices it involves bit more uh difficult uh calculation we will see also in a bit the uh determinant of a 3X3 Matrix It relies on the determinant of a 2×2 matrix and the idea is that every time we uh increase the dimension of our problem so let’s say we are in R4 then we will go back to the R3 and then given that R3 relies on the determinant of the underlying 2x two matrices anytime we increase the dimension we again go back to this idea of using 2x two matrices that form the entire Matrix in order to compute the determinant only when it this R4 R5 Etc so it becomes much more difficult to describe and to do it manually therefore there are other algorithms which we will see at the end of this course like uh the composition algorithms and factorization algorithm items that can be used in order to calculate the determinant of a matrix that has higher Dimension higher than the tree for instance but in this specific unit we are going to discuss both the calculation of the 2x two matrices determinant and the determinant of a 3X3 matrices and we will also see detailed examples of them so without further Ado let’s then go ahead and calculate the determinant of this 2×2 matrix so let’s now look into this specific example where we are calculating the determinant of this 2×2 matrix so this is the A and let’s keep in mind that this is the um uh a this is the uh B in this not in this uh way of writing the Matrix a so the uh letters corresponding of the uh elements of this Matrix a so this is the a this is the B and then this is the C this is the D and we said that the determinant that of a is equal to the diagonal elements so one * 4 minus the of diagonal Elements which is 2x 3 because we said that the definition of this determinant is that it’s equal to a * D and then minus B * C which is exactly what we are doing in here so if we calculate 1 * 4 is = to 4 and then 2 * 3 is = to 6 4 – 6 is equal to -2 therefore we say that the determinant of Matrix a is equal to Min – 2 let’s now go ahead and uh practice with calculation of determinants on two other matrices so in this case we are still in the two dimensional space so we have 2X two matrices we’ll first calculate the determinant for Matrix a so we see that we got this element 506 one and we know that by definition the determinant of the 2×2 matrix so that of Matrix is equal to a * d – B * C where the Matrix has the following form so we got a and then D in here and then B and the C in here so we see that this is basically our a this is our D this is our B and this is our C the way you can also see it is that those are the diagonal elements and those are the of diagonal elements so therefore it means that we can calculate the determinant of Matrix a by taking the 5 multiplying with one so it is 5 * 1 minus the of diagonal element which is 6 * 0 and this amount is equal to 5 – 0 and is equal to 5 let’s go ahead and also calculate the determinant of Matrix B we see here that on the diagonal we have this two elements one one and of the diagonal elements are both zero those two therefore we can calculate the determinant of this 2×2 matrix which is also sometimes referred as I2 so it is the identity Matrix because we got here the E1 and then E2 in the two dimensional space and the determinant of of the Matrix B using this definition is then equal to 1 * 1 – 0 * 0 so 1 * 1 – 0 * 0 and this is equal to one and this is actually a special case of determinant and later on we will see why it is so important to uh have this relationship of identity Matrix having a determinant and having it equal to one um and this relationship between determinant identity Matrix is something that we see also uh in the upcoming lesson so keep this one in mind so now when we are clear on how we can calculate the determinant for 2x two Matrix so this is quite simple and straightforward calculation by taking the diagonal elements a and then D and then subtracting from that from that product a * C we are subtracting the of diagonal elements products B * C we can then get our determinant and now when we are clear on that we are ready to go on to bit more advanced calculations which is calculating the determinant this time for the 3X3 Matrix so now we increase the um the dimension size and we go from R2 to R3 because now we have a 3X3 Matrix and by definition given a 3X3 Matrix a which has the following elements so a11 a21 a31 and then a12 a22 a32 so we have already seen this coefficient labeling this should look very familiar this is 3×3 Matrix 2 and the determinant of a matrix a denoted as that a is calculated using the formula and here we see the formula we are basically using the 2x two matrices that form this Matrix a in order to calculate the determinant of the 3X3 Matrix and how we are doing that well we are using this element and then this element and this element and every time we are hiding part of the Matrix so when we have for instance this a11 so for this first part we are saying well let’s hide the row and the column corresponding to this element which means that we need to hide this this uh row and this column and what is left is this 2x two Matrix we will calculate the determinant of this 2×2 matrix and we will multiply this with this element that we use in order to remove the corresponding row and column this will form the first element in here so you can see a11 which is a simple value so this this the um uh entry volume which is in the first draw and First Column a11 multiplied by the determinant of this Matrix so this Matrix so once we have that and we already know how we can calculate a determinant of a 2X two Matrix because this 2x two so taking the diagonal elements and then multiplying them together subtracting from that the of diagonal elements product now we are ready to go on to the next part of the calculation which is this time adding a minus here so you can see here this here is plus and then here is minus so we do here minus and for this second step what we need to do is kind of similar only this time the element that we will be using to understand how we can remove the row and the column so we will then dark it out it is this one a12 so then we will need to remove this column and this row and then the remaining Matrix which is this one this 2x two and here I mean a 21 a 31 and then a 23 and then a 33 this is the Matrix that you can see here remaining which means remove this one and then this one and then the remaining 2 by two Matrix is what you need to use in order to do your calculations so you can see that I got exactly the same in here and once again we are Computing the determinant of this Matrix we are multiplying this with this a12 element so this element and now we have also the second element in our calculation and then we go on to the next step which is a plus sign here let me use the same colors plus sign here and then we are using this time our final third element to understand which row and which column we need to dark out which is this element so we then remove the first row and the last column and this is then the Matrix the 2x two Matrix that we use in order to do our calculations so deter the determinant of this Matrix multiplied by the a13 so we could also use in the same manner this row or this row it really depends on the kind of values the the tip that um I will provide to you or the trick is that to always look for the Zer Zer values wherever I see Z zeros or I see one one I’m thinking that hey those same u values that um give me the most straightforward and easy calculations because if I have zeros in my C in my entry so if I got a zero here for instance 0 * any determinant is zero I don’t even then need to calculate the determinant right because then I know that I’m multiplying that determinant with zero therefore if I know that that entry for instance this row contains the majority uh of zero so it is 0 0 one then of course it’s a great uh row to pick to use this target elements so in that way I will then know that this is the row that I need to Target but if it is like that that for inance since I got a matrix 10 3 4 and here I got 0 1 0 and here I have 100 3 and 4 of course the easiest thing would be to not use this row but instead use this one so in that case I will then have this zero and zero as my target values which means that I will only need to calculate the determinant of a 2 x two Matrix this uh for this one for the two cases I don’t need to do because I know that the corresponding Target values the target elements from my Matrix will be zero so let me show you what I mean by that so if for instance I go for this second row and not the first one what I need to do is that I can calculate the determinant of a by taking the a21 this then will be my target I will then need to remove move this uh column and this row then I will need to do the determinant of A1 2 A1 3 a 3 2 a33 this is what then I need to do then the next thing I need to do is of course here I have a plus here I need to do minus because we always need to Interchange the values so here is a plus here is a minus here is a plus so I do PL a minus in here then I do the next element in my row which is this one let me use red color so a22 so I’m then doing a 22 multiply the determinant of so I’m re removing this row and this column a11 a13 and then a31 a33 and then the final part is of course as you might have already guessed is to look into this element so it is plus a 23 multiplied the determinant of let me actually write it down in here the determinant of a11 A1 2 and then a31 and then a32 so in this way basically independent of what row I will take as my leading row that I will do my calculations and I will just need to pick one row I can always get the same value for determinant of a but choosing intelligently which row to pick it will save you a lot of time and headache in terms of calculations because if you are dealing with a row that contains many zeros for instance you have 0 0 1 or 1 0 0 or even better 0 0 Z then you know automatically that you will need to calculate your DET the determinant once here also once and here you don’t even need to calculate it you know that you got zero here Z here Zer here so it’s automatically equal to zero so I hope this makes sense because this is a trick that usually you will not come across but this just helps you to save a lot of time uh when comes your calculation of your determinants in a 3X3 settings so in this case uh we have this um we now we have this definition and we know the tricks that we can use but I think it’s really uh helpful to go ahead and to solve a problem so basically this is the higher level summary of the steps that we just discussed um so the determinant of a 3X3 Matrix it simply involves multiplying the A1 1 by the determinant of the 2×2 matrix that that remains after excluding the row and column of a11 so what we did in here by doing this and subtracting the product of A1 2 and the determinant of its respective 2 two Matrix so this part and then adding the product of a13 and the determinant of its respective 2x two Matrix so this part and this signs alternate so it means first you always got the plus then you always get the minus and then the plus so they interchange you start with plus then you do the minus and then the plus so let’s go ahead and calculate the determinant of this Matrix so before even looking at the answer let’s actually go ahead and do that on this paper so we got a matrix a which is equal to 1 2 3 4 so basically from 1 till 9 1 2 3 4 6 4 5 6 and then 7 8 9 and for this 3×3 Matrix we need to calculate the determinant so the determinant of a the first thing that I’m seeing is that there are no rows with zeros or columns which means that I cannot use my uh trick and instead I will just need to go with let’s say the first R and it’s also convenient given that I got as scaler this values this much smaller values relatively to the other ones all right so first things first let’s go ahead and write down that formula so the determinant of a is equal to first we are going to take this one so our one one times and then we got determinant of and then we have this Matrix which is 5 6 8 and 9 this is our remaining Matrix then the next thing we need to do is to Interchange the size uh the the sign which is minus and then we got so the remaining Matrix is then determinant of 4 6 7 9 and then finally plus three times and then determinant of what do we have well this is the target so it is 4 5 7 8 right so let’s go and do those calculations quickly this is equal to 1 * the determinant of this is the diagonal element so 5 * it is 5 * 9 – 8 * 6 – 2 * 4 * 6 – 7 * 6 Sorry 4 * 9 so the diagonal elements 4 * 9 – 7 * 6 and + 3 * and then 4 * 8 – 5 * 7 this is equal to so 9 * 5 is = to 45 8 * 6 is = to 48 then- 2 * 4 * 9 is 36 7 * 6 is = 49 7 * 6 is = 42 + 3 * 4 * 8 is = 32 – 5 * 7 is = 35 so this is = to 1 * – 3 – 2 * and then here we got 36 – 42 so that’s – 6 + 3 * – 3 which is that equal to – 3 + 12 – 9 which is equal to Z so let’s check it indeed we got the right answer perfect so now when we are clear on how we can do this calculation let’s now go ahead and calculate yet another determinant of a 3X3 Matrix and this time I want to show you this uh simplified version by you making use of this trick that I uh specified so instead of using this first dra as an indicator I will be using the uh second row as my indicator one thing to keep in mind when making use of this trick is that when you start from the second row so from the even rows even rows second fourth or sixth then in those cas PES you need to flip the signs that you will be using so while in here you had the Sign Plus in the beginning then you got a minus and then a plus when doing all these calculations so you remember here we got plus minus plus when you start from the second row instead of first one you need to flip the order of this so you need to start with minus you have minus you got plus and then minus so knowing this trick it also means that you go One Step Beyond and you know how you need to intelligently uh reduce the time that you are spending on calculation uh calculation of the determinant but it also means that you need to be careful on knowing what kind of science you need to use because if you start from the first or you start with plus and then you do minus plus minus plus so knowing how to start you already already know how you can go on but when it comes to the second row so the even rows you need to start with the minus so you need to do minus plus minus plus dot dot dot all right so let’s now go ahead and use that technique in here so here I see that my first row doesn’t contain zeros but my second row does so this gives me indication that I can reduce the time that I spend on calculating the determinant at least one time because I didn’t no longer need to calculate that determinant so the determinant of B is then equals 2 I will then start with minus given that I’m going to use this rope and then I have 0er * so because this is my element the determinant the determinant of 2306 and then Plus then this time the second element Target element is this one so it’s four times and then we got determinant of 1 3 1 6 and then minus D 5 * so this five determinant of 1 2 1 Z and what is this amount it is equal to this I don’t need to calculate because I got a zero in here this this trick is all about this to not calculate the determinant too often and then this equal to four times 4 * determinant of this is 6 – 3 so 1 * 6 – 1 * 3 which is equal to 3 and then minus 5 * determinant of 1 2 1 0 which is 0 – 2 so this equal to 4 * 3 12 – 5 * – 2 which is equal to 12 + 10 and is equal to 22 let’s go ahead and check this and this is the more detailed and formal derivation so one uh interesting thing is that I calculated with my second row and in here in this slide you can see calculation with the first draw this is just a nice way of seeing the difference that you can do in here uh in this solution what we have is that we have manually calculated this first determinant to so in total three determinants but we again end up with the same determinant so independent what kind of row you will use in order to calculate your uh determinant of Matrix B you will all always end up with the um with the same similar volume unless you have made a mistaking your calculations so you just need to keep track of the uh rows that contain many zeros and you need to um be careful in terms of the signs that you need to use and the sign that you will need to start if you start with the first row then start with plus if you start with the second row then it is minus and then plus Etc so as you can see here it’s a plus and then minus and then Plus in my case I did with my second row therefore I started with minus all right so let’s now move on to the properties of determinance so the determinant of an identity Matrix is one that’s something that we have also seen when doing our calculations because we uh saw that in one specific case when we had this example so this Matrix B and the Matrix B was the identity 2 in two dimensional space we have calculated its determinant and we saw that it’s equal to one and this was not a coincidence because the determinant of identity matrices is always equal to one then the second property is that swapping two rows or Columns of a matrix changes the sign of its determinant so if you swap rows or columns in your Matrix so if you end up with Matrix A and B they are exactly the same only one swaps the two columns or two rows then you are changing the determinant of that Matrix uh the sign of that determinant but not devalue itself it means that if you got a and you got B and your a is equal to let’s say uh A1 and then B uh A2 and then A3 so it contains these columns and then Matrix B is equal to um let’s say A2 and then A1 A3 then and the determinant determinant of a will be equal to minus of the determinant of B you can also say determinant of B will then be equal to the minus determinant of a this is basically the idea of this property let’s now move on to the third property which says that if a matrix has a row or a column of Zer its determinant is zero so if you got a matrix a that contains these different values a11 H1 dot dot dot a n uh M1 and then here you got suddenly um column that contains all zeros and then the rest are nonzero even so in that case you know that your determinant is is equal to Z so for a specific example if you got for instance Matrix 1 0 2 0 0 3 13 then the determinant of this Matrix is equal to zero and otherwise if you got a matrix B that has a column of zeros so come that is entirely of zeros so let’s say here we have 1 one one and we have a a zero Vector here so we got in here 0 0 0 and then 3 4 five then given that we have here this zero Vector then the determinant of Matrix B is equal to zero and this actually straightforward to be seen from this calculations that we saw because if you do the uh if you pick this specific row and then you do 0o times determinant of the remaining Matrix 0 times determinant of the other Matrix and then plus so plus and then so minus and then plus and then minus 0 * determinant of the third Matrix it is obvious that 0 * a determinant is0 0 * determinant is 0 0 * determin is zero which means that you got a whole bunch of zeros to be added to each other or subtracted from each other this means that if you have a row or a column with zeros this already gives you an idea that your determinant is equal to zero you don’t even need to do calculations so the final property of determinants is that if a determinant of a product of matrices equals the product of their determinants so the determinant determinant of a b is equal to determinant of a multip by determinant of B this is basically what this property is about so let’s quickly go through examples to ensure that we are at the same page with all these properties and we can prove them so let’s say we have an identity Matrix n by n which is we are dealing with i n now according to this first propert T when we calculate the determinant of this Matrix so the determinant of i n is equal to 1 Let’s actually look at a specific example so here we got um identity um Matrix in the two dimensional space in the R2 and we can quickly calculate the determinant of this I2 and we can see that it is equal to this diagonal element so 1 by 1 minus 0 * U it’s actually something that we did as part of my uh previous examples so this equal to 1 – 0 and is equal to 1 one thing that I wanted to show you before moving on to the next example about the swapping rows is that when we are swapping some of the rows or some of the columns or two rows or two columns of Matrix a we are referring to this matrix by this notation so we add this not in here and we say that this is basically the manipulated version of Matrix a so if we have for instance Matrix a equals you a b and and c and those are vectors and then we are swapping two of the columns let’s say we are swapping this two we get B and then a and then C then this Matrix we are referring as a not this is just a matter of notation and we just learned it as part of the properties that the determinant of this new Matrix is equal to minus the determinant of a so if a matrix a has a row or column of zeros then the determinant of it is zero so let’s actually quickly look at this specific example in here we got a which is uh having a column of zeros and another column of B and D where B and D are real numbers so let’s prove that his determinant is actually equal to zero so the determinant of a 2X two Matrix we have already SE is equal to the diagonal elements so 0 * D minus the of diagonal elements which is 0 * B 0 * B and what is number * 0 is equal to 0 0us 0 * B is also 0 it’s equal to 0 therefore the determinant of a is equal to 0 so when it comes to the uh determinant of a product of matrices let’s prove that the determinant of a * B is equal to the determinant of a Time the determinant of B so therefore the first thing we need to do is to calculate this a * B let’s quickly go ahead and do that so let me add here this um blank file so a is equal to 1 2 3 3 and 4 B is equal to 5 6 78 and I want to prove that the determinant of a b is equal to determinant of a * determinant of B first I will be calculating this and then I will be calculating this so for the first one what I need to do is that first I need to calculate d a * B which is equal to 1 2 3 4times 5 6 7 8 and then this is equal 2 should be 2 by two so first I take this 1 * 5 is 5 2 * 7 is 14 14 + 5 is 19 then for this one I need to pick this row so 3 * 5 is 15 and then 4 * 7 is 28 so 15 + 28 is so there we have 33 43 so I got here 43 then I’m going on to the next column which is in this case 1 * 6 is 6 6 + 16 is 22 and now the second column 3 * 6 is 18 4 * 8 is 32 and this gives me 50 all right so now I have the 800 B then as the next step what I need to do is to calculate the determinant of this a * B which is equal to the determinant of this Matrix 19 22 43 50 that I just calculated and what is this amount the diagonal elements 19 * 50 – 43 * 22 19 * 50 is then equal to 950 and 43 * 22 is 946 which means that we end up with four this means that the determinant of the a * B is equal to 4 let’s quickly check what are the parts of the second amount so for that I need to calculate determinant of a which is equal to 1 * 4 – 2 * 3 1 * 4 is 4 3 * 2 is 6 so 4 – 6 is = – 2 determinant of B is equal to 5 * 8 which is equal to 40 and then 7 * 6 is equal to 42 and this is equal to Min – 2 and determinant of a times determinant of B is equal to – 2 * – 2 which is equal to 4 so we can see that now we just proved that the determinant of a * B is equal to 4 so we have seen that determinant of ab is equal to 4 and we see that that’s exactly the same as determinant a * determinant of B which is equal to four so we have just proven that the this equation indeed holes so the determinants they are not just um some calculations or some amounts but they are actually uh important concept and their interpretation um is highly relevant from geometric perspective so determinant have a geometric interpretation and the for example determinant of a 2X two uh Matrix or 3×3 Matrix they represent the area in case of 2x two or the volume in case of 3×3 Matrix uh of the parallelogram that they are forming so uh this is often referred as uh parallel uh piped um I hope I’m pronouncing this correctly and it’s formed by the con vectors of the Matrix so if we have for instance this uh Matrix a and then we have a b and then C and D we have this A and C which is the first vector and then B and D which is the second vector and the uh the two vectors they actually form a parallelogram um when it comes to the uh two dimensional space and the area that this uh parallelogram uh is forming that is equal to the determinant of this MRI so the determinant of this scalar value that summarizes this linear transformation that we describe by this Matrix because we saw that we had this a x is equal to B linear system that we were describing using this coefficient Matrix and this was our unknowns this was our variable and then this B was the um amount that we were uh putting this as equal to if B was equal to zero then we were solving the homogeneous system otherwise we had this non-homogeneous system and in the geometric terms the determinant of this Matrix a so the determinant of a um in case of 2x two space so in R2 um when we got two vectors basically in our Matrix a this is equal to the area that is spent by these vectors in the two dimensions space in a bit I will also show you specific example such that um we will be on the same page when it comes to this concept of parallelogram the determinant and those vectors that form the column um uh space of the uh Matrix a uh when it comes to the three dimensional space when we have R3 so we got 3×3 Matrix of a then the determinant of this Matrix a is it’s the volume that is um formed by these uh threedimensional vectors because unlike the two in R TR we got the three vectors that form the a let’s say this one this one and then this one and then here we can create this area covered by these three vectors and the area that is formed by these three vectors from a it is equal to the determinant of that Matrix a so in terms of the 3D it’s bit harder to uh visualize it but in uh case of the two-dimensional space I think this will help uh to improve our understanding of the determinants and make this interpretation uh from geometry uh from geometrical perspective so given the two vectors A and B in the two dimensional space the determinant of this Matrix uh is then equal to the um diagonal elements we already know minus the of diagonal elements right so we are also saying we have seen this notation already very often you will see this volume this is the absolute we already know this from high school this is the absolute volume because the determinant can also be a negative number we have seen – 20 or minus 2 and we know that the area cannot be a NE negative number therefore we are adding this absolute term here so knowing for example that we have this Matrix a which consists of the elements 3 2 and then 1 4 we know that the determinant of this a is equal to 3 * 4 12 – 1 * 2 it is 10 and the absolute value of it so absolute value of 10 is equal to 10 given that is positive and this is exactly what we have here and this is referred as the area of the parallelogram that the two vectors are forming and how does that look like in uh the uh coordinate space so this is the parallelogram that we were referring by and this area that is formed by this parallelogram is equal to the determinant of the a The Matrix a so one thing that we need to keep in mind is the definition of parallelogram which means that those two are parallel and they are the same so this and this lines those two are the same and then of course the same holes for those two they are parallel and they have the same um length therefore this figure in here this is what we are referring as parallelogram and those two vectors that we can see in here this one and this one they form this parallelogram and they are the two vectors that are part of the Matrix a hence if we got two vectors that the uh that come from The Matrix a so Matrix a and we got here this two vectors in a 2X two Matrix then the determinant of this Matrix is then describing the area that these two vectors are using or are spinning when creating this parallelogram so the determinants they play an important role in understanding the geometric properties of the spaces that uh spent uh by these vectors they provide valuable insights when it comes to the scaling effect effect of linear transformation the orientation and the um the locations of them in the coordinate system as well as the Practical applications in calculating areas in calculating volumes welcome to another unit in our fundamentals to linear algebra course where we are going to talk about Advanced linear algebra Concepts so uh in the first module we are going to talk about Vector spaces and the projections we are going to define the bases in a couple of examples of them we have already touched upon this concept briefly when we are calculating the basis of a no space and the basis of a comp space we are going to do a similar example in this case and then we are going to uh look into this concept of the uh standard bases for uh different spaces including the arum we’re going to to introduce the concept of projections what is the definition of projections what is the formula how we can calculate it we are going to look into detailed examples of them then we are going to talk about a concept of auton normal basis in this module we are going to introduce this concept then we are going to understand the orthogonality normalization we are going to then discuss a very important topic in linear algebra which is the gramme process we’re going to Define it we are going to see the overview the step by step process of applying grme uh algorithm then we are going to see an example of it and the calculations step by step and then we are going to talk about applications of auton normal basis the application of gram Smiths process and the importance of this auton normal basis this is the module one of this part so let’s first Define the basis a basis of a vector space is a set of all both linearly independent vectors that spend the entire Vector space every Vector in the space can be expressed as a unique linear combination of the basis vectors so there are a couple of parts in this definition they are really important and first thing that we need to uh mention here is this Vector space that says it is a set of linearly independent vectors that spend the entire Vector space this is very important because um here we are with the basis is simply this Vector space that is a set of linearly independent vectors which means that one of these vectors cannot be Rewritten as a linear combination of the other one so we have a larly independent vectors and they span the entire Vector spe space so for instance if we are in R2 then the basis of a vector space is then a set of linearly independent vectors that span this entire R2 so we do we then need to have four vectors forming a basis so let’s say we have a basis of vector space for us to say that this is the the basis of this Vector space let’s say in R2 we need to First say we need to First prove that these vectors this vectors are linearly independent and two they span the entire R2 which means that span of these vectors is equal to R2 we can actually be even more specific in a example of let’s say having a vectors A and B we can say that this set that we have here consisting of vectors A and B in R2 form the bases of a vector space if the first criteria is that a and b are linearly independent and the second criteria is is that those two vectors together they spend the entire Vector space of R2 which means that span of a and b Vector space is equal to R2 on more specific example and then the second part of this definition says that every vector in the space can be expressed as a unique linear combination of the basis vectors which means in our specific example when we had this A and B forming the bases of vector space this means that if we prove that this is indeed the basis of this Vector space then any combination every Vector let’s say a vector C that consists of this C1 and C2 elements that this Vector this random Vector from R2 C can be represented as a linear combination of these vectors A and B so let’s say we have a coefficient K1 time a plus K2 * B then here we are representing this random Vector c as a linear combination of these vectors A and B which form the basis of a vector space of this Vector space so we have previously spoken about the no space and Comm space so let’s now go ahead and do one more example when we are calculating the no space and the Comm space and then we are again calculating this concept of basis of vector space and B basis of the Comm space and then we will be uh finding the basis of a vector space uh with um R2 example so given that we have already looked into this concept the basis of Comm space and basis of no space I will try to uh go through this example bit more quickly to save time on more complex Concepts so let’s say we have an example of a matrix and that Matrix is a is equal to 1 2 3 6 this is our 2x 2 Matrix a and the first thing that I want to do is to understand look into my Matrix and understand whether I’m dealing with unique vectors or not and by unique I mean whether I’m dealing with two vectors that are linearly dependent or linearly independent this kind of inspection always helps us to save time when we are doing our calculation for the no space and for the Comm space and for the basis of no space and base of Comm space now here we can see that this our A1 the first Vector the first com Vector forming the Matrix a and this Vector is the hu another thing that uh we can notice here is that we can easily take the First Column A1 multiply it by two and get D A2 because 1 * 2 is 2 3 * 2 is 6 that is that 2 * A1 is equal to A2 which means that we can say that A1 and A2 are linearly dependent okay so seeing this and knowing this this can help us to quickly go through our calculations of the bases of the col space and the bases of a no space so let’s go ahead and first calculate what is the basis of no space of a so we have already learned that the um basis of a no space can be calculated when looking into the first no space so we we need to calculate the no space and then we need to calculate the basis of that no space so this means that we need to get the na and we have learned that in order to get the na we for that need to solve the a x is equal to zero problem and this x will give us the no space of a we have also learned that the no space of a is equal to the no space of R RF of a which means that using gausian reduction or gausian elimination we can quickly find the solution to this problem of a x is equal to Z and find this x this is simply solving a similar Pro problem only in this case the B so this is equal to zero because we are dealing with the homogeneous case I want do the calculation for this we have done a ton of examples when we were doing this step bystep calculation getting the uh argument Matrix of a and then doing all these different draw operations normalizations and then eliminations in order to uh get this uh complex Matrix a to the point of uh basic representation from which either we can visibly see the solution to the problem or we can at least simplify it and describe it as a linear combination of vectors in this case if you go ahead and solve this problem you will find that the x that solves the a x is equal to Z problem is unique and this x is equal to- 0.894 4 as the first element and then 0.447 as the second element this can be a good practice also to refresh um the memory when it comes to the gaion elimination and reduction the example itself is quite simple the a is just a 2×2 matrix um and um by performing couple of operations uh in terms of normalization and elimination you can find this X for your ax is equal to zero given that now we know what is the solution to ax equal to Z problem now we know what the no space is because in this case the all this help us to understand that the no space of a is then equal to the set the vector set where as part of this we got just single column which is minus 0.8 94 and 0.447 this is the no space this is the first part I will say it 1.1 and then 1.2 will be to get the bases basis of this na and we have just seen what is the definition of the bases so the basis of vector space is a set of linearly independent vectors that spend the entire Vector space therefore given that we got just this single Vector as a solution to our problem we can see then very quickly that the new space of a is based on this and then the basis of the no space is simply this entire set so knowing what the solution is to our homogeneous problem a is equal to Z so let me also write down in here then we know that the no space the N A is then equal 2D Vector minus 0.894 and 0.447 this is my Vector X that solve this a is to Z problem and this is simply the no space of a and given that we have calculated and we have got this unique solution to our problem we can say that any Vector in R2 can be represented as a linear combination of this Vector so 1.2 any Vector in R2 can be represented as linear combination combination of this Vector X therefore we are saying that the bases of no space of a is this entire set consisting of the single vector so this is about the basis of a no space let’s Now quickly look into the concept of the basis of a c space so the first thing we need to then uh get is the column space so to get the bases of CM space we need to get the ca first which is the Comm space of a and what is the Comm space of a the Comm space of a uh is the uh setle and the space of the vectors that we can see in here in this A1 and A2 is it’s quite straightforward so these two vectors they form the c space of this Matrix a so then the ca is simply the set of one three and then two six vectors this is A1 this is A2 now we have just seen in the beginning before even starting our calculations that A1 and A2 are linearly dependent because A2 can be right written as 2 * A1 so one of these vectors can be written as a linear combination of the other one this means that we got just a single linearly independent vectors and why is this important because we have seen in the definition of the basis that for us to have a basis we need to have a linearly independent vectors so the basis of vector space in this case a Comm space is a set of linearly independent vectors that need to spend the entire Vector space in this case R2 so therefore we need to look into the ca that we got in here and select one of these two vectors that can be considered as linearly independent let’s say we pick one three now we know that we can then write any Vector in R2 as a linear combination of of this Vector 13 so we can scale this Vector 13 and get a new Vector in R2 therefore we are saying that the basis of Comm space basis of Comm space space of a is then the set of one three because one three so A1 is then linearly independent and the span of A1 is R2 now when it comes to the uh bases of the entire R2 one thing that we can notice is that this A1 so one three it’s not forming it’s not spanning the entire R2 because because we cannot uh write any random Vector in R2 as a linear combination of these two therefore we are saying that this is the basis of Comm space but we are not saying that this is the basis of R2 and the final element in this definition that I want you to uh focus on is that every Vector in the space can be expressed as a unique linear combination of the bases vectors so in here we have looked into this idea of basis of a new space and the base of Comm space and we saw that we are talking about specifically the new space and Comm space but when it comes to the entire space for instance the basis for R2 then the basis of Comm space for instance is no longer um helping us because the basis of com space it consists of this Vector one tree and this one tree alone is not satisfying the second criteria that says that this Vector needs to spend the entire Vector space because this one tree Vector it’s a single vector and this Vector it is not forming the entire R2 it’s not um the basis for R2 it’s not spinning the entire uh R2 so given that D1 Tre is not spinning the entire R2 because of that we know that the one tree is not the set of one Tre is not the basis of R2 so this distinguishing of the basis of R2 based basis of Comm space basis of no space is really important because basis for R2 it means that we need to find set of linearly independent vectors that they together form the entire R2 they spend the R2 which means any random Vector that we can see in R2 we can represent as a linear combination of the vectors in this space so in here let me also prove that this one tree alone is actually not forming the R2 it’s not spinning the R2 which then uh concludes that they are not the it is not the bases of R2 and after this I will then provide you an example where we have a set of vectors that span R2 and are linearly independent which means that they are the bases of the entire R2 so first I want to show you why this single Vector one Tre is not the bases of R2 so being the base of R2 we have the criteria that the vectors need to be linearly independent so let me actually clear up some space here so I want to see and find the basis of R2 first I want to prove that this set which is the basis of Comm space I want to prove that this is not the basis of R2 then I will also as part of the second part of this proof look in look into the case when we do have vectors and the set of vectors it forms the base of R2 so the first thing the first criteria of the basis of R2 says that let’s qu it 1.1 the first criteria says that this Vector in this Vector space it need to be they need to be linearly independent well that criteria is valid given that 13 is linearly independent this means that criteria one is satisfied so whenever you got just one vector this criteria is automatically satisfied so then you have the 1.2 which says that we need to have this span of these vectors equal to R2 so is the span of 13 the R2 well no and how we can prove that because the idea is that any Vector including an example where I have for instance uh let’s say four and five this Vector that I need to be able to find find a scaler that will help me to create a linear combination let’s say C linear combination using this Vector 13 which will then set this amount this to be equal to this which means that I need to be able to write my random Vector 45 as a linear combination of this Vector that forms my uh Vector space so let’s see whether that is even possible well here I got four and five if I do this multiplication in the right hand side I get C and here I got 3 C because C * 1 is C and 3 * C is C and this means that I have an equation 4 is equal 2 C and 5 is equal to 3 * C from this I get that the C is equal to 4 and C is equal to 5 / to 3 but that is impossible because 4 is not equal to 5 / to three which means that I’m proving in here and I got to prove that the uh any random chosen Vector 4 five cannot be written as a linear combination of this Vector that forms this uh space therefore as random Vector from R2 can’t be written as linear combination of one Tre criteria two is not satisfied because for that we had to say that this pen of one3 is equal to R2 which we saw that it’s not the case because then we would have been able to represent this four five as linear combination of this one Tre Vector okay so now we have proven that the one Tre is not forming the basis of R2 let’s now look into what then does form the basis of R2 an example of it so we are familiar with the unit vectors E1 and E2 into r 2 which form the identity Matrix and this is 1 Z and this is 01 also 1 0 0 1 in the form of a matrix so in this example we have a set consisting of E1 and E2 where this is this E1 this is the E2 and the set corresponding to this Vector space is then 1 Z and then 0 1 and now I will be proving that this space this Vector space does indeed equal to the bases of R2 so this is the basis of R2 so the first criteria of the basis is that these two vectors should be linearly independent now we can quickly uh remember from our previous theory that the two unit vectors one0 0 1 are actually linearly independent that’s something that we have proven and you can easily see it also from here there is no way that you can find um scalar C that you can multiply this Vector with and get a vector zero one because for that for this one to become a zero you need to multiply this with 0o but then 0 * 0 is not equal to 1 which means that there is no way that you can find a scalar C to multiply this E1 to get the E2 so let me write this down E1 and E2 are linearly independent because there is no scalers C which is a real number such that such that c * E1 is equal to E2 so this means you can’t write E2 as linear combination of E1 or vice versa this means that E1 and E2 are linearly independent and this satisfies our first criteria so criteria one is satisfied what we have also learned is that any Vector in R2 can be actually written as a linear combination of a unit vectors that form that um R2 in this case 1 0 and 01 so let’s assume that this random Vector is C1 C2 so this is C vector and what we want to prove is that we can always write this C in terms of a linear combination of these two vectors and how can we do that well let’s say here we got a K1 K1 which is a real number and we multiply this by 1 Z and then we add K2 K2 and then here is 01 so this is our E1 this is our E2 can we do this well what is this this is equal to K1 0 Plus 0 K2 and what does this give us well this means this amount let me write it over K1 * 1 which is the E1 plus K2 * 01 which are which is our second Vector E2 this is equal to K1 0 + 0 K2 and this is equal to K1 K2 so I got on one hand this Vector C1 C2 which I want to write as a linear combination of K1 E1 plus K2 E2 if I take the K1 equal to C1 and K2 K2 equal 2 C2 well then in that case I can prove so this is basically equal to C1 and C2 which means if I take this K1 and K2 equal to C1 and C2 respectively and those numbers are given then I can represent this Vector c as a linear combination of E1 and E2 which is what I had to prove in order to say that the span of 1 0 which is the E1 and 01 which is the E2 is equal to R2 because any random Vector that will be provided to me with an element C1 and C2 and those are just real numbers can be written as a linear combination of these two vectors this means that the spend of these two vectors is equal to R2 and this is basically the second criteria so criteria two satisfied and if the criteria one and criteria 2 are both satisfied it means that this Vector space of 1 Z and 01 this is the basis of the entire R2 so let’s now talk about the concept of projections by definition a projection of a vector a on two not Vector B is the orthogonal projection of a along B it’s denoted by approach and then B underneath here we see the index and then a so projection of a onto B so here is the A and here is the B and represents the component of a in the direction of B so component of a in the direction of B all right so in order to properly understand this concept the intuition of it let’s actually make use of the R2 space so let’s first start by picturing in our flat world the R2 coordinates so the Cartesian coordinate system so let’s say here we got our y AIS here we got our xais is so this is the X this is the Y and uh here we of course we need to keep in mind this is just an example when it comes to projections we can always go beyond R2 but for keep it simple and truly understand this Concepts and this intuition behind the projection I want to simplify this and do the example in r two so here uh imagine that we got this line and this is our line that goes through the center that’s called this line B so B is line in R2 let’s say this is that line and now that imagine that we have this Vector which is part of this line let’s say this is this line and this line is the representing by uh on this line we got this Vector B and this Vector is basically part of that line as you can see this is the vector B on this line B so we know from this concept of the line spanning the R2 and then vectors we know that in this case independent what is the magnitude of this Vector what is the direction of this Vector we can represent this line B by this linear combination based on this Vector so linear combination of this Vector which is in this case D set set then here we got some C where C is a real number multiplied by this Vector B knowing that this C is just a real number so let’s make it actually green so we can basically say that this entire line B can be represented as the set of this linear combinations of these vectors so for instance if this is one and we do the C isal to two then we can get this part of so we can get this Vector otherwise if C is equal to three we can get this vector or C is equal to 4 this vector and then and so on which means that we can always come up with a linear combination forming a part of this line therefore we are seeing that this line can be represented as all these linear combinations uh of this Vector B which is part of this line and here this C is just a scalar so a number which is a real number so this C * Vector B represents this uh entire line so we will knit this in a bit but for now imagine this line and part of this line which is this Vector B so imagine then that we got yet another Vector which is let’s say in here I again going from the center but this time in this different direction so in here this is Vector a we call this Vector an A so you can see that this Vector a is actually much longer than the vector B and we see that V Vector a is not lying on the same line as B so B is lying on the line b and a is not lying on the line B now let’s say we want to project this Vector a onto this Vector B which means that we want to project this a in this direction so we want to bring this Vector a onto this line let me actually use a different color and the word of the projection actually does make sense in here as you might notice because we are trying to cast the shadow of a onto this line of B and how can we do that we can only do that if we connect this Vector a like this with this orthogonal line let’s say by using a different color of this so with this perpendicular line we then will be connecting the vector a to the line B because we want to project our Vector a onto this direction C so this perpendicular line that you see in here that goes from Vector a to the line B where on line B we have the vector B so here is the line a or line B and this perpendicular line it goes from a to line B and on line we we have the vector B that is represented like this then the projection of a onto Line B is this Shadow Vector that you see in here and the word projection or the name projection actually does make sense because we are projecting this Vector a onto this line and it creates this Shadow so we are casting this Shadow on here and and this Vector is what we are referring as projection of vector a onto Line B notice that we don’t say projection of B on Vector B but instead we are saying projection of a on the line B then another thing we can notice is that we are getting this projection of a on B so this vector by taking the Vector a so Vector a and subtracting from that projection of a on B that is the formula for this Vector that we refer as a perpendicular that goes from a to line B so when drawing this perpendicular line from a to line B we are referring this as a minus projection of a b because you can see that this Vector is simply this Vector minus this Vector that is the um ex mathematical expression for this perpendicular line so how we can then find out what is this C that we got in here because we understand that that to get this exact formula for the projection of a on the line B we need to understand what is the scaler specifically what value are we using to multiply this Vector B to get to this point so what is that c what is c what is C such that c * B is then equal to projection of a on the line B because we can have different sorts of a linear combination of vector B on this line uh B and in fact B this line B is the set of all linear combinations of this Vector B and I want to know specifically what is the vector that we see in here what is the shadow Vector because this is the projection of a on the line B what we see in here now how can we do that well let’s first formally def find on this specific case what is the projection of a on this line B so projection of a on line B is some Vector that is also on line B where a minus projection of a on B is per pendicular or ortogonal two this is basically the definition of the projection of a on line B under this specific example so in this case the way we can find this projection is by looking into this C so this is what we are interested this specific specific c times B vector and knowing C and knowing B we already know what is B what B is knowing C we can then describe this specific projection so one thing that we can know is the condition under which we say two vectors are a topen not that’s something that we already have learned as part of the previous lessons so let’s go ahead and find that amount so now what we need to do is to calculate this value of C because value of C calculation will then lead us to the exact uh Vector that we are interested in which is this projection so our end goal is to find out what is this projection of a on B this is what we want and for that we need to calculate this C because we already know the vector B so let me quickly remove this part cuz here we will then do our calculation so one thing that we need to make use of is this part when it says orthogonal because we know that if two vectors are orthogonal then their dotproduct is equal to zero so we know that this Vector is orthogonal to this target Vector which means that we can say that the Vector a and then minus projection of a on B multiplied with Vector B that this is equal to zero this is something that we know by definition of orthogonality two vectors are orthogonal it means that their dot product is then equal to zero now let’s make use of that part so this means that we need to describe this projection of A and B we need to make use of the fact that we know that this projection of a onto B is actually some linear combination of vector B so let me actually go ahead and remove this part we already know the definition so let us go ahead and calculate that c that we need in order to find out what is this entire projection so few things that we need to clear out is those formulas because then we can make use of them to find the C so we know that by definition the projection of a on the line B it is this vector that we get where we draw this perpendicular line from Vector a onto Line B and we said that this line is equal to this amount this is simply the vector a minus this Vector the shadow Vector which we said it’s defined by projection of A and B this thing so we can make use of that because we also see in here that this we are saying isogonal to this vector so given that this uh Vector a minus projection a b is orthogonal to line B that is also orthogonal on this specific Vector which is the projection itself so from this we can make use of the fact that two vectors when they are orthogonal their dotproduct is equal to zero in order to find this uh value of C so firstly we just said that D A minus projection of a on the line B that this multiplied by this Vector B is equal to zero because those two lines they should be perpendicular but at the same time we know that this is simply the linear combination of this vector because this line is perpendicular to this one and this line is some linear combination of this Vector B because if I have here a vector and then I have the longer version of that Vector on the same line which is then a linear combination of this original Vector let’s say this is my Vector B then this second Vector that I in here is then equal to sum C * Vector B this is also exactly what we said in here we said any Vector on line B can be represented as a linear combination of vector B and this is exactly what we are seeing in here so this projection is simply that c times Vector B this is something that we have already said so we are just making use of that to fill in that volum so this then results in a minus this C * B multiplied by this Vector B is equal to zero formula so here we are simply making use of the fact that the projection of a on to B is the shadow Vector which is then equal to some linear combination of this original Vector B which is on this line B then I can easily find the scalar C from here because we know how we can easily calculate this dot product so let us actually go ahead and do that let’s first multiply this a by B and then minus so I’m simply opening the parentheses C * then I got B by B and this equal to zero so C * B * B is then equal to a n B which means that c is equal to a * B / to B * B now when we have the C we can easily derive the formula for the projection of a on the line line B so this is the first part this is the second part so then the projection of a on B so projection of a on B is equal to this C c times the B and we just found out that this is equal to the C was equal to a * B / to B * B and now we need to take this C and then multiply by Vector B this is then the projection of a on B this Vector so projection of a on line B so you will notice that this is the same that we just got so whether you compute the projection of a on the entire line b or projection of a on the specific Vector b as we are using the vector b as a source for drawing our line this is the same as the projection of vector a on Vector B and this is the same formula as we seen here so this is the projection formula that we have just uh found out so projection of a on to B is given by this formula a * B so the dotproduct of the vector A and B divided to the dotproduct of the bay with itself and multiply it with the vector B and this is the in here this is something that we have calculated time and time again in our examples so if we go back to our example then here we can see that this is our Vector B this is our Vector a and we are saying if we take the vector a and we project it onto this Vector B then we can calculate this projection which is in here the formula for this entire Vector which we are calling projection of a on b or projection of a on B this can be find out so the the length of that Vector we can find by by using this formula so the dotproduct of vector A and B divided to the dotproduct of B with itself and then multiplied with Vector B so again a DOT product and this is of course something that we get as a vector so this is a vector something that is equal to this entire Vector in here this Vector so uh I know that this uh might look bit messy because it contains many moving Parts but I wanted to provide this detailed explanation and this step by-step process even if it is bit confusing and bit uh messy um in the beginning because this help us to understand what this uh formula is about and what is the intuition behind it because what we are doing is that we are making use of the fact that the line can be represented as a linear combination of all the um vectors that we use in here so this is Vector B and this entire line B is a linear combination of this Vector B and we can make use of that in order to find that scalar that we are multiplying to create this single linear combination that will end up giving us this Vector that we see in here which is the projection the projection that we are interested which is this line This is the projection that we are defining by this projection a on to B and we can get that by making use of the fact that this this perpendicular line that we are creating in here which is simply the vector a minus this projection this is this Vector this projection Vector that this is perpendicular to this line B and if the vector B is part of this line B this means also that this line a minus projection a is also perpendicular to that vector vector B making use of that formula we can then uh make use of the product of the two we know that the dot product of two perpendicular vectors is equal to zero making use of that we can then obtain this specific scaler C that we need in order to get the final formula for our projection we are interested in this C because knowing C we can and then multiply with this Vector B to get our final projection and we have found that that projection a on B is defined as the dotproduct of the A and B divided to the dotproduct of the B with the B and multiply with the vector p and this is again a vector now let’s look into a couple of numeric examples to clarify this topic and practice with it so given vectors A and vectors B find the pro ejection of a onto B so without looking into answer I will quickly go onto that example so Vector a is this Vector 3 4 can also represent this by our more common notation which is three and four and then Vector B is one and zero so let’s quickly draw our coordinate system this our x-axis this our y AIS and then what is the a the a is three and four three and four so this is our a and what is the B the B is 1 and zero which means that our line B is then C * the vector B given that the C is a real number and one thing that you can notice is that the line B is actually our x-axis it is this line this is our line B this is our line B so the projection is then this line this is our projection because we can know that by drawing a perpendicular line in here from a to the line B we can get then the connection between our Vector a and Vector B and create our projection so this is then the a minus projection of a on line B and this part is then this is then this projection a on B and how we can get this projection well we just learned that the projection of a on B is equal to dotproduct of a with B divided to dotproduct of B with be B itself and multipli it by B this is the formula that we can use and even if you don’t remember the formula by heart you can make use of this visualization to figure out what that formula is because we know that if this line is perpendicular to this one then a minus projection of a on B multiplied by this projection a on B should be equal to zero and this projection of a on B is equal to some scalar C multiplied by Vector B that’s something that we see in here the first thing we need to do is to compute the dot product between a and b a * B is equal to 34 multiplied by 1 Z this is the dot product which is then equal to 3 * 1 + 0 * 4 and this is equal to 3 the next thing we need to do is to compute the dotproduct between B itself so B * B and what’s that that is 1 0 with 1 0 multiplied this is equal to 1 1 * 1 + 0 0 * 0 is equal to 1 then the Third third thing that we can do then is to obtain the final value which is projection of a on B is then equal to 3 ided 2 1 multiplied by Vector B which is 1 0 which is equal to 3 0 and this actually makes sense visually too as you can see in here this is the tree for the x-axis and here we have the center zero so this projection is then the vector 3 0 so even without calculation we could see just from plotting the uh on the coordinate system the vectors A and B that the projection of a on B will be this Vector 3 Z but we have followed the formula in order to do calculation step by step which is something that you can see in this answer to so the projection of this Vector a onto B is then this Vector of a length tree in the direction of B so you can see that it is of the length of three so this is the tree on the direction of B so on the line B let’s now move ahead and look into a different example but this time we will do the calculation in a quicker way so we got two vectors 43 and B is equal to 2 and we need to find this projection of a on to B so the first thing we need to do is to calculate the a * B which is equal to 43 * 2 0 and that’s equal to 4 * 2 + 3 * 0 and it’s equal to 8 the second thing we need to calculate is the B do product with B which is equal to 2 0 2 0 this is then equal to 4 and the final part is to take and uh from this one and two this values and then bring them all together so then the projection of a on B is equal to 8 / 2 4 multiplied by the vector to0 and this is equal to 8 / to 4 is 2 2 * 2 is 2 2 * 0 is 0 so we are getting this 2 Vector so projection of a on B is then this Vector 2 which is actually on this x axis similar to what we had before only with the length of two on uh towards the direction of B which is then equal to 4 and z and this is again similar to what we had before uh where we got the projection of a on B on that end up on the xaxis but now with a length of four so now our projection has as the following Vector so the uh following magnitude and Direction so this is the step by-step process that I just followed if you want to do it bit slowly and this is the final result so uh the interpretation of this projection is that this projection a onto B is simply this 4 zero this means that the A’s component in the direction of B is spends uh four units along this x-axis that we saw in here because this is the value X this is the value of y so this projection shows us that a influence in the direction of B is completely horizontal with this magnitude of four because we saw that we end up with the projection on the x-axis again so this was four this was our projection vector and if you plot this entire Vector a and Vector B on this xaxis and Y AIS then you can clearly see that the uh horizontal line that we end up with the uh projection of A and B is very similar to what we had before in here let’s now talk about a concept of auton normal bases so let’s now Define what the auton normal bases are so by definition auton normal basis for a vector space is a basis where all vectors are orthogonal or perpendicular to each other and each Vector is of unit length so as you can notice here here we have a special type of basis it’s called auton normal basis because in the beginning of this section of this module we defined formally this concept of bases we talked about the concept of calm uh space and then the uh basis of a Comm space the no space the basis of a no space and then we talked about the concept of the basis of the entire space for instance dr2 and now we are defining a special type of bases which we are referring as auton normal bases and this auton normal basis as you can see from this definition it contains two criteria for it to be uton so an uton basis for Vector space is a basis where a all vectors are orthogonal or perpendicular to each other and B each Vector is of unit length we already have learned that when we have vectors let’s say Vector A and B perpendicular it means that A and B their dot product is equal to zero that’s the first CRI IA that we need for calling our basis an auton normal basis then the second criteria is that each of these vectors they need to have a length of one if we have this condition satisfied then we are saying that our vectors they help us to form this autona basis if we got three vectors forming this Vector space it means that we need to have the a * B = to0 A * C = 0 and then B * C = to zero this is if we are in in case we are using three different vectors that Define our Vector space in this case we make make this part smaller so let’s put the length of B in here in this case the second criteria becomes that the length of a is equal to the length of B and then is equal to the length of c and is equal to one so depending on the number of vectors that you use to form your vector space the prove that you are dealing with auton normal bases will be different here we got just two vectors here we got three vectors but in both case we first need to prove that we are dealing with uh vectors Each of which are a set of orthogonal perpendicular vectors and all of them pairwise they need to be perpendicular and at the same time the second criteria says that they all need to have a unit length so their length should be equal to one we need this auton normal basis in order to simplify our calculations including the calculations of projections and Transformations that we just saw before when we were discussing this concept of projecting a vector onto a line or projecting a vector onto OD Vector because we were in this basic case when we had just two vectors in R2 and calculating projection in R2 is very easy because we can make use of this formula um a a and then B uh the dot product of them and then divided two dot product of the B and then times the B this was quite straightforwards right but when it came so this is the projection of a on B but when it comes to projection in higher dimensional space let’s say you have R5 or you have r00 or R th000 then it becomes much more difficult to do those projections and to calculate data projections and for those cases we can make use of this concept of auton normal basis to simplify our calculations and we will see that in a bit so let’s first understand this orthogonality and the normalization part so orthogonality refers then to the part of uh when we are saying that the vectors should be orthogonal to each other and the normalization refers to the fact to the fact that the length should be one this is basically the set of two criteria area that I just discussed this is uh the summary slide that will give you an indication what is meant by that so if we have two vectors V and W then we say that the first criteria is that those two vectors are orthogonal which means they’re dot product is equal to zero and we are saying that their length is equal to one which we are referring as a normalized vector so if the vector has a length of one then we are calling a vector v normalized so if both of this criteria of normalization and orthogonality is satisfied that we are saying that we are dealing with an uton normal basis so now when we have learned this idea of projections also this idea of autog colonization and the uh concept of auton normal bases we are ready to discuss the concept of the grme process so the gram shade process is this method for orthogonalizing a set of vectors in an inner product space and turning them into an auton normal set so let’s say we have a set of vectors we want to uh bring and transform all these vectors onto this auton normal set of vectors which means that we want them to be aut toonize so we want them to be perpendicular and we want them to be normalized because we know that the two criteria were specified right so the first criteria was that we need to have vectors ortogonal hence we are doing orthogonalization and the second criteria was that they need to be normalized because we want the vectors to have length one so we are doing normalization this process of turning this set of vectors onto this auton normal set by using this method of orthogonalization which is something that we are referring as a gamish made process this is something that we can use in order to simplify later the different sorts of Transformations which we need in order to perform bit more advanced uh Transformations like Matrix uh factorization different decomposition techniques so given the set of linearly independent vectors this process which we are referring as grme process produces this auton normal set that is spinning the same Subspace so we have the same Subspace it’s just that we are turning the set of vectors into an auton normal set of vectors that is spanning the same Subspace so the grum Street process step by step looks like something like this so given the vectors A1 A2 up to a n the first thing we need to do is to start with the vector V1 which is equal to our first Vector A1 and first we need to normalize this vector and how we can normal normalize this Vector well we need to take this vector and we need to divide it to its length so the grme process step by step will look like something like this so in the first step what we need to do when starting with these vectors of A1 A2 up till a n so in RN we need to First Take the first vector and we need to normalize it and how we can normalize the vector and ensure that its length is equal to this length of V1 well we need take that vector and we need to divide it to this L because when we take the vector V1 and we divide it to its length of V1 then we will ensure that the length of that Vector is equal to 1 we can actually prove that very easily but I won’t do it in here uh feel free to go through the process assuming that the length of the vector what what you want to achieve at the end is that the length of vector v is equal to one this is something that we want to achieve and this normalization process can be done if we find a way to ensure that we uh get this E1 because E1 means that we end up with this Vector y 000000 0 this will be for first Vector so V1 this is E1 so the one is really important here so we want to normalize this Vector V1 by uh ensuring that we get the E1 so we go from V1 to E1 and the way we do that is that we take the V1 and we divide it to the length of V1 and in this way we get the E1 so the normalized version of P1 1 is E1 so then for each subsequent Vector a which means A2 A3 A4 up to a n we need to subtract its projection on all the previously computed orthogonal vectors in this way by using this step two we are ensuring that all is different each pair wise set of A1 A2 and then A2 A3 Etc they are all orthogonal to each other and we know that this projection is something that we got when we had this two perpendicular lines so we had this Vector we’re projecting onto this Vector we got that by finding this perpendicular line and making use of that using this property we are then making use of that in order to see how we can ensure that the subsequent Vector that we have is always perpendicular to this one so let me actually write down what is in this formula so here VK is equal to AK minus the sum of all the projections so then we need to normalize the VK to get the EK and then we need to repeat this Step 2 and three for over vectors which means that first here we apply this normalization on the vector A1 so V1 is equal to A1 and then we get the normalization by getting this E1 so E1 is normalized version and then we need to apply a bit different tactique for our V2 V3 up to VN and then let me actually write down this for this General case so what this processed this the gr let me ensure that I’m not making a typo processed step by step means step number one for vectors A1 A2 A3 dot dot dot a n so we are in the RN then step number one basically says take the V1 and set it equal to this first element V1 this is A1 then what we need to do is to normalize it to get the E1 so normalize normalize V1 to get E1 which is equal to 1 0 0 0 and then dot dot dot zero and the size of is n by 1 and how we can do that by taking this Vector V1 and divided it to the length of V1 which basically means in this specific case A1 ided to the length of A1 this will then give us our A1 this Vector this is basically what the step one entails then in the step number two we have for each subsequent AK where K is just an index referring to whether we are dealing with K is equal to 2 so uh A2 A3 and then dot dot dot a n this is what basically the K is used for to refer to which Vector we are dealing with we need to subtract is projection on all previously computed orthogonal vectors by using this formula so let’s actually do a couple of those case to see what is going on for instance for K is equal to 2 so K is equal to 2 and here is the formula by the way so VK a VK is equal to a k minus sum K is equal to K starts with one and then then me use a different index so I is = to 1 till K minus one and then projection of AK a K on E1 or EI I so the eii that we have just computed because every time you are then normalizing and normalizing every time your vectors and then you are uh finding out what is the projection of your vector a onto that EI and then you are subtracting that from your vector so what this means in Practical terms when for instance your K is equal to 2 it means that V2 is equal to a 2 minus sum of I is = to 1 and then K is = to 2 K minus 1 this means this is 1 projection of a and then 2 on A1 given that this is one this is simply equal to A2 minus projection of E1 that’s normalized version of E1 and then A2 so projection of A2 on E1 and then in the step number three we need to do we need to go from VK to get EK so basically we are ensuring with the step number two the orthogonally orthogonality condition and with step number three I me add some spe Cas in here so in the step number three step number three we then saying let’s normalize normalized this VK that we have just computed in here because we remember that the second criteria after tonality is normalization that the unit or the length of the vector should be equal to one so then V K in this case for K is equal to 2 for K is equal to 2 means that we need to go from V2 to E2 and the way we can do that is by taking the V2 by V2 and then divide it to the length of V2 this will then give us the E2 this is the normalization part and this step number four basically means repeat repeat step to entry for all case which means that if we go back so we are done with V2 so we have obtained V2 and then we have obtained normaliz normalized version of V2 by getting this E2 we are ready to come back and do the same for K is equal to 3 and for K is equal to 3 in Step number two we got V3 is equal to A3 minus making use of this formula sum overall I is = to 1 K – 1 is = 2 and then projection of this time A3 see three k is equal to three and then on A2 actually it says EI let me remove this this otherwise we would have made a mistake this should be I because then I will change per K this is the entire idea we need to re um subtract all the um projections what this basically means is that we need to take A3 and this time given that here we have two instead of one in here we need to have an extra step which means A3 minus and then what this formula basically says this is the sum of the projections of A3 on e i where I goes from one to two so projection of a Tre on a one when K so when I this is the I is equal to one case plus projection of a Tre on A2 this is the I equal to 2 case this is basically what this summation says this is this element and we have seen this as part of the high school but also the pre-algebra course okay so now when we are clear on how we can calculate the V3 in the step number two for K is equal to 3 we are ready to go onto the step number three and what was step number three the step number three for K is equal to Tre was saying let’s take the V Tre and nor normalize it to go from V Tre to e Tre and how we can do that by taking the V Tre and dividing it to the length of V tree to get on to E Tre and this cycle goes on and on until we cover all the case so all the vectors so the idea is that we first for our initial tab we set the V1 equal to A1 we normalize it then starting from the K is equal to 2 we don’t go first on and on WE autal it by formula in here by using this we can ensure that each of these vectors is then orthogonal to all the other vectors so for K is equal to 2 we ensure that this uh vector that we get is orthogonal to all the other ones and the cas is equal to treat that the third Vector is orthogonal to all the other ones and we are doing that in Step number two so for each case for each K we basically are ensuring that in this case we have an a vector that is autal to all the other vectors in this set and for each Vector we are also normalizing it to satisfy the second criteria because we had this two criterias to create this auton normal set so we are doing this in subsequent uh way so first for K is equal to 1 so basically for A1 and then we are doing this for K is equal to 2 so A2 and then until K is equal to n so a n what we are doing every time is that we are obtaining this V1 and then we go from V1 to E1 to normalize it and then here we are getting the V2 here to go to E2 by normalizing it so this basically the step two and step three and then we do this every time and up until to the point of obtaining VN and then from VN we go to to normalize it so this is the idea of this entire process step by step step to start with V1 as part of the step number one and then as part of Step number two for each subsequent Vector a k so K is equal to 2 obtain the VK and then normalize it for K is equal to 3 obtain the V3 and then normalize it to get E3 up to the point of the last Vector which is a n the vector a n we compute the VN and then we normalize it to get the and this is what this part is which is the step number two that says repeat steps to entry for all vectors it means that every time when you increase your K when you go into the next Vector we first compute the V so VK and then you normalize it you get the e k and then you go back to the step number two or three because you then again need to calculate the VK and then EK and then for the next case so this is something that you will see also a lot when you are writing Thea code for your uh algorithms because in many cases you need to do this repetion of the steps so uh you for one vector you do something or for one iteration you do process and then you uh go back and do for the next one and for next one this process is what we are referring by repeat step number two and three for all vectors so let’s now look into an example let’s apply this grumme process two vectors A1 and A2 where A1 is 1 1 0 and A2 is 1 1 so let’s go ahead and do that so A1 is equal to 1 1 0 A2 is equal to 1 0 1 we want to apply this grum process to create this auton normal basis for the Subspace that is pented by A1 and A2 so now we have the set 1 1 0 and one 1 and what we want is to create an autonoma basis so creating creating or to normal normal bases with from M process so here we got only two vectors so obviously it’s this and it’s a very simplified version of it what was the first step in our case uh in our algorithm it was to set the V 1 = to A1 what we need to do step number one we need to set the V1 equal to A1 and we need to normalize normalize the V1 to get E1 that’s what our goal is so let’s go ahead and do that V1 is equal to A1 and is equal to 1 1 0 that’s our A1 so 1 1 Z and in order to normalize V1 and get the E1 we know that this is equal to V1 / to the length of B1 which is then equal to take this V1 so that is 1 1 0 and then divide it to the length of V1 and you can very quickly see that given V1 is equal to V1 * V1 that’s something that we learn in the very beginning of our fundamental to linear algebra course that the length of V1 is simply the dotproduct between uh V1 and V1 and it’s equal to 1 1 0 * 1 1 0 which is equal to 1 + 1 so 2 so this is then equal to 1 1 0 / 2 which is equal to 1 / 2 1 / to two and then is zero this is our E1 so we are done with our step number one because now we have B1 and we got E1 so what was the step number two in the step number two we need to set the k equal to two this is the next K so for A2 what we need to do is we want to get V2 and normalized V2 by getting E2 and how can we get that well first let’s find what is the V2 well V2 was and using that formula that we saw before which was this formula so it’s equal to AK minus and the sum I is equal to 1 to K minus one and then projection of a onto EI I so let’s take this formula over this is equal to a 2 because K is = to 2 a k minus sum and then I is equal to one till K minus 1 and then Kus 1 which is equal to basically 1 given that K is equal to 2 and then projection of A2 onto e i Y and this is equal to H2 minus given that we got K minus y is equal to 1 so the limit for our summation is equal to 1 so this one this means that like before we got just one part as part of our summation so minus and then projection of let me actually keep the same color I want it to be consistent so projection of A2 on the E 1 so you see here the i i is equal to 1 and the limit of the I is K minus one which is equal to 1 so we got here just E1 so we got the V2 formula we can then now calculate because we know A2 and the A2 is this so one0 one 1 0 1 but now we got a problem we don’t know what this is so let’s quickly go and calculate this part so projection of A2 on A1 and we learned from the projection formula that this is equal to A2 * E1 / 2 E1 * E1 so the dot product multip by E1 and what is this this is equal to 1 1 multiplied by and what is the E1 E1 we just calculate in here so it is 1 / to 2 1 / to 2 and then zero here / 2 and then 1 / 2 1 / 2 and then zero multiplied by 1 / 2 1 / to 2 and then zero here multiplied by the same Vector so E1 so this two cancel out this two also cancel out and as you can see we are getting that the projection of A2 on E1 is equal to this Vector we can also manually check that actually so let’s let’s do that so let’s see we are not canceling out these vectors and instead we are manually calculating this so here we got 101 ultip by 0.5 and 0.50 this is equal to 1 * 1 / 2 is 1 / 2 0 * 1 / 2 is 0 1 * 0 is 1 so + 1 IDE 2 this amount is 1/4 + 1/4 this multiplied by the V Vector 1 / 2 1 / 2 and then zero in here this is equal to 1 / 2 1 + 1 / 2 is = to 3 / to 2 and then 1 1/4 + 1/4 is equal to 1 / to 2 multip by 1 2 and then one 2 and then zero what is this amount well those two can cancel out so we end up with three times and then 1 / 2 2 and then 1 / 2 and then zero this is then the projection 3 / 2 3 divided to two and then zero so let me remove all these calculations and then we can take over the projection value which is 3 / to 2 3 / to 2 and then zero to get our Vector V2 which is equal to 1 – 3 / to 2 0 – 3 / to 2 and then 1 – 0 and this is equal to here it is 1 here it is – 3 / 2 and here is minus and then 1 ided to 2 because 3 / 2 is minus uh it is 1.5 and then 1 – 1.5 is simply – 0.5 so this is then the vector V2 then what we need to do is to normalize this Vector to get D E2 which is then equal to V2 / to V2 length which is simply equal to V2 / to V2 * V2 so the dot product and this is equal to let’s take the V2 which is -1 / 2 and then Min – 3 / 2 and then 1 and then divide it to and this amount let’s quickly calculate that it is equal to so the length of V2 is equal to – 1 / 2^ 2 + – 3 / 2^ 2 + 1 this is equal to 1/4 + 9 / to 4 + 1 which is 4 / to 4 and then this is equal to 1 + 9 is 10 10 + 4 is 14 so 14 / to 4 this is the length of it so 14 / to 4 so then this is equal to this Vector to this threedimensional vector -1 * 14 -1 / 2 * 14 / 4 is equal to this is 7 so minus 7 / 2 4 and then – 3 / 2 think I just made a mistake here actually so minus 1 / to 2 so the first element and then divided to 14 / 4 is actually actually equal to this multiplied by 4 / to 14 so you take this element then divide it to this one and we know that a / to B * C / 2 D is equal to a * D and then B * C so we are basically flipping this side this is from pre-algebra and then here this is equal to 2 and then is = to – 1 / 2 7 then let’s sh the second one too so we got – 3 / to 2 / to 14 / to 4 is actually = to – 3 / 2 * 4 / to 14 and then if we remove this this is then two this is seven this cancel out this equal to -3 / to 7 – 3 / to 7 and then finally we got 1 / 2 14 / to 4 which is equal to 4 / to 14 this equal to 2 / to 7 so 2 / to 7 and this is our A2 and given that we got just two vectors so we have already reached the end of our solution so now when we have already the V1 and the V2 the E1 and the E2 We have basically completed the process of this grummet uh procedure because we have already uh only two vectors that means that we need to have V1 and V2 and then uh E1 and E2 and this is all that you need in case you got two vectors if you have three vectors of course the process will include um the same process of Step number two and three so the V2 and the normalization of it two times for your k equal to 2 and k equal to 3 and then if you have more vectors then every time you will have more of the steps but at the end what we want to have is the set of vectors that are orthogonal and at the same time they are normalized in this case we say that this vectors form this orthonormal bases now why is this important the applications of orthonormal bases well firstly it simplifies a complex Vector operations and uh this is the basis of many uh more difficult mathematical Concepts uh like for year series or quantum mechanics it’s used also um when it comes to this auton normal basis uh also signal processing and it’s a critical uh process in numerical methods especially in machine learning algorithms and in data compression so we will see this process to be Ed also as part of uh decomposition techniques which is really important when it comes to different algorithms uh whether it’s optimization algorithms but also um algorithms that are used for recommender systems for example and those uh Concepts they all come together and we will see later on when we will be discussing the concepts of the compositions and metrics factorization so this uton normal basis and this grum made process they are really foundational in linear algebra they provide tools for simplifying and also solving this high dimensional problems efficiently their application include different fields of science engineering demonstrating their versatility and utility let’s now talk about the special matrices and their properties so we are going to talk about special matrices like symmetric matrices and their example diagonal matrices and their corresponding example but also the orthogonal matrices with the corresponding example so when it comes to the special matrices special matrices have unique properties such as being symmetric or all nonzero elements on the diagonal like diagonal matrices or orthogonality uh in matrices which means that we have orthogonal matrices so when it comes to the symmetric Matrix it means that uh the a The Matrix a is equal to its transpose to a so a is equal to a in this case we can confirm and say that the Matrix a is symmetric so in this case we have Matrix a and we know that the way we need to transpose this Matrix is to taking this rows and making them The Columns of our transpose Matrix so a is then equal to 2 – 1 and then zero then the second row which is min -1 and then 2 and then Min -1 and then the third row which is 0 – 1 and two so the third row then becomes my third column so as you can see those two are the same so I’m using then the definition of the transpose of the um Matrix and then here then we end up with two matrices they are actually the same so we can see that the A and the a in both the First Column they got 2 minus one and a zero the second column Min -1 2 and minus one the third commn 0 – one and two so their columns and their rows they are the same which means that we are dealing with a symmetric Matrix so whenever we want to check whether the Matrix is symmetric we just need to take the transpose of it and see whether the Matrix is equal to its transpose in that case we are dealing with symmetric Matrix do also note that for a matrix to be symmetric it needs to be a square Matrix so it needs to be 2x two in the two dimensional space or 3×3 in the three dimensional space or n by N in N dimensional space which means that the number of rows should be equal to number of columns because otherwise when you flip your number of rows with number of columns on in case there is no um uh Square version of that Matrix so m is not equal to and in that case a will have a dimension of M by n and then a t so a t will have a dimension of n by m which means that there is no way that a can be equal to a this is not then possible therefore we need to have a square Matrix for them to be symmetric let’s now talk about diagonal matrix so a diagonal matrix has a nonzero element only on its diagonal which means that in this case we have this nonzero elements on the diagonal so let’s call it d11 d22 and then d33 this equal to 3 this equal to 5 this equal to 7 and all the elements as you can see in here they are zeros so the concept of diagonal matrices is very uh simple therefore we will then go through the next example which is about orthogonal Matrix now this is a concept that we haven’t yet seen and we spoken about so let’s code read through this bit slowly so an orthogonal Matrix is a square Matrix whose columns and rows are orthogonal unit V vectors so auton normal vectors and its transpose equals its inverse so there are two part of these elements so firstly it says that for the Matrix to be orthogonal Matrix it should be square Matrix so Square Matrix and then its columns and rows are orthogonal unit vectors so columns and rows are orthogonal unit vectors which means they need to be normalized so normalized so um we have seen when forming this uton normal bases that we had this process of uh this condition of orthogonality the vectors had to be orthogonal and they had to have a length of one which means that they had they had to be normalized we can see exactly the same in here so hence the name uton normal vectors so they are orthogonal and they are unit vectors which means they are normalized so then the final condition is added in here which actually is not so much a condition but rather than property something that we can prove that once we have all this we can also say that if we are dealing with orthogonal Matrix then Q T * Q so the dot product of the transpose with that Matrix Q is equal to the Q * QT is equal to i y because the QT is equal to the Q minus one because the transpose of that Matrix Q is actually equal to its inverse and given that we learned that the Q minus one so the inverse time Q is equal to Q inverse * Q is equal to I and given that here we are learning that QT is = to Q minus one we are then making use of this to claim this so instead of minus ones that we are used to when we are dealing with inverses here we have t the transpose so in this case this orthogonal Matrix that we have just learned about this is this Square Matrix who called rows are orthogonal and they are also normalized meaning that we are dealing with QT QT is = Q minus one it will look like this so this q1 you can see that here we got the first row here we got the second row and if we calculate the dot product between this row and this row we can quickly see that we are getting a value of zero so we can prove that that they are actually autog those two rows let’s go ahead and actually prove that so let’s call this R1 let’s call this R2 this is Row one and row two and I will leave the uh column version so q1 * Q2 that’s. product on you to prove that the columns are perpendicular I will work with the rows so R1 * R2 for me to prove that they are orthogonal I need to prove that this equal to zero can we do that well let’s try so 1 / 2 < of 2 1 / 2 < 2 multiplied by 1 / 2un 2 needs some bigger space in here so 1 / 2 of 2 and then- 1 / < of 2 that’s how I can calculate the dot product between R1 and R2 R2 and R1 you can see that the elements in here are the same and here the elements are also the same so then this is equal to 1 / 2 < of 2 * 1 2 of 2 – 1 / 2 2 * 1 / to of 2 I’m simply taking this minus and given that the dot product is basically plus and then this amount I’m just taking this and bringing up in here to a avoid one more step uh given the space is quite limited now what do we see in here this value is the same as this value which means that this is equal to zero and we know that the two vectors to be autal they need to have a dotproduct equal to zero so here we have proven that dotproduct of R1 and R2 is equal to zero so this proves that R1 and R2 so the two rows of this Matrix so R1 and R2 are autogo we can also prove that the second criteria of auton normal vectors is also satisfied in here we can prove that when we look at the length of this vector and of this one then they are of the unit one so let’s actually go ahead and and do for one of them so let’s prove that for 1 divided 2 Ro of two and then 1 / 2 Ro of 2 this is a vector that the length of it this is let’s say our first row so this is R1 then the R1 length is equal to 1 / 2 of 2 2ar + 1 / 2un of 2 2 this is equal to 1 / 2 + 1 / 2 and what is 1 / 2 + 1 / 2 it’s equal to 1 so we have proven that the length of R1 is equal to 1 you can quickly and E easily also compute that for the second row and you will then also prove that the R2 the length of it is also one which is then the second criteria which said that for the vectors to form this auton normal bases so to be auton normal vectors they uh also had to have a length of one so they had to be a unit vectors in this case then we can make use of the property that d q 2 transpose is equal to Q inverse and this then results in Q2 transpose time Q2 Q2 which is equal to Q2 * Q2 transpose which is equal to the identity Matrix and specifically I2 because we are in the R2 so both this Q2 and the previous example those are all to Al matrices and in here we have proven that the rows are indeed orthogonal and we have also seen that the length of them are unit vectors meaning that we have automatically got this I will leave this one to you to do those proofs so to uh ensure that the row one and row two are orthogonal so they are perpendicular which means they the product of their uh the dot prod of these two vectors is equal to zero and also that they are normalized which means the length of them is equal to one and this means that then this holds you can actually even go ahead and uh practice the material that we uh learned as part of the previous units by calculating the inverse of this Matrix and checking that the inverse of this Matrix is indeed equal to the transpose of the Matrix so that QT is equal to Q Q -1 because we learned how we can compute the inverse of a matrix because the inverse of a matrix was equal to 1 / the determinant of this Matrix times and then the manipulated version of it which was in this case 0 0 and then we need to have here one so Min – 1 * 1 and then 1 * -1 so we have to multiply this and this by minus so 1 one and then here minus one so in this way you can also prove that this inverse is actually equal to the Q2 transpose because then you can prove that indeed and you can see for yourself that this formula is in equal to the Q2 transpose because then you can prove that indeed and you can see for yourself that this formula is indeed true in this module we are going to talk about Matrix factorization we are going to discuss the significance of Matrix factorization we are going to Define Matrix factorization we are going also to discuss the common applications of Matrix factorization across different fields and then we are going to see detailed examples of Matrix factorization so let’s talk about why Matrix factorization matters so metrix factorization techniques they are essential for various reasons they are used for simplifying metrix operations like solving linear systems or when we have this um many uh matrixes but we want to um simplify these operations that we apply to these matrices and we want to solve the problem then we can make this uh complex Matrix operations more manageable and make this uh calculations more manageable by using metrix factorization techniques we can also use metrix factorization directly to solve system all linear equations efficiently we can also use Matrix factorization to perform igon value de composition singular value de their composition or called SVD and othero operations which are crucial in machine learning and data analysis so ion values and ion vectors you might have heard already they are part of also PCA which is the principle component analysis and this comes from uh fundamentals of statistics and the uh p a is used as a dimensionality technique and in fact it’s one of the most popular dimensionality techniques that you will find in the industry used in the data science used in data analytics machine learning even in the Deep learning so Matrix factorization can also be used to reduce the computational complexity by making use of this factorization we can then simplify the process and also make it more efficient for computation and it’s especially in important when we are dealing with this High dimensional data when we have many features or we have a very large model and complex model then this uh metric factorization technique can make a huge difference in our data processing process so these techniques underpin many algorithms in numeric analysis in optimizations and Beyond so whenever it comes to machine learning or data science or many other fields you will this uh process and this term Matrix authorization appearing a lot even um in the example of a streaming company Netflix which I’m sure that you are aware of Netflix is using uh metrix uh factorization to build a recommender system and uh metrix authorization usage in building recommender algorithm for personalized recommendations is actually one of the most popular applications of metrix factorization therefore I wanted to specifically discuss this to as part of our Advanced linear algebra course and some of the concepts might seem bit more complex than the ones that we have discuss as part of the previous units but once we go through them step by step and I will give you all the details in all these examples this entire process of these different metrix factorization techniques should become much more clear and straightforward so we will be discussing not just one but multiple fundamental metrix factorization techniques beside of talking the high level where they are used and how you can choose for what type of applications so we are going to demystify this entire concept of Matrix factorization and we are going to uh start from high level then we are going to go into the deepest details let’s now formally Define the metrix factorization so metrix factorization refers to decomposing a matrix into product of two or more matrices revealing its structure and simplifying further analysis so what is this idea behind metrix factorization the idea is that if we have a matrix a and we want to simplify our process of calculation or multiplication anything that’s related to this a but this a in itself it contains this weird numbers or it is just too complex you know it contains this ton of different numbers you don’t recognize where the columns are linearly independent it’s not very readable from the first View and you just want to make your life easier when performing this calculation well for that you can make use of this Matrix factorization to write this a in terms of some other matrices let’s say um and I’m calling here randomly Q or t so it’s equal to for instance the dotproduct of these two matrices Q * T where Q is much simpler and the t is also much simpler so those may contain vectors that are um for instance this can be a diagonal matrix or it can be a matrix uh with specific properties when using those you will feel much more comfortable so it will be easier for you to use them in order to multiply uh with other matri matrices it can be easier for you to solve this problem but of course if you are in the two dimensional space let’s say you are in R2 or in R3 then most likely it will be quite straightforward for you to use the a itself but if you are in the r 100 or r 1000 then of course this uh entire computations they become super complex it will be difficult to understand and compute this linear combinations find out whether you are dealing with a linearly independent columns find out um the um no space the column space the basis of the new space and cumn space and all this they might seem uh much more difficult when you are in high dimensional space for in those cases we can then make use of metrix factorization to make the entire process much more simplified and also more efficient this entire calculation process so common types of Matrix factorization include lower upper uh Matrix factorization or in short Lu QR factorization and INF famous type of factorization ation which is called orthogonal triangular factorization and then we have SVD singular value de composition yet another in famous metrix factorization and then finally the igon dec composition also another Super popular metrix factorization technique so uh the QR SVD and IA de composition are in fact highly popular the composition and Metric factorization techniques that you will see appearing in the 90% of all the statistics related and machine learning related books so this just comes to prove how important these concepts are when it comes to properly learning and mastering these more applied uh science related fields like machine learn so if you want to go beyond the level of knowing algorithms but rather than to also be able to edit the algorithms tweak them adjust them be able to understand machine learning algorithms deep learning algorithms data science at its core and in order to become a professional well-rounded professional then this I composition the singular valid composition and the QR metrix authorization techniques are techniques that you want to know and you want to understand at least higher level such that you can easier grasp more more advanced concepts that come from the applied sciences like machine learning and AI so let’s first discuss that high level what this QR decomposition is so what the QR DEC composition does is that it decomposes a matrix into an orthogonal Matrix which we are referring by q and then an upper triangular Matrix R so in here you can see that we have this two different matrices so we are basically saying a is equal to this product of this Matrix q and R where the first one this Matrix Q this one should be orthogonal Matrix so this part is really important and we have learned as part of the previous module the definition of orthogonal Matrix we learned that the rows or columns they had to be or Al to each other and we also learned that they need to have a length of one they need to um be normalized and we learned that this means that the transpose of those matrices is equal to the inverse of this matrices so this was just the last part of the previous module and this is exactly what this Matrix Q is about so we are saying that we will decompose I into these two matrices as a product of these two matrices q and R one of which this Matrix Q should be uh an nutal Matrix which means the rows and the columns they should be orthogonal to each other so their uh dot product each of them should be equal to zero and they need to be normalized so the length of them should be one for each of those rows and vectors and then the second part of this U the composition is this Matrix R which says that the Matrix R should be an upper triangular Matrix and what is the definition of upper triangular well in this case you can think of this r as this Matrix where we have here all zeros and then here on the diagonal you have numbers nonzero numbers and then here let’s say 1 2 3 4 five and then here in the upper part you will also have numbers so unlike in the lower part part of this Matrix R where you will have zeros in here you will have also n Zer numbers numbers let’s say 7even 10 uh 8 and I’m just writing these numbers randomly so of course in the real case when we have this Matrix a and we go through this process of QR de composition of course we will have an appropriate q and appropriate R where these numbers will be different and they will be specific numbers that will will will be calculating but the idea is that we need to get this upper triangular Matrix R for this calculation to make sense so we will then be using this qard composition for solving linear um linear Le squares problems for instance which is part of the linear regression too because linear regression from machine learning and from statistics uh it is based on the least Square technique the estimation technique that we are using for linear regression in machine learning um to solve this linear regression problem is called Ordinary Le squares so the algorithm is based on this idea of Le squares which is trying to minimize squared uh residuales of the model and that can be done by using this idea of QR the composition so it helps us to provide numerically stable solutions for this type of problems too and QR de composition is used extensively in Signal processing and statistical analysis let’s now briefly talk about the Lu decomposition so Lu DEC composition decomposes a matrix into lower triangular Matrix so this is the opposite of what we had before we can have an upper triangular triangular Matrix like we had in the QR the composition we can also have a lower triangular Matrix so you might have already guessed how it will look like I won’t go into that very soon in the QR composition example you will see the idea of the upper triangular I will also show the idea of a lower triang so the composition in case of Lu uh is done by decomposing a matrix into lower triangular Matrix l and an upper triangular Matrix U so basically the difference between the QR de composition and L de composition is that in the QR DEC composition we are decomposing a matrix into orthogonal Matrix and an upper triangular Matrix while in case of L decomposition we are decomposing a matrix into lower triangular Matrix and an upper triangular Matrix so here you can see that we no longer have this idea of orthogonal matrix but instead of that we are talking about lower triangle Matrix so in that aspect uh L DEC composition is different from QR DEC composition so what the Lu DEC composition does is that it facilitates the solving of linear equations and Matrix inversions it is common in engineering and in physical sciences for systems of this linear equation to be solved by using lud de composition and in fact if you are learning Quantum uh mechanics that this Lu decomposition can definitely help you to better understand many Concepts but if your target fields are machine learning deep learning or artificial intelligence then for those using QR de composition will be uh much more often a case than using this L de composition let’s now talk about the singular value de composition so what the VD does is that it decomposes a matrix into three matrices so first one is the orthogonal Matrix U the second one is a diagonal matrix and then the third one is this V Star which is the conjugate transpose of an orthogonal Matrix so for now this might seem bit complex and you can see that unlike the QR or Lu de composition where we got just uh two uh matrices as a result of our de composition in case of SD we got three matrices like the name suggest two by the way so three parts and this might seem bit complex but we are going to go through this process step by step and I’m going to provide you detailed example such that this will all make sense but for now let’s focus at the highight level usage of SVD so singular value decomposition is one of the most popular decomposition techniques and it is also directly used as part of machine learning algorithms to form uh those machine learning algorithms it is also used in the data compression in the noise reduction so when we are trying to clean our data and remove the Noise by using SVD because SVD can help us to identify those outliers and then remove them from the data by performing noise reduction and it is also used in the principal component analysis the PCA the uh same dimensionality reduction technique that I just uh mentioned related to Theon de composition because SVD and the ion de composition are highly related to each other so this SVD is used as part of this PCA algorithm and PCA is the most popular the infamous dimensionality reduction technique that is used both in the advanced statistical studies in the statistics in general also in finance and is also used as part of many machine learning and deep learning applications so knowing PCA is a must if you want to get into uh data analytics or data science machine learning and AI but also uh it helped you it will help you also to uh understand uh many other Concepts when it comes to these fields so the SVD provides insight into the structure but also the rank of the Matrix so we are going to see this as part of our example two let’s now also briefly talk about the igon de composition so igon de composition which is highly related to these concepts of igon values and igon vectors it decomposes a matrix into this igon values and ion vectors which then shows the matrices fundamental properties which are related to this idea of correlation what kind of information does this uh Matrix contain what is the variation in what direction is the variation the largest and this ion de composition which is then related to also this idea of SVD and in general this dimensions and correlations is critical for understanding linear Transformations the stability analysis and systems of differential equations but beside this uh mathematical side of uh Concepts and understanding these mathematical topics the ion de composition is also the basis for many algorithms in numerical linear algebra uh but also many applied linear algebra topics like in the data science in machine learning and is used heavily in artificial intelligence for feature extraction for dimensionality reduction related again to the concept of PCA because PCA is based entirely on this concept of I their composition PCA is the direct result of computing the igon values and ion vectors so without knowing what our Dion values and icon vectors you cannot perform PCA because the first step of the PCA is the computation of the icon values and ion vectors and then using different rules which we are referring as the elbow rule or Ka rule we can then use these icon values and icon vectors to understand what are the features in our data that contain the most variation so the most information and then we can use that in order to understand what are the most important features in our data and reduce the dimension of our model by selecting these most important features because what PCA basically does is that it it uses this icon values and icon vectors to understand how we can uh create a linear combination out of our features and understand the the amount of those linear combinations that contain the most variation and then select those and uh select the largest amount of information in the data and then Skip and drop those uninformative being your combinations while still keeping the most information and this definition of the most will then be decided by this differ ruls this is just higher level Insight background information on what you can expect when you are talking about applying this highly technical linear algebra concept of ion de composition into an applied science Fields like data science or machine learning or AI but we will see this later and I’ll also make comments regarding this and though PCA won’t be discussed as part of this course because here we are talking about linear algebra but PCA is part of the fundamental statistics course and in there we are no longer providing all these different details on how you can uh perform this ion composition therefore knowing how to perform I and composition will then set you for success to actually understand the mathematics behind the statistical Concepts like PCA and also later on understand how you can use that PCA in a machine learning Concepts and in AI Concepts like outter encoders and how you can relate your um Auto encoders to this concept of PCA how they are related what are their commonalities and what are their differences so everything is about the choice and choosing the right tool for your problem when it comes to the decomposition tools metrix factorization tools we have seen that there are many options and the the question is which one should we pick in what cases so choosing the right tool is really important when it comes to this different metric factorization techniques because there are many choices and each of them they can be used for different sorts of problems so therefore in order to understand which one you need to pick in what kind of cases what kind of requirements you have and what kind of Sol uh problem you are trying to solve that in those cases you will need to have this knowledge that you learn as part of this course in order to make that right choice of the tool so the choice among QR de composition the L de composition the SVD and igen de composition it really depends on your specific problems requirements and the data characteristics so are you dealing with a complex data are you dealing with a simple data with low Dimensions what is the goal that you uh want to uh achieve what is the problem that you are trying to solve is it to uh reduce the dimension of your feature space is it to solve a problem with linear equations is it to solve a quantum mechanics problem or is it to um incorporate this as part of your machine learning algorithm so QR and LU DEC compositions are usually preferred for solving linear systems while SVD and I and compositions they help us for deeper insights when it comes to the data and what kind of information it contains how we can reduce the dimension of the data or how we can use it as part of machine learning algorithm for noise reduction identifying outliers Etc so um this type of algorithms like SVD and ion de composition it helps us to also uh intuitively using geometry and our knowledge of geometry to um visualize the data for instance the PCA helps us to visualize this High dimensional data using just couple of principal components let’s say we have 10 features in our model so we have a dimension of 10 we are in r10 but we want to visualize our data by using PCA we can then reduce the dimension and come up with uh three principal components which are linear combination of our original 10 vectors and then we can use the three principal components to VIs visualize our data in 3D and this basically helps us to geometrically visualize our data and then make presentations make much more sense of our story so to do uh storytelling for our data and uh much more and these two uh models and tools they are invaluable when it comes to uh applications in machine learning in deep learning in data science and artificial intelligence so so matric factorization techniques they are super important when it comes to computational mathematics they are also directly affecting the data science Ai and many other algorithms so they are not only important in terms of the problem that they are trying to solve but also in order to make the computation process so when coding in python or in other programming languages to make that process much more efficient they also help us to uh make these computations efficient and provide insights into different properties that we have in our data as part of this course we are not only going to discuss one but actually three of these four the composition techniques and this metrix factorization techniques in detail we are going to talk about the qard de composition we are going to not just discuss it but uh also to learn it step by step and we are going to do a detail example with all this steps involved such that you will feel confident doing a QR de composition all by yourself then we are also going to do an SVD DEC composition as well as igon DEC composition and then we are again going to discuss them in terms of their mathematical formulation the definition but also the application stepbystep process and a detailed example such that you can conduct each of those metrix factorization techniques and these decomposition techniques by yourself manually doing all these calculations this understanding and this examples and this Concepts will help you to not just be able to formulate what these techniques are about but really and truly understand and then use them later on whether when doing your own research writing scientific papers or tweaking the algorithm all by yourself when inventing new algorithms I won’t be discussing this L de composition technique because we already know uh that the QR and LU they are both used for similar type of problems therefore to save us time I have selected carefully the uh most important the composition techniques and metrics soriz techniques that you will most likely be dealing with will be dealing with in your future career in applied sciences

    By Amjad Izhar
    Contact: amjad.izhar@gmail.com
    https://amjadizhar.blog

  • SQL for Data Analysis: Pivoting, Stats, Segmentation, Views, and Optimization

    SQL for Data Analysis: Pivoting, Stats, Segmentation, Views, and Optimization

    The initial source, “01.pdf,” details an investigation of a database schema, focusing on understanding table relationships and performing revenue calculations. It demonstrates how to join tables to incorporate customer and product information, filter data for recent sales, and categorize customers based on revenue using case statements. The subsequent sections introduce the concept of pivoting data using aggregation and case statements, illustrating techniques for analyzing customer counts by region and calculating net revenue across different categories and years. Further content explores statistical functions within pivoting for median sales analysis and advances into segmentation using multiple conditions within case statements for detailed revenue breakdowns. The final portion of the provided text transitions into date calculations, covering functions like date_trunc and date_part for time series analysis, extracting date components, and using intervals and the age function to analyze processing times. This culminates in an introduction to window functions, explaining their syntax and application in calculations over partitions of data without collapsing rows, including ranking and running aggregates, and finally examining frame clauses for controlling the data within a window.

    Source Material Study Guide

    Quiz

    1. Explain the purpose and importance of the %sql magic command in the provided text. What happens if you try to run a SQL query without it?
    2. Describe what magic commands are in the context of the source material. Give at least two examples of magic commands mentioned besides %sql and explain their function.
    3. What is the Contoso database, and what are some of the key tables within it that are discussed in the excerpts? Briefly describe the purpose of the Sales, Customer, and Date tables.
    4. Explain how net revenue is calculated in the context of the Sales table. What columns are used in this calculation, and why is net price used instead of unit price?
    5. Describe the process of joining tables in SQL as demonstrated in the excerpts. What type of join is frequently used, and on what columns are the tables typically joined in the examples?
    6. What is a CASE WHEN statement, and how is it used in the provided text? Give an example of how it’s used to categorize data within a SQL query.
    7. Explain the concept of pivoting data as introduced in the “pivoting with case statements” section. How is the COUNT(DISTINCT CASE WHEN … END) syntax used to achieve this?
    8. Describe the DATE_TRUNC and EXTRACT functions as explained in the text. What are they used for, and what are some examples of date parts that can be extracted?
    9. Explain the purpose and basic syntax of a Common Table Expression (CTE). How are CTEs used to structure more complex SQL queries in the examples provided?
    10. Briefly describe the functionality of window functions as introduced in the excerpts. How do they differ from aggregate functions with a GROUP BY clause?

    Quiz Answer Key

    1. The %sql magic command is crucial for indicating to the Jupyter Notebook environment that the subsequent lines of code should be interpreted and executed as SQL queries. Without it, the code will be treated as regular Python code, leading to syntax errors and incorrect execution.
    2. Magic commands are special commands in the Jupyter Notebook environment that extend its functionality. Besides %sql, examples include %timeit which measures the execution time of the next line of code, and single % followed by Python code which executes that line as Python without timing.
    3. The Contoso database is the data set used throughout the course. Key tables discussed include Sales (containing transaction information like price and quantity), Customer (containing customer details like name and location), and Date (intended for date-based aggregations but later suggested to be ignored for learning date functions).
    4. Net revenue is calculated by multiplying the quantity of a product by its net price and the exchange rate. The net price is used because it represents the actual price charged to the customer after all discounts and adjustments.
    5. Joining tables combines rows from two or more tables based on a related column. Left joins are frequently used to keep all rows from the left table and matching rows from the right table. Tables are typically joined on key columns like ProductKey, CustomerKey, and date columns.
    6. A CASE WHEN statement allows for conditional logic within a SQL query, enabling the assignment of different values based on specified conditions. For example, it’s used to categorize customers as “high” or “low” value based on their net revenue.
    7. Pivoting data transforms rows into columns. The COUNT(DISTINCT CASE WHEN condition THEN column END) syntax is used to count the distinct occurrences of a specific column based on whether a certain condition is met, effectively creating new columns for each category.
    8. DATE_TRUNC extracts a specified date part (e.g., month, year) from a date, while EXTRACT similarly retrieves a part of a date. They are used for analyzing data based on different time granularities. Examples of extractable parts include ‘year’, ‘month’, ‘day of week’.
    9. A Common Table Expression (CTE) is a temporary, named result set defined within the scope of a single query. CTEs are used to break down complex queries into smaller, more manageable, and readable parts, often used before a final SELECT statement or when joining to the same subquery multiple times.
    10. Window functions perform calculations across a set of table rows that are related to the current row, but unlike aggregate functions with GROUP BY, they do not collapse the rows into a single output row. They allow for calculations like running totals, rankings, and averages within partitions of data.

    Essay Format Questions

    1. Discuss the importance of using magic commands in the context of interactive SQL querying within a Jupyter Notebook environment. How do they facilitate the integration of SQL with other programming languages like Python, as suggested in the excerpts?
    2. Analyze the strategy of exploring the Contoso database by examining individual tables (Sales, Customer, Date) and then combining them through joins. What are the benefits and potential challenges of this approach to understanding a new database schema?
    3. Evaluate the use of CASE WHEN statements in SQL for data categorization and pivoting, as demonstrated in the source material. Provide examples of scenarios where these techniques would be particularly valuable for data analysis and reporting.
    4. Compare and contrast the DATE_TRUNC and EXTRACT functions for manipulating date data in SQL. In what situations might one function be preferred over the other, and how do they contribute to more effective time-based analysis?
    5. Explain the role and advantages of using Common Table Expressions (CTEs) in writing complex SQL queries. How do CTEs improve query readability and maintainability, and can you provide a hypothetical example (based on the source material) where a CTE would significantly simplify a query?

    Glossary of Key Terms

    • Magic Command: Special commands in interactive environments like Jupyter Notebooks that provide extra functionality beyond the standard language syntax (e.g., %sql, %timeit).
    • SQL: Structured Query Language, a standard language for accessing and manipulating databases.
    • Jupyter Notebook: An interactive web-based environment for creating and sharing documents that contain live code, equations, visualizations, and narrative text.
    • Database: An organized collection of structured information, or data, typically stored electronically in a computer system.
    • Table: A structure within a database that organizes data into rows and columns.
    • Column: A vertical attribute or field in a table, containing a specific type of data for each record.
    • Row: A horizontal record in a table, representing a single instance or entry.
    • Query: A request for data or information from a database.
    • Syntax: The set of rules that govern the structure and format of statements in a programming or query language.
    • Autocomplete: A feature where the environment suggests or automatically completes code as the user is typing.
    • Syntax Error: An error in the structure or grammar of a statement that prevents it from being correctly interpreted.
    • Execution Time: The amount of time it takes for a program or query to run and complete.
    • Net Revenue: The actual revenue received after accounting for discounts, returns, and other adjustments.
    • Unit Price: The standard price of a single unit of a product before any discounts or adjustments.
    • Quantity: The number of units of a product.
    • Join: An SQL operation that combines rows from two or more tables based on a related column.
    • Left Join: Returns all rows from the left table and the matching rows from the right table. If there’s no match in the right table, NULLs are used for the columns of the right table.
    • Alias: A temporary name given to a table or column in a query to make it easier to refer to.
    • CASE WHEN Statement: A conditional expression in SQL that allows for different results based on specified conditions.
    • Pivoting: A data transformation technique that rotates rows into columns.
    • Aggregation: The process of summarizing data using functions like COUNT, SUM, AVG, MIN, and MAX.
    • DATE_TRUNC: An SQL function that truncates a timestamp or date value to a specified precision (e.g., day, month, year).
    • EXTRACT: An SQL function that retrieves a specific component (e.g., year, month, day) from a date or timestamp value.
    • CAST: An SQL operator used to change the data type of an expression.
    • Common Table Expression (CTE): A temporary, named result set defined within the execution of a single SQL statement.
    • Window Function: An SQL function that performs a calculation across a set of table rows that are related to the current row, without collapsing the rows.
    • Partition By: A clause used with window functions to divide the rows into partitions within which the function is applied.
    • Order By: A clause used to sort the rows within a result set or within a window function’s partition.

    Jupyter, SQL, and Database Exploration with PostgreSQL

    ## Briefing Document: Analysis of Provided Sources

    This briefing document summarizes the main themes and important ideas presented in the provided excerpts from “01.pdf”. The excerpts cover a range of topics related to using Jupyter Notebooks with SQL, exploring a database (Contoso), performing various SQL operations (including joins, aggregations, window functions, pivoting, date manipulation, and query optimization), and finally, setting up a local PostgreSQL environment with tools like pgAdmin and DBeaver for more robust database interaction and project management.

    **Main Themes:**

    1. **Introduction to Jupyter Notebooks and SQL Integration:** The initial sections focus on using Jupyter Notebooks with SQL through “magic commands” like `%sql`. This integration allows for writing and executing SQL queries directly within a Python environment.

    * **Key Idea:** The `%sql` magic command is crucial for executing SQL within a Jupyter Notebook cell. Without it, SQL syntax will be highlighted as incorrect and will result in errors.

    * **Quote:** “very important that you put these magic commands up at the top now so people don’t think i’m crazy magic commands are the actual official language of this”

    * **Key Idea:** Jupyter Notebook also supports other magic commands like `%timeit` for measuring code execution time, demonstrating the versatility of the environment. Single `%` applies the command to one line, while `%%` can apply to an entire cell (though not explicitly shown in the excerpt).

    2. **Exploring the Contoso Database Schema:** The sources introduce the Contoso database as the primary dataset for the course. The excerpts detail the exploration of key tables like `Sales`, `Customer`, and `Date`.

    * **Key Idea:** Understanding the relationships between tables (e.g., `Date` table related to `Sales` via date columns, `Customer` and `Product` tables linked to `Sales` via keys) is fundamental for querying and analysis.

    * **Quote:** “last table to explore is that date table this is related using that date column here to the sales table order date and delivery date.”

    * **Key Idea:** The `Date` table, while useful for quick filtering in tools like Power BI, will be largely ignored in the course in favor of learning more flexible date functions in SQL.

    3. **Performing Fundamental SQL Operations:** The excerpts illustrate core SQL concepts such as calculating net revenue, joining tables to combine data from different entities, and using aliases for tables and columns.

    * **Key Idea:** Net revenue is calculated as `quantity * net_price`. The `net_price` already accounts for discounts and promotions.

    * **Quote:** “the net price is the price after all the different discounts promotions or any adjustments so basically it’s what we actually charge to the customer when they pay for the product”

    * **Key Idea:** `LEFT JOIN` is used to combine tables while ensuring all rows from the left table are included. Aliases (e.g., `s` for `Sales`, `c` for `Customer`, `p` for `Product`) improve query readability.

    4. **Introduction to Pivoting Data with `CASE` Statements:** The sources introduce the concept of pivoting data, transforming rows into columns. This is achieved using `CASE WHEN` statements combined with aggregation functions like `COUNT` and `SUM`.

    * **Key Idea:** `CASE WHEN` allows for conditional logic within SQL queries, enabling the creation of new categories or columns based on existing data.

    * **Quote:** “we’re going to be using statements like case when and aggregation in order to pivot data but what the heck is pivoting data let’s take a look at this simple example”

    * **Key Idea:** Pivoting can be used to create summary tables where values from one column become headers in the output.

    5. **Date Manipulation with Functions like `DATE_TRUNC` and `TO_CHAR`:** The excerpts demonstrate how to extract specific parts of a date (e.g., month, year) using functions like `DATE_TRUNC` and `EXTRACT`, and how to format dates into desired string representations using `TO_CHAR`. Casting data types (e.g., to `DATE`) is also shown.

    * **Key Idea:** `DATE_TRUNC` allows truncating a date to a specified level of precision (e.g., month).

    * **Quote:** “specifically if you just want to specify one attribute you want to extract out of it such as something like month as we did you could either do quarter year decade century or even millennium”

    * **Key Idea:** `TO_CHAR` provides more flexible date formatting options using various format codes.

    6. **Introduction to Window Functions:** A significant portion of the excerpts is dedicated to introducing window functions. These functions perform calculations across a set of rows that are related to the current row, without collapsing the rows like `GROUP BY`.

    * **Key Idea:** Window functions use the `OVER()` clause to define the “window” of rows for the calculation. `PARTITION BY` divides the data into groups, and `ORDER BY` orders the rows within each partition.

    * **Quote:** “they let you perform calculations across a set of tables related to the current row…and like we showed they don’t group the results into a single output row this is very beneficial as we’re going to demonstrate some future exercises”

    * **Key Idea:** Examples include calculating running totals, ranks (`ROW_NUMBER`, `RANK`, `DENSE_RANK`), and moving averages using frame clauses (`ROWS BETWEEN …`).

    7. **Lag and Lead Functions:** The excerpts introduce `LAG` and `LEAD` functions, which allow accessing data from previous or subsequent rows within a window partition. This is useful for calculating differences or growth rates over time.

    * **Key Idea:** `LAG(column, offset, default)` retrieves a value from a row `offset` rows before the current row. `LEAD` works similarly for subsequent rows.

    * **Quote:** “these type of things in a window function allow us instead of looking at the current row to allow us to look at things like the row above it or the row below it”

    8. **Frame Clauses in Window Functions:** The sources explain how frame clauses (`ROWS BETWEEN`) within the `OVER()` clause can further define the set of rows to be considered for a window function calculation (e.g., a moving average over the preceding three months). `CURRENT ROW`, `PRECEDING`, and `FOLLOWING` are key keywords.

    * **Key Idea:** Frame clauses allow for flexible calculations based on a sliding window of rows.

    * **Quote:** “this allows us to specify a physical offset from the current row such as maybe the three preceding rows or maybe the two following rows”

    9. **Setting Up a Local PostgreSQL Environment:** The later excerpts transition to setting up a local PostgreSQL database, including installing the server and pgAdmin (a GUI administration tool).

    * **Key Idea:** Having a local database environment allows for more hands-on practice and development without relying on remote systems.

    * **Key Idea:** pgAdmin is used for managing the PostgreSQL server, creating databases, running queries, and exploring the database schema.

    10. **Introducing DBeaver as an Alternative Database Tool:** DBeaver is introduced as a more versatile database management tool that can connect to various database systems, unlike pgAdmin which is specific to PostgreSQL.

    * **Key Idea:** DBeaver offers a more comprehensive set of features for database development and administration, including project management, SQL editing enhancements (auto-completion, formatting), and data export/visualization capabilities.

    * **Quote:** “dbeaver now this is a database management tool so can only connect to different [types of databases]”

    11. **Project Management in DBeaver:** The excerpts demonstrate how to create projects in DBeaver to organize SQL scripts, bookmarks, and other related files. This helps in structuring database development work.

    12. **Introduction to Views:** Views are introduced as virtual tables that represent the result of a stored query. They simplify complex queries and provide a level of abstraction over the underlying tables.

    * **Key Idea:** Views are created using the `CREATE VIEW` statement and can be queried like regular tables.

    * **Quote:** “it’s a virtual table that allows us to show the results of a stored query in it”

    13. **Introduction to VS Code for Project Development:** VS Code is presented as a powerful code editor, not just for SQL but also for creating and managing project documentation (like README files in Markdown). Its preview capabilities for Markdown are highlighted.

    * **Key Idea:** VS Code, with its extensions, provides a robust environment for both code (SQL) and documentation.

    14. **Query Optimization with `EXPLAIN` and `EXPLAIN ANALYZE`:** The final excerpts touch upon basic query optimization by introducing the `EXPLAIN` and `EXPLAIN ANALYZE` commands, which provide insights into the query execution plan and performance.

    * **Key Idea:** `EXPLAIN` shows the planned steps the database will take to execute a query. `EXPLAIN ANALYZE` actually executes the query and provides timing information.

    * **Quote:** “explain demonstrates the execution plan without actually executing it whereas explain analyze basically means like it’s going to analyze it and it actually does execute it”

    **Most Important Ideas and Facts:**

    * Jupyter Notebooks can seamlessly integrate with SQL using magic commands like `%sql`.

    * The Contoso database is the central dataset for learning SQL concepts.

    * Understanding table relationships is crucial for effective querying.

    * `CASE WHEN` statements are essential for conditional logic and data pivoting.

    * Window functions provide powerful analytical capabilities without collapsing rows, enabling calculations like running totals, rankings, and moving averages.

    * `LAG` and `LEAD` functions allow for comparisons between rows.

    * Frame clauses in window functions define the scope of rows for calculations.

    * Setting up a local PostgreSQL environment with pgAdmin and DBeaver provides a robust platform for database learning and project development.

    * DBeaver is a versatile database tool supporting multiple database systems.

    * Views simplify queries and provide abstraction.

    * VS Code is a valuable tool for both SQL development and project documentation (using Markdown).

    * `EXPLAIN` and `EXPLAIN ANALYZE` are used to understand and optimize SQL query execution.

    These excerpts lay a comprehensive foundation for learning intermediate SQL concepts, ranging from basic query structures and database exploration to advanced analytical functions and development environment setup. The progression through Jupyter Notebooks to local database tools like PostgreSQL and DBeaver indicates a move towards more practical and real-world database interaction and project management.

    Exploring Data with SQL Magic and the Contoso Database

    1. What is the purpose of the %sql magic command in the provided context?

    The %sql magic command is essential for executing SQL queries within the environment (likely a Jupyter Notebook). When placed at the beginning of a cell or line, it signals to the interpreter that the subsequent text should be treated as a SQL query to be run against the connected database. Without this command, the SQL syntax would be misinterpreted, leading to errors. Using two percent signs (%%sql) applies the command to the entire cell, while a single percent sign (%sql) applies it only to the current line.

    2. Beyond SQL, what other types of “magic commands” are mentioned and what is their general function?

    The text mentions that %sql is not the only magic command available. It specifically highlights the %timeit magic command as an example. The general function of these magic commands is to provide additional functionalities and tools within the coding environment, such as measuring the execution time of code (%timeit) or facilitating interaction with external systems or specific languages (like SQL with %sql).

    3. What is the Contoso database and what are some of the key tables within it that are explored in the excerpts?

    The Contoso database is the primary dataset used throughout the lessons. The excerpts introduce and explore several key tables: – Sales: This table contains transactional data, including information about orders, quantities, net prices (prices after discounts), and order dates. It’s central to calculating revenue. – Customer: This table holds information about customers, such as their given name, surname, country, continent, and customer key. – Product: This table contains details about the products being sold, including product key, product name, category name, and subcategory name. – Date: This table contains various date-related attributes that can be used for aggregation and filtering based on dates, although the course later emphasizes using date functions instead of relying solely on this table.

    4. How is “net revenue” calculated within the context of the Contoso database, and why is it considered important?

    Net revenue is calculated by multiplying the quantity of a product sold by its net price (the price after all discounts and adjustments) and the exchange rate. It is considered important because it represents the actual revenue received from customers after accounting for discounts and promotions, reflecting the true value of sales transactions.

    5. What is “pivoting data” as described in the excerpts, and how is it achieved using SQL?

    Pivoting data involves transforming rows into columns. The example provided shows how to take customer counts grouped by continent (originally in rows) and restructure the output to have each continent as a separate column displaying the total customer count for that continent. This is achieved using aggregate functions (like COUNT DISTINCT) combined with CASE WHEN statements to conditionally assign values to the new columns based on the continent.

    6. What is the purpose of the DATE_TRUNC and EXTRACT functions when working with dates, and how do they differ from the TO_CHAR function?

    • DATE_TRUNC is used to truncate a date to a specified level of precision, such as month, quarter, or year. It returns a timestamp or date with the less significant parts set to the beginning of the time period (e.g., the first day of the month).
    • EXTRACT is used to retrieve a specific component from a date or timestamp, such as the year, month, or day. It returns a numeric value representing that part.
    • TO_CHAR is used to format a date or timestamp as a text string according to a specified pattern. This allows for flexible output formats, such as extracting the month name or formatting the date in a particular way.

    While DATE_TRUNC and EXTRACT help in manipulating and retrieving date parts for analysis or grouping, TO_CHAR focuses on presenting date information in a desired textual format.

    7. What are “window functions” and how do they differ from standard SQL aggregate functions? What are some examples of window functions discussed in the excerpts?

    Window functions perform calculations across a set of rows that are related to the current row, without collapsing the rows into a single output row like standard aggregate functions (e.g., SUM, COUNT, AVG) do. They allow you to access and perform calculations on a “window” of data defined by a PARTITION BY clause (dividing the data into groups) and an ORDER BY clause (specifying the order within each partition).

    Examples of window functions discussed include: – Aggregate functions used as window functions (e.g., AVG() OVER (…)). – Ranking functions (ROW_NUMBER(), RANK(), DENSE_RANK()). – Value functions (FIRST_VALUE(), LAST_VALUE(), NTH_VALUE(), LAG(), LEAD()). – Percentile functions (PERCENTILE_CONT()).

    8. What is “cohort analysis” as demonstrated in the excerpts, and what kind of insights can it provide about customer behavior?

    Cohort analysis involves grouping users or customers based on a shared characteristic, typically the time they acquired a product or service (their “cohort year” or “first purchase date”). It then tracks their behavior over time. The excerpts demonstrate cohort analysis by examining how different cohorts of customers contribute to total revenue and customer retention in subsequent years. This can provide insights into customer lifetime value, the effectiveness of acquisition strategies over time, and customer churn patterns by showing how engagement and spending change for different initial groups of customers.

    SQL for Data Exploration: A Course Overview

    Based on the sources, data exploration within the context of this SQL course for data analytics appears to be a crucial initial step involving understanding the structure and content of a database using SQL queries and visualization techniques.

    Here’s a breakdown of data exploration as presented in the course:

    • Understanding the Database Structure: The course emphasizes the importance of getting familiar with the database schema, which includes identifying the different tables and understanding how they relate to each other. The Entity Relationship Diagram (ERD) of the “cantazo” database is introduced as a tool to visualize these relationships, particularly how dimensional tables like store, product, and customer relate to the main fact table, sales.
    • Examining Tables and Columns: Data exploration involves inspecting individual tables to understand the columns they contain and the types of information stored in them. This is demonstrated by using SQL queries like SELECT * FROM sales LIMIT 10 to view the first few rows and identify the available columns such as dates, customer key, store key, product key, quantity, price, cost, and currency information.
    • Exploring Metadata: The course also shows how to query the information schema, a meta-database, to discover the tables within a database and the columns within each table. Specifically, it demonstrates using SELECT table_name FROM information_schema.tables WHERE table_schema = ‘public’; to list the tables and SELECT * FROM information_schema.columns WHERE table_name = ‘customer’; to see all the column names in the customer table.
    • Using SQL for Initial Analysis: Simple SQL queries are used to get a first look at the data and its characteristics. For example, selecting all columns from a table and limiting the number of rows allows for a quick overview of the data’s format and values.
    • Leveraging Tools for Exploration: The course utilizes Google Colab in the first half, which allows for running SQL queries and provides features like converting query results to interactive tables and generating visualizations. The integration with Gemini AI is also mentioned as a way to assist in generating SQL queries for data exploration. Later in the course, pgAdmin and DBeaver are introduced as more advanced database tools that allow for visual exploration of the schema, tables, and data. DBeaver, in particular, is highlighted for its ability to view table data in a grid format and examine ER diagrams.
    • Understanding Data Relationships through Joins: As part of data exploration, the course demonstrates how to use JOIN clauses (specifically LEFT JOIN) to combine data from multiple related tables, such as sales, customer, and product, to understand how different entities interact and to bring together relevant attributes for analysis.
    • Identifying Key Fields: The initial exploration helps in identifying key fields that will be important for further analysis, such as the different keys used to relate tables and the metrics (e.g., quantity, net price) available for calculations like net revenue.

    In essence, data exploration in this course lays the foundation for more advanced data analytics by ensuring a solid understanding of the available data, its structure, and its basic characteristics through the use of SQL and database exploration tools. This initial phase is crucial for formulating meaningful analytical questions and developing effective SQL queries for deeper insights.

    SQL for Time Series: Date Calculations

    Based on the sources, this SQL course includes a chapter dedicated to date calculations, emphasizing their importance for time series analysis. The course covers several key date and time functions and keywords:

    • DATE_TRUNC() Function: This function allows you to truncate a timestamp down to a specified level of precision, such as year, quarter, month, week, day, hour, etc.. For example, DATE_TRUNC(‘month’, order_date) extracts the month and year from the order_date. The output of DATE_TRUNC() is a timestamp, which can be cast to a DATE data type if needed using the ::date operator.
    • TO_CHAR() Function: This function provides a flexible way to format date and time values into strings based on various format patterns. You provide a timestamp or date and a format string to specify the desired output. For instance, TO_CHAR(order_date, ‘YYYY’) extracts the year, and TO_CHAR(order_date, ‘MM-YYYY’) extracts the month and year in the specified format. TO_CHAR() offers more customization compared to DATE_TRUNC() as you can combine different components in your desired order.
    • DATE_PART() Function: This function extracts a specific component from a date or timestamp, such as year, month, day, hour, minute, second, etc.. The syntax involves specifying the part you want (e.g., ‘year’, ‘month’) as a string and then the source date or timestamp. For example, DATE_PART(‘year’, order_date) extracts the year. The source mentions that the output might include decimals, which might not always be desirable.
    • EXTRACT() Function: Similar to DATE_PART(), EXTRACT() also retrieves a specific component from a date or timestamp. However, the syntax is slightly different: you specify the part (e.g., YEAR, MONTH, DAY) as an uppercase identifier followed by the keyword FROM and the date or timestamp. For example, EXTRACT(YEAR FROM order_date) extracts the year. The course prefers EXTRACT() over DATE_PART() for components like year, month, and day as it typically returns integer values without unnecessary precision.
    • CURRENT_DATE: This keyword returns the current date at the time the query is executed, based on the server’s time zone or a specified time zone (though specifying a time zone is optional if the default is sufficient).
    • NOW(): This function returns the current date and time (timestamp) at the moment the query is executed.
    • INTERVAL Keyword: The INTERVAL keyword is used to represent a span of time, which can be defined in units like days, months, years, hours, etc.. You can create an interval by using the keyword INTERVAL followed by a value and a unit (e.g., INTERVAL ‘5 year’, INTERVAL ‘6 month’). Intervals can be added to or subtracted from dates and timestamps for date arithmetic.
    • AGE() Function: This function calculates the difference between two timestamps or dates, returning the result as an interval. The order of the dates matters; AGE(end_date, start_date) will yield a positive interval. You can then extract specific components from the resulting interval, such as the number of days, using the EXTRACT() function.

    The course also demonstrates how these date functions are used in conjunction with other SQL clauses for analysis:

    • Filtering Dates with WHERE Clause: Date functions are commonly used in the WHERE clause to filter data based on specific date ranges or conditions. Examples include filtering orders within a specific year using EXTRACT(YEAR FROM order_date) = 2023 or finding orders within the last 5 years using order_date >= current_date – INTERVAL ‘5 year’.
    • Grouping by Date Components with GROUP BY Clause: Functions like DATE_TRUNC() or TO_CHAR() are useful for grouping data by specific time periods, such as monthly sales by grouping on DATE_TRUNC(‘month’, order_date) or TO_CHAR(order_date, ‘MM-YYYY’).
    • Ordering by Date with ORDER BY Clause: Dates can be used in the ORDER BY clause to sort results chronologically.
    • Calculating Time Differences: The AGE() function is used to calculate the duration between events, like the processing time of an order by finding the age between the order date and the delivery date.

    The importance of dynamic filtering using functions like CURRENT_DATE and INTERVAL is highlighted, as it allows for creating queries that automatically adjust based on the current time, such as always retrieving data for the last 5 years.

    SQL Course: Calculating Net Revenue

    Based on the sources, net revenue in this SQL course is consistently calculated by taking into account the quantity of items sold, the net price of each item, and the exchange rate if currency conversion is needed.

    Here’s a breakdown of the net revenue calculation process as described in the sources:

    • Net Price Defined: The net price is the price that the customer actually pays for a product after all applicable discounts, promotions, or adjustments have been applied. It is explicitly stated that the net price is less than the unit price due to these reductions.
    • Basic Calculation: The fundamental way to calculate the net revenue for a particular transaction is by multiplying the quantity of the product purchased by its net price. This can be represented as:
    • Net Revenue = Quantity * Net Price
    • Incorporating Exchange Rates: In the context of the “cantazo” database used in the course, the transactions may involve different currencies (e.g., pounds and US dollars). To standardize the revenue in a common currency (like US dollars, as the instructor prefers), an exchange rate is applied. The complete formula for net revenue used throughout the course is:
    • Net Revenue = Quantity * Net Price * Exchange Rate
    • This formula is used in various lessons when calculating total revenue, revenue by category, customer lifetime value, and for cohort analysis.
    • Example of Currency Conversion: Source provides an example where revenue figures are initially in pounds and then converted to US dollars by multiplying by an appropriate exchange rate.
    • Application in SQL Queries: The course demonstrates the use of this net revenue calculation within SQL SELECT statements, often with the result being aliased as net_revenue or total_net_revenue. This calculation is then used in aggregations with the SUM() function to find total revenues for different groupings of data (e.g., by order date, category, customer cohort).

    Therefore, to calculate net revenue in the context of this course and the “cantazo” database, you generally need to multiply the quantity of the products sold by their respective net prices, and then adjust for currency differences by multiplying by the relevant exchange rate. The course emphasizes that the net price already reflects any discounts or adjustments, representing the actual amount charged to the customer.

    Customer Segmentation: A Data-Driven Approach

    Based on the sources, customer segmentation is a key data analytics concept that involves dividing customers into distinct groups based on shared characteristics or behaviors. The goal of customer segmentation is to enable more targeted analysis and tailored strategies for different customer groups.

    Here are the main aspects of customer segmentation discussed in the sources:

    • Definition: Customer segmentation involves taking large datasets and breaking them down into smaller, more manageable pieces to analyze different behaviors within those groups. This allows for a deeper understanding of customer behavior and facilitates more effective decision-making.
    • Methods using CASE WHEN Statements: The course emphasizes using the CASE WHEN statement as a fundamental tool for customer segmentation. This allows for the creation of new columns that categorize customers based on specified conditions.
    • Simple Binary Segmentation: Customers can be segmented into two groups, such as “high value” and “low value,” based on a single criterion like net revenue threshold (e.g., above or below $1,000).
    • Segmentation by Multiple Conditions: More advanced segmentation can involve multiple conditions using the AND operator within a CASE WHEN statement. For example, segmenting customers based on a combination of the year of purchase and whether their net revenue is above or below the median.
    • Segmentation into Multiple Tiers: Customers can be divided into more than two segments (e.g., low, medium, high value) using multiple WHEN clauses within a single CASE block. This allows for a more granular understanding of customer value.
    • Segmentation based on Net Revenue and Spending: A primary method for customer segmentation in the course involves analyzing customer spending, often using net revenue as the key metric.
    • Segmentation using Percentiles: The course demonstrates segmenting customers into tiers (low value, mid value, high value) based on their total lifetime value (LTV) using percentiles (25th and 75th). Customers falling below the 25th percentile are categorized as “low value,” those between the 25th and 75th percentiles as “mid value,” and those above the 75th percentile as “high value”.
    • Purpose of Segmentation: The primary goals of customer segmentation highlighted in the sources include:
    • Identifying Valuable Customers: Understanding who the most valuable customers are based on their spending or LTV.
    • Targeted Marketing: Enabling businesses to target specific customer groups with marketing campaigns tailored to their needs and value.
    • Analyzing Group Behavior: Facilitating the analysis of different customer groups to understand their spending habits, retention rates, and other key behaviors.
    • Developing Business Strategies: Providing insights that can inform business decisions and strategies for customer engagement, retention, and growth.
    • Implementation in SQL: The process of customer segmentation typically involves:
    1. Calculating relevant metrics like total net revenue or lifetime value.
    2. Using CASE WHEN statements to create a new column that assigns customers to different segments based on defined criteria.
    3. Aggregating data by these segments to analyze their characteristics, such as total revenue contribution, customer count, and average value.

    In summary, customer segmentation as taught in this course is a crucial analytical technique leveraging SQL’s conditional logic and aggregate functions to categorize customers based on their value and behavior. This process allows for a more nuanced understanding of the customer base and enables businesses to implement more effective and targeted strategies.

    SQL Query Optimization: Techniques and Analysis

    Based on the sources, query optimization is an important topic covered in the second half of this SQL course. The goal of query optimization is to improve the performance and efficiency of SQL queries, making them run faster and consume fewer resources.

    Here’s a breakdown of the key aspects of query optimization discussed in the sources:

    • Understanding the Execution Plan with EXPLAIN: The course emphasizes the use of the EXPLAIN keyword to understand how the database plans to execute a query.
    • EXPLAIN shows the execution plan without actually running the query. This plan details the steps the database will take, such as table scans and joins.
    • EXPLAIN ANALYZE goes a step further by executing the query and providing actual execution times, planning time, estimated costs, number of rows processed, and other statistics. This allows for a more precise understanding of query performance. The output of EXPLAIN ANALYZE can help identify bottlenecks in a query.
    • The output of EXPLAIN and EXPLAIN ANALYZE includes details about the cost (an arbitrary unit assigned by PostgreSQL), the estimated number of rows, and the width (row size in bytes) for each step in the execution plan.
    • DBaver provides a feature to visualize the execution plan, offering another way to understand the query execution flow.
    • Query Optimization Techniques: The course covers various techniques to optimize SQL queries, categorized as beginner, intermediate, and advanced.
    • Beginner Techniques:
    • Using LIMIT: Employing the LIMIT clause to restrict the number of rows returned can significantly reduce query execution time, especially when dealing with large tables and only a subset of data is needed. The sources demonstrate a substantial decrease in execution time when LIMIT is used.
    • Being Selective with Columns (SELECT Specific Columns vs. SELECT *): While PostgreSQL might sometimes efficiently retrieve data using SELECT *, it’s generally recommended to select only the specific columns required for the analysis. This practice can be more efficient, particularly in large databases, by reducing the amount of data that needs to be processed and transferred.
    • Using WHERE Instead of HAVING: Filtering data using the WHERE clause before aggregation (with GROUP BY) is generally more efficient than filtering the aggregated results with the HAVING clause. The WHERE clause reduces the number of rows that need to be processed by the aggregation step.
    • Intermediate Techniques:
    • Minimizing GROUP BY Operations: Reducing the number of columns in the GROUP BY clause, especially if grouping by columns that have repeating values within the context of the aggregation, can lead to performance improvements. The course demonstrates that removing an unnecessary column from the GROUP BY clause can decrease execution time. In cases where seemingly redundant GROUP BY columns exist, using aggregation functions like MAX() on those columns can help minimize the GROUP BY while preserving the desired information.
    • Reducing JOIN Operations: Minimizing the number of JOIN operations and considering the type of JOIN used can impact query performance. Using functions to extract necessary information instead of joining tables can sometimes be more efficient. Additionally, using more specific join types like INNER JOIN when all matching records are expected in both tables can be slightly more performant than less restrictive joins like LEFT JOIN.
    • Optimizing ORDER BY Clauses: Optimizing the ORDER BY clause involves limiting the number of columns being sorted, avoiding sorting on computed columns or function calls if possible, and sorting by the most selective columns first. Utilizing database indexes for sorting can also be beneficial, although index management is typically handled by database administrators.
    • Advanced Techniques:
    • These include using proper data types, implementing indexing on frequently queried columns to speed up data retrieval, and employing table partitioning for very large tables to improve query performance. These techniques are often managed at the database administration level.

    By understanding and applying these query optimization techniques, along with analyzing the execution plan provided by EXPLAIN and EXPLAIN ANALYZE, users can write more efficient SQL queries that perform better, especially when working with large datasets.

    SQL for Data Analytics – Full Intermediate Course

    The Original Text

    data nerds welcome to this full course tutorial on intermediate sql for data analytics this is the course for those that understand the basics of sql but want to take it to the next level perfect for those that took my first course on this now to master this tool we’ll break down more advanced sql concepts in short 10-minute lessons during this you’re going to be working right alongside me completing realworld exercises following each lesson you’ll have the option to do interview level practice problems to not only prep you for the job but also reinforce your learnings and by the end of the course we’ll have used sql to build a fully customizable portfolio project that you can share to demonstrate your experience now sql is by far the most popular tool of data analysts for those in the united states it’s the top skill that’s in almost half of all job postings for data analysts and this only increases in demand for senior data analyst roles coming in at two out of every three job postings now in related data jobs like data engineers it’s almost the same appearing in two of three job postings and for data scientists it’s in almost half now sql or sql is the language used to communicate between you and a database it’s my mostused tool as data analyst starting with my first job working for a global fortune 500 company and even to my most recent role working with mr beast yeah even jimmy uses it this tool is so imperative i use it all the time with python excel powerbi and tableau to connect to my databases so over the years i’ve been cataloging everything i found helpful with using this tool and i put it all into this course now you’re probably wondering who is this course for well if you’re unfortunate to take my first course here’s some items you should definitely know keywords used for data retrieval functions and keywords used for aggregations and grouping the different types of joins and also unions keywords used for logic and conditions along with date manipulation data schema control and finally subqueries and cte now as far as the math required to take the course if you have a secondary education such as high school in the united states you have the requisite knowledge to take this we’re going to be doing at most just some basic algebra and statistics now let’s get into the course structure we’re going to be breaking this down into two halves in the first half we’ll have an intro that will get you set up and comfortable with the database we’ll be using throughout the entire course next we’ll jump right in pivoting data using case statements we’ll be transforming and analyzing data using aggregation and also statistical methods then we’re going to get into intermediate date and time functions because frankly you can’t get away from date and time data in databases we’ll then wrap up the first half covering window functions the most requested topic i’ve gotten by far on this covering basic and also complex aggregations now for the second half of the course we’re going to shift gears we’re going to not only install postgress on your machine but also we’re now going to be working in these lessons to building our portfolio project we’ll start by setting up the database locally and installing a top editor for running sql queries with this environment set up we’ll build our first view and this will actually help us solve our first portfolio problem after this we’ll transition into learning the most popular functions to transform messy data to solve our second portfolio project problem and then we’ll wrap all this up with query optimization understanding how to use keywords like explain to optimize queries so by the end of this you’ll have a real world project to showcase your newfound skills and demonstrate your experience now i’m a firm believer in open sourcing education and making it accessible to everyone so this course is completely free i’ve linked all the resources you need below including the sql environment and all the different files you need to run the queries remotely and locally oh and also include my final project that you can also model after now unfortunately youtube isn’t paying the bills like it used to so i have an option for those that want to contribute and thus help support fund more future tutorials like this for those that use the link below to contribute you’re going to get some more additional resources specifically after each lesson you’re going to have access to interview level sql problems it will not only reinforce your learnings but also prep you for job interviews in here you’re going to get community access to be able to ask any questions to fellow students along with access to the queries and notes behind each lesson so you can follow right along as i go through it finally at the end you’ll receive a certificate of completion that you can share to linkedin now for those that have bought those supporter resources you’re going to continue watching the course here on youtube but then you can go to my site to actually work through all these problems access to the notes and access to community all right we’re about to get into the first lesson before we do that i want to cover some common questions and answers specifically we’re going to start with this one first what database are we even using well every year stack overflow interviews a bunch of nerds to find out what are their top technologies that they’re using and 50,000 chose that postgress was their top option to use and to use over the coming year and according to this visual it’s not only the most admired it’s the most desired to learn database so for this course we’re going to be using and learning with postgress now that we know the database how the heck are we going to be running these sql commands well as i mentioned previously this course is broken into two halves and we’re going to be using an option for the first half that gets you up and running quick specifically we’re going to be using google collab which is a free option and it allows us to have an environment that we can not only load the database in but also query it i’ve linked this notebook below and includes all the code necessary to install this database and get into querying it now don’t worry if you haven’t used collab before i’m going to break it down all in the next lesson which for those that bought the course perks you’re going to get access to these lessons which are in a jupyter notebook for the second half of the course we’re going to shift gears and we’re going to install postgress locally on your computer and run all the queries from there we’re going to get you set up with pg admin which is postgress’s custom guey in order to interact with databases but from there we’re going to get you set up with the most popular database editor dbaver which is used by over 8 million users and this is where we’re going to be running our queries and i like this editor because it’s not only free but it also connects to a host of different databases so whatever you use and learn in this course with this editor you can apply to other databases now that we know the database and the editor what data set are we going to be using for this well i present to you cantazo and this is a data set created by microsoft used to imitate real business data jumping back into dbaver we can see the erd or entity relationship diagram and this shows how the data set revolves around sales data that’s the fact table and then we also have four dimensional tables that relate to it this is going to be great for analyzing business transactions in a real world scenario we’re going to go over everything you need to know for this after our google collab lesson now that we got that out of the way let’s get into some resources you have available starting with those that have decided to support the course first i’m going to walk you through how to get access to the course notes which detail all the different topics and code that i use within each lesson and next you’re going to have access inside of the course platform to interview level sql practice problems after each lesson i’m going to provide you with a bunch of different practice problems that range in difficulty for you to go through and test your skills if you get stuck feel free to jump in the comment section below and talk with other students in the course speaking of help how the heck do you get help in this course well you could jump into the youtube comment section and hope somebody comes and actually answers your question or you can get a really quick answer going to a reputable chatbot like chatgbt i use this bad boy all the time with my coding issues and it gets you an answer quick all right next question well isn’t really a question it’s more of a statement people tell me all the time luke this video is too long i can’t navigate it well unfortunately i think you don’t know how first of all i include chapter markers for all the different lessons throughout this the next is keyboard shortcuts i like to use j and k in order to jump forward or backwards 10 seconds and then finally if you need more precise navigation you can just click and drag up on the navigation bar of the video itself and then you can do precise seeking pretty cool all right last question who helped build this course and i’d be remiss if i didn’t give a shout out to kelly adams she was the brains behind putting together the lesson and also a lot of the practice problems for this this course wouldn’t have been possible without the help of her all right let’s get into the first lesson all right in this lesson we’re going to be going over how we’re going to be running sql queries in this first half of the course using google collab which is a type of jupyter notebook so link below is a blank notebook and opening up it’s not fully blank but it’s blank enough to actually get started with writing sql queries let’s do a quick demo of how we’re going to use this for sql queries first i need to run this cell up top and it’s going to give me this warning that hey this notebook was not authored by google it’s fine it’s run anyway it’s from me you can trust me it should take about 40 to 50 seconds to run this cell which we’ll go through more later in this video basically it’s loading the database and getting it set up for us to actually use and now run sql commands so inside this code cell let’s provide a command so we’re going to begin by writing our command underneath this percent sql syntax right here at the top and i’ll provide this query looking into the sales table looking at those top 10 options i can run it by pressing this play button or pressing shift enter in less than a second i have all the different results pictured below if i want to run another cell i can just come underneath it click code make sure that i add that percent sequel to the top of the cell it’s not going to work otherwise and then run my next command that i want to right underneath this all right with that out of the way we’re going to now dive deeper into understanding what is google collab what are jupyter notebooks how to actually use these to run sql queries and what the heck is going on with all that code that i had in those cells now if you have familiarity with using google collab already or already confident in using jupyter notebooks and you feel like any of this that i’m going to cover is not relevant to you it’s fine go ahead skip to the next lesson this is more focused on those that don’t have any background with using jupyter notebooks so let’s start with jupyter notebooks here i have a jupyter notebook of this actual lesson inside of vs code don’t worry you don’t need to actually open inside vs code just showing this for demonstration purposes now personally i love jupyter notebooks for performing analysis because not only can i have these text cells like are pictured right here and then scrolling down even further i can see that at the bottom i have a sql cell along with the sql output so i love these because i can use sql to extract out and analyze the data i need and then if needed use something like python to visualize it now moving into google collab which you can see right here i’m inside my web browser and this is that same exact file that i had inside of vs code but now it’s here inside of google collab and similarly it has that same functionality where i can write python code in cells along with using that sql and the outputs of that below it i really like google collab because it makes it super easy to share and collaborate with others this isn’t just a static document i can come in here and actually run all the different cells inside of this notebook and if somebody wanted to they could come in and modify this query further so right now this one’s only looking at years let’s say we wanted to look at the actual total revenue i could just add this line in the command run it and get the results right below so super easy to collaborate with others and now you may be wondering why are we actually using collab for running these sql commands well basically this code right here that i have in this cell that we’re going to cover i promise allows us to load in our database and for you to have access to the database immediately without having to actually install it locally on your own computer so basically we can get up and running with running all these different sql commands really quickly let’s start with a blank notebook to walk through this process of understanding how to use notebooks if you navigate to collab.resarch.google.com this is where we’re going to start a new notebook and it will have prompted you to log into google at this point anyway go and click this so it starts this new one which gives the title untitled zero you can go up up here and actually change it and i’ll change it something like collab 101 quick overview before diving into the center portion right here we have a typical menu up at the top to do a bunch of different options and then we also have this sidebar over to the left hand side that gives us a lot of different options as well in the center here is where the actual notebook is itself and i can do things like either add a code cell or a text cell if i wanted to i could type into it this is a text cell i can also change the formatting of it by highlighting it and toggling it to being a heading they also have multiple other options available as well whenever i’m done with this all i have to do is press shift enter and whenever i press shift enter it then starts another cell a coding cell below that now in collab these are exclusively python cells we have to do some magic if you will in order to get it to run sql but you may not realize it but you actually know some python even if you don’t know it i could do something like 2 + 2 press shift enter and what’s going to happen here is it’s going to run the cell of 2 plus 2 and then we get the results of four now if i don’t need certain cells like this one up at the top i just click into it and click the trash can similarly i can do it to this one down below now let’s go over these menus and for this i’m going to be demoing it using the actual lesson plan notebook from this cuz it makes it more interactive to show actually the capabilities of it anyway over on the lefth hand side if i click this over on the left i have the table of contents based on how i formatted all the different lesson notes i can actually scroll through and see all the relevant topics if i wanted to find something i can just go in here type fine of markdown and as expected take me to all the different markdown things inside of here we also have other things like variables secrets and also files that’s more in depth if you’re using python for this you won’t really need to use that along with these three at the bottom also not going to be using as much in this sql course now up at the top in the file menu right here file edit view insert everything like that’s normal runtime is the one location that i find i’m actually using the most and find the most important anytime i’m opening a notebook i’m going to be doing this run all and i can also see that i can do this with the shortcut of command f9 and this will go through and actually run all the cells down here at the bottom it gives you a status update of what’s going on along with the time it’s taking so far now scrolling through all these different cells i can see they all executed properly but sometimes we run into bugs and they’re not running properly in that case we can come up here into runtime and i recommend running this of just restart session and run all it will prompt you if you need if you really want to do this and yes go ahead and do it basically clear everything out and run it again that’s only if you’re having problems you shouldn’t but if you did now you know in this last section of the lesson let’s understand what is going on with how we’re running sql queries inside of this notebook for this i want you to actually open up that blank sql notebook and load it into your window and you can follow along with me if you haven’t done it already go ahead and up at runtime click run all so i mentioned earlier all of this code here which is in python goes through and actually installs and sets up your database we’re going to walk through it really quickly but the important thing to understand here is not necessarily the code or that you need to code it yourself it’s mainly understand what’s going on behind the scenes first it goes in and imports some important libraries that we need for this next if it’s in collab which we’re in we go in and install postgress so postgress is actually running inside of this environment that we’re inside of it goes through and sets up a user a password and then from there actually installs the database itself which you can get at this link right here from there we import in a sql library in order to be able to run sql commands specifically it’s called gps sql and then with this jubsql we go ahead and load the extension actually connect to this database that we loaded in from up above and do some other fancy things that help us get formatting and everything else set up properly so similar before below this magic command of percent sql i can write a sql query as i’m writing these sql commands you should have autocomplete come up so in this case i have select if i want to use it all i have to do is press tab and then once i have everything i need there once again i can press shift enter now that magic command is really important if i were to copy this paste it below one i get all of this highlighting saying that it’s misspelled and that they have syntax errors and then two when i actually try to run it i get actual syntax errors so very important that you put these magic commands up at the top now so people don’t think i’m crazy magic commands are the actual official language of this and we’re not only limited to sql magic commands they also have a host of other ones let’s say i want to use this one of time it where it measures the execution time of the next line of code i could type the magic command of percent time it some help pops up of what actually is going on with this module that we’re actually using here which is pretty actually useful and then underneath it i can put some python in here i’ll just do something simple like 2 plus 2 running this pressing shift enter we can see that this special command provides the time of this took 9.93 nanconds now with these magic commands you can also use just one percent sign and that means it applies only to the line that it’s currently on so in this case i could do 2 + 2 on this line press shift enter it’s still going to run it which in this case looks like it’s a little bit faster but if i actually had only one percent sign and let’s say this is on another line pressing shift enter it’s just going to output the four and it’s not going to actually time it it’s not until i actually use two of the percent times and run it that it will actually time it and now we’re back up to 9.85 nconds so i’m just reinforcing this because it’s very important that you remember to do that percent sql before any sql command now if you’re nerd like me and you want to dive deeper into the documentation of jubsql because of the brains behind that sql magic man you can a link below all right for those that purchased the supported resources you now have some practice problems to go through and get more familiar with how to use jupyter notebooks and sql queries together in the next lesson we’re going to be diving deeper into the database to understand all the different tables and what comes along with it with that i’ll see you in the next one in this lesson we’re going to be getting an intro into the database that we’re going to be using for the entirety of this course specifically the contazo database for this we’re not only going to explore why we’re using this data set but also the components about it exploring all the different tables using things like the erd or entity relationship diagram now we’re going to use this lesson as a warm-up to get ready to get into using intermediate sql so during the course of this i will be covering different past topics that you should know in order to get you up to speed as fast as possible if you haven’t used sql in a while by the end of this we’re going to be covering a query from scratch in order to dive in to the most popular tables while using google’s collab and some additional ai features to speed up your workflow now the contazo database that we’re going to be using for this is based off of a data set from microsoft which they’ve been using for years whenever they launch any products specifically sql products in order for you to explore how to use the functionality of it anyway this database is really robust because it contains a lot of different information in it such as sales transactions product information store details and even date and time data and this database is great because it allows us not only to explore all these different intermediate sql topics that we’re going to be using for this but also it’s based on a real world business set of data so what you’re going to learn in this course you can apply to the real world and so you may be like luke how the heck do i get this database installed well if you remember from the last video we have this python code up at the top that actually goes through and installs the database the database or the sql file for loading it it’s located at this link and we go through this script right here in order to load it in to this collab notebook which i’ve conveniently linked a blank notebook below that you’ll be able to follow along any of the lessons with so this diagram shows via these lines between all these different tables how they are actually related and there’s actually a lot of columns inside of these tables themselves so we put these ellipses at the bottom to basically signify or symbolize all the different columns that are in it so let’s get into breaking this bad boy down we have a total of six tables in this contazo database specifically our main fact table is the sales table and this contains all of our quantitative business metrics that we’re actually going to be analyzing and inspecting as we go throughout the course so it’s probably the most important table you need to know then we have four related tables or commonly known as dimensional tables these things have descriptive attributes that we can use in our analysis so for things like store we relate it using the store key and the sales and then stores table and the store database has information on well the stores similarly been said about the product and also the customer table the date table is slightly different in that it relates to the different dates specifically our order and delivery date the last table in this is that currency exchange table and it’s not related at all to our fact table and we’ll show why in a little bit now you may be wondering how can you actually go through and see what this database looks like and understand what are the tables in it well we’re going to be exploring tools later in the course specifically this is pg admin right here where i can visualize that erd and it shows how our fact table of that sales table is related to all those other different dimensional tables additionally it’s pretty nice because i have this kazo 100k and i can go into something like schemas and then down to tables and further i can further explore all these other different tables as well even looking at things like the columns for the sales table but we’re getting ahead of oursel we’ll learn how to do that in a bit i’ll teach you some shortcuts on how you can actually do something similar to this in collab so let’s get into running some queries first thing we need to do is go through and actually run all the different cells in your notebook basically get that database loaded into our environment and so we’re looking to explore what are the tables in this database that we just loaded into here i’m going to use gemini for this if it’s your first time using this ai model from google it’s going to prompt you with this privacy notice make sure you click continue and i can prompt it this of what sql query shows the tables in a database what we can do is access all these different table names by looking in information schema which is a meta database and specifically using the data attribute the looking at the tables within it which is a table now for this you can either click copy cell or you can do add code cell now remember we’re going to have all the syntax highlighting issues because we’re not or we don’t have in that magic command we need to put at the top specifically that percent sql so i’ll just copy that from here paste it up here and then run this bad boy so from this we confirm we do have six tables in our database and if i wanted to i can convert this data frame to an interactive table like this and then we also have this option to visualize it which we’ll be doing down later down the road so let’s explore first that sales table as that’s the most important part of this whole puzzle i want to see all the different columns of this so i’m going to use select and then star we’re going to do this from that sales table now if you’re noticing right now i have some autocomp completion happening right now you see i typed sales and i have this underscore fact underneath it this is the ai autocomp completion especially whenever i’m learning how to use sql i don’t find this very helpful and actually quite distracting so we can turn this off real quick if we go into open settings and select under ai assistance we can uncheck this option here for show ai powered inline completions whenever we close this we can see no longer pops up now this is good enough query as is but anytime i do a select star type thing it’s very resource inensive especially if there’s a lot of columns and rows so with this i’m going to limit this to just the first 10 rows then from there press control enter also don’t need this query off to the side so i’m going to close that so with this sales table we can see that it has all those different relations to those other tables such as the dates customer key sore key and product key from there we have information on what is actually sold in this sale specifically the quantity the price the cost and then also the currency used and its exchange rate in our example at the end of this we’ll go through calculating what is the net revenue and how we need to actually multiply or use all this together to calculate that let’s get through exploring these tables specifically we’re going to go with the easiest one first next of exchange rate if you recall our currency exchange table is in no rel way related to that sales fact table but what the heck is in it well exploring it we can actually see that in it it has a date column from currency to currency and exchange rate basically it at a specific time in history it tells you how you could convert a currency from one to another what the rate you need to use that now conveniently our sales table automatically just includes this exchange rate which was calculated from this table so technically this table is only needed if you need to go back and dive into understanding the exchange rate and how it’s trending over time all right we have four tables left and they’re all the dimensional tables that related to our sales table let’s start with store first this one is related to that sales table on a store key and then has information on where this is located such as country name of the store even the size next up is our product information and it’s related to that sales table on that product key it has information on the product specifically what is the name who’s the manufacturer how much it even weighs and what categories and subcategories it falls into next up is our customer table it’s related to that sales table on our customer key and this has a bunch of information related to the customer itself like where they’re located what their name is what their birthday is blah blah blah anyway what you notice right here in the middle is we have these ellipses and that’s because there were so many columns in this it didn’t show it here now previously whenever we were looking for the tables in the database we could run this on that metadata inside the information schema so what i’m going to do is actually i’m going to take this right here command c this and i’m going to paste it right into here but for this we don’t want to use tables we want to use columns running shift enter on this this only gives us table name information so i’m actually going to change this to select star run shift enter so we can see everything available in this query and inside of here i can see of this columns table we have a table name and column name so what i can do is i can now filter this for the table of customers so i’ll specify where table name is equal to customers running this again pressing control enter got a typo it’s customer running control enter again so now i have a way to view all the different column names and it’s not cut off and so we can see everything inside of it but not really finding anything that great right here for now but other stuff we’ll use in the future last table to explore is that date table this is related using that date column here to the sales table order date and delivery date now this table has a lot of different ways that you could aggregate all the different date data in here by looking at maybe day of week or month or year so this is great and all especially if you’re using a tool like powerbi and you want to just grab something quickly in order to filter maybe for january 2015 data but in this course we’re going to be diving deeper into using different date functions and so we’re not really going to rely on this table at all to get the data out because you won’t always have a date table available in order to investigate things so basically just ignore this bad boy now let’s wrap this lesson up by getting into an investigation of how we can use all these tables together for a common example so let’s say my boss who’s not so good at sql comes to me and wants to get some different revenue data that has information about customers and also products they’re ping purchasing and whether they’re of different high value or low value items so we’re going to walk through this example calculating the net revenue for this and how we can put this all together using all the different tables first thing we need to do is calculate net revenue so let’s look back at that sales table we’re going to use that same query as below and we get this table that we saw previously now for this how do we want to actually calculate that net revenue well in order to do this we need to use the net price now you’ll notice from this the net price is less than the unit price that’s because the net price is the price after all the different discounts promotions or any adjustments so basically it’s what we actually charge to the customer when they pay for the product and with this net price we need to multiply it times that quantity so what i’m going to do is put a comma here go to a next line and say we want to multiply the quantity times the net price and we’ll say this we’ll label this as the net revenue now when i name variables or when i name new column names i’m going to put this underscore between it i just find it easier to read the naming convention that kazo’s database is using and looks like i have a typo which is pretty good that we hit this right now because this is how i’m actually going to go through and troubleshoot this first it will tell me that there’s this runtime error anytime i’m running a query you can just ignore that you’re going to be seeing that all the time but it actually points this carrot here to where the issue is specifically it’s point to this line and it has to deal with quantity is not spelled correctly at all running this again pressing controll enter okay we actually have it now and over to the side we have that net revenue double checking this it looks like all the numbers are actually getting calculated correctly there’s one last step to do and that is we need to convert it to a common currency right now you can see that they’re using pounds here and then us dollars below basically we’re going to use it all the same i’m in america so we’re going to be using us dollars all we have to do for this is just multiply by the exchange rate gone ahead and added it in and now we can see that it is in fact adjusted for what it needs to be now we’re going to be adding customer and also product information using this customer key and product key but this table’s already getting sort of large so i want to condense it down to different columns i’m for sure i’m going to use and really the only other thing i care about is order date so we’ll go ahead and simplify this table down to this next we’ll move into our second of five steps and we want to filter for our recent sales specifically we want things from 2020 and greater for this i’m going to use a wear clause and i want this for that order date that we have in that sales table to be greater than or equal to january 1st 2020 now let’s go ahead and try to run this and it looks like it works now i would say in order to be safe if you’re ever working with date data that you’re not sure if it was converted to the date type specifically in postgress you can use this colon operator and then specify the data type you want to use for this in this case date so order date is getting converted or cast as a date this is going to work just the fine but just a tip for you all right next thing my boss wants added in is the customer info about who ordered that order now in order to do this we need to use a join and there’s four major types of joins left join right join inner join and then full outer join in our case we want to perform a left join because table a is our sales table and we want any related data to that a table in the sales table returned from that b table or customer table so let’s add this left join we’re just going to go between from and where i’ll add in a left join we want to do this on the customer table we’re going to give it the alias just c to make it easy similarly i want to give sales an alias as well i’m actually going to bring this down and then indent this over i’ll give this the alias of s now for this left join we want to do this on from the sales table we want to use that customer key and then from the customer table we want to use customer key so we’re going to use good actual naming conventions here i’m going to add that s dot to the front of order date along with the front to quantity net price and exchange rate now i’m going to go ahead and run this to see if it actually works and it looks like it works we don’t have anything from the customer table i’m going to go ahead and add in all the different columns by doing basically a c.ar notation to bring all those in all right so from this list i can see there’s a few different columns we want that my boss has told me about specifically we want to get the given name or first name surname country full and then also the continent that they’re from all right second to last step we need to add that product information in and similarly we’re going to be forming a left join with this we’ll give that product table an alias of p and we’ll be connecting it on the product key of the sales table and the product table once again i want to see everything from that product table so i’ll do p.star running this control enter i can see that we connected it properly with all the different product information once again i don’t want all the different columns associated with this only want to select few does my boss specifically these four columns of product key product name category name and subcategory name all right so looking pretty good with this only one last step to do and we’ll have all the information we need specifically we want to look at whether a customer is high value or low value looking at the net revenue we want to basically bin these customers into whether they’re spending less than $1,000 or greater greater than $1,000 in order to accomplish this we need to use a case when statement and we’re going to add it in at that last column right here so we’ll say case when we want to look at the net revenue but we can’t use an alias inside of the select statement because it’s not necessarily defined yet so we just need to take all of this below paste it in here and say greater than 1,000 and in that case we want to say that it is high else we want to say that it’s low so we can end this and then we’re going to use the alias for this of high low real original i know let’s run this pressing control enter inspecting it we can see that our formula is working for those values that are greater than a th00and we’re marking it as high so this has everything that we need in it for my boss remember right now we’re doing this limit 10 we actually need all the different data in it so i’ll go ahead and press play looks like we have 124,000 different rows in this and if i want to export this to my boss i could click this here in order to convert this into this type of table but what’s really convenient about this is i can now copy this entire table which allows us to either export to a csv json or even markdown csv is most common so i’ll use that all right so now that’s our initial dive into this kazo data set we now have some practice problems for you to go through and get even more familiar with this data set working through some problems in the next lesson or the next chapter we’re going to be diving into using the case statement in order to pivot data super exciting all right with that see you in the next chapter welcome to this chapter on pivoting with case statements and specifically we’re going to be using statements like case when and aggregation in order to pivot data but what the heck is pivoting data let’s take a look at this simple example focusing on that first table first typically our data comes in a long format and in this case we have an example of a columns of date category and sales where we have different categories of a and b it’s very common to pivot things such as on the category here of a and b so that way we get to more of a wider format as shown below this is not only easier to read and understand and analyze but also easier to visualize which we’ll be doing in this so what will we be covering in the lessons in this chapter in this lesson we’re going to be focusing on understanding the basics of using aggregation methods such as count and sum in order to pivot data we’ll use count to analyze the number of customers per region and then we’ll use sum to calculate the net revenue based on different categories in different years in lesson two we’re going to build this up further and start looking at statistical functions such as min max median and average for this we’ll get into an example of calculating what is the median sales across categories then finally in lesson three we’re going to jump into advanced use cases of case statements specifically we’re going to be looking at things like segmentation we’ll learn how to analyze by multiple and conditions in order to look at things like bucketing for certain years based on revenue and then similarly we’ll use multiple when conditions in order to analyze different bucketing of revenue tiers and see how they apply across different categories now i just showed a bunch of visuals and the goal of this course is not learning how to build or make visuals which i will show in this but really i want to be able to show that hey with these insights that we’re gaining you can take it a step further and visualize it all right with that let’s get into it in this first example we’re going to do a review understanding count but also distinct count in order to calculate the total number of customers per day in 2023 this will be the final table that we end up getting as always if you want to follow along open up that blank sql notebook and run all the cells in it so we can get started so remember we want the total number of customers per order date we can uniquely identify this based on the customer key so add a select statement from there i’ll add order date followed by customer key and then we’ll get this from that sales table let’s start with this first so as we can see from this we have this is the first of 2015 we have duplicate customer keys but then we also have a bunch of different ones we’re going to start simple first we’re just going to do a count of all the customer keys so i’ll wrap customer key and count and provide it the alias as total customers let’s run this and this isn’t going to work right because well we need a group by right so adding that group by statement we’ll add in we want to do this by that order date and then run this again all right so now we have the order date by total customers right now i’m noticing that the dates are not in order so i’ll add in an order by order date and not too bad but remember previously whenever we were actually looking at it we could see that customer key is actually duplicated we want to find the unique customer so we want to use something like distinct so going back up into our original query all i’m going to do is add in distinct in here and then run control enter and now those numbers are going to drop right because they have a we’re going to remove all those duplicates last thing we need to do for this one is just add a wear condition for filtering for dates in 2023 so i’ll add an order date and for this i recommend using the keyword between so we don’t have to do that greater than less than all that kind of mess and then putting in between january 1st 2023 to december 31st 2023 running this we can actually check the contents yep january 1st to december 31st one quick note now on visualizing this you can use this button right here and actually select it to go through and draft different visualizations to try to understand what is going on here with the data what it will do is it will give you different previews in our case this is time series data so i know that’s the best choice to use for the visualization whenever i go to select it it will autogenerate all the different python code you need in order to visualize that data and then all you have to do is click add cell and then running this you can actually visualize it in more detail right below so that’s why i really like collab for this is because it has gemini implemented into it makes it super simple for you to just go forward and actually visualize this all right let’s now get into actually pivoting using count as an aggregation and for this we’re going to be looking at something similar from that last example understanding how many daily customers we have but broken down by region specifically three continents of europe north america and australia for this we’re going to be getting this final table where we have things like order date in the leftmost column and then we have the customers based on the different regions in their own individual column first things first though what continents do we actually have available inside of our database it’s underneath the customer table when we run this we can see as a previous report in got europe north america and australia so let’s go forward with actually adding this table into the query that we just made at that last example in order to do that we’re going to be performing very commonly a left join and that’ll be with the customer table with an alias of c and we’ll do this on our customer key and what we’ll need to do now cuz we have two tables in here we’ll need to assign an alias also to our sales table and then also to all those other different columns that come from the sales table running this to make sure that the error there’s no errors there are accidentally messed up order date run this again okay everything’s working fine now but now we need to create individual columns for total customers based on continent so how are we going to do this well let’s focus on this syntax right here we’re going to be using the count distinct that we use as we used previously and inside of this we’re going to be throwing in a case when statement it’s case when a condition then what the output we want it to be the column in this case and then end and then finally assigned an alias so i’m going to go ahead and copy this right here and i’m going to insert it in the next line underneath here but we need to go through and actually fill it out so the condition is we’re looking for if it equals a certain continent so for the continent from that customer table we’re going to see in this case if it equals to europe and specifically the column that we want from this is then that customer key so i’ll go ahead and put that in and this one will give the alias in this case called eu customers let’s try this bad boy out and bam now we have our european customers in here let’s go ahead and add the other two as well of north america and australia all right i got those in as well have the north america and then also the australian customers go ahead and run this and scrolling down we can see that based on the total customers the europe north america and australian they do add up to this line right here so that field of total customers is now somewhat redundant i’m going to go ahead and actually remove that and this will be our final query now visualizing this one similar to the last one this one i find especially has multiple different columns in it the visualizations it provide aren’t that good specifically it is here in these time series but it’s broken up to where this one’s europe this one’s north america and then this one’s australia they’re not all on the same graph so unfortunately gemini in this case is not that strong in producing graphs if you really want to visualize it and you want to know my method for it all you have to do is go ahead and click that table and then remember you can actually copy it and this is going to copy the table to your clipboard so this contents right here i want it as a csv i’ll go ahead and copy it and we’ll need to put it into some sort of document because it’s pretty long so you want to put into a document such as csv so on mac i’ll put in something like textit um on windows you’ll put into something like notepad i’ll just paste the contents in using commandv and then from there just save it inside your favorite chatbot in my case i really like chat gbt you could use gemini claude whatever i’ll give it the simple prompt with the actual document of visualize this as a line chart and then with it visualized we can actually i like going in this interact mode on chatgpt we can actually go through and you can see both the all three of these regions along with visualize if you want to download the graph you can just click it there last example for this lesson for this one we’re going to be looking at using the sum function with case when in order to look at what is the total revenue by category and we’re going to be using that case when in order to look at 2022 verse 2023 this is the final table that we’ll be creating where we have category in the leftmost column and then we’ll have the total net revenue for 2022 and then for 2023 right next to it now for this i don’t want to start from scratch so i’m going to do take this last query that we took right here and then paste into cell make sure it runs properly all right now for this i want to just start simple i want to first look at what is the total revenue by order date so i’ll just start by first removing we’re going to be done in 2022 and 2023 removing this wear clause also we don’t need this customer table so i’ll remove this as well along with these this count distinct that we did for all the different customers with it just simply like this i’ll just start run it and make sure yep everything’s appearing it’s got all the different order dates in it okay now let’s get the total revenue and that’s going to be done by using sum now if you remember from a couple of lessons ago you need three things for this quantity net price and then also exchange rate so i’ll add all three of them here using multiplication and i’ll assign this as the alias of net revenue um remember anytime we’re doing an aggregation need to have that group by let’s go ahead and run this not bad but right now we’re aggregating it by order date and we actually want to break this down based on the category just as a refresher you don’t need to run this query what we need is from the product table is right here this category name so one we’re going to need to merge this with our sales table and two extract out that category name so inside of our original query we’re going to go ahead and do a left join connecting in the product table with the aliasp and on specifically that product key we’ll go ahead and run this to make sure that it still executing properly okay good we didn’t bring anything from the product table in we need to do that now and what we want to do is replace this order date now but with category name and we have it in three places so i’m going to show you a shortcut real quick so what i’m going to do is i’m going to highlight all of this right now you can see it’s only selected on the top one i’m going to press on mac command shift l on windows you’d press control shift l and now all of these are when i press backspace all of them are removed and then as i type all of them get typed in super convenient saves a lot of time and then i’ll go ahead and run this again by pressing controll enter and bam now we have category name and net revenue for each we have this net revenue across the entire data set still need to filter down but this is pretty good so far now in order to do this bas it up on 2022 and 2023 we need to be using a similar type syntax that we used before specifically wrapped in our sum function we’ll use our case when when it meets a certain condition of 2022 2023 we’ll provide it the net revenue when it meets that condition else if it’s not that year it’s going to be zero so whenever we sum it all up you only sum up if it’s that year and then finally we’ll end it with an alias so i’m going to go ahead and just copy this all and then inside of here i’m going to paste it down below so our first condition is checking on whether the date is in 2022 so for this we’re going to be using that order date column and we want to check if it’s between a certain date specifically between january 1st 2022 to december 31st 2022 had a brain fart there for the column for this we’re going to be using what’s above here inside of our net revenue of all three of these columns multiplied together and then finally the alias we’ll provide it we’ll call it total net revenue 2022 let’s go ahead and run this and bam we have it for 2022 this is looking good let’s go ahead and put a comma on the end and i’m going to go ahead and copy this and then pasting it right below then i’ll just need to go through and update it to make sure that we’re now using instead of 2022 that we’re actually using 2023 make sure to also change the alias okay running this processing control enter we get almost our final results once again we don’t need that net revenue in there it’s not telling us what we need so we’ll go ahead and remove it and now we have our final table and from this we can see that for some strange reason from 2022 to 23 for all of these columns all the data went down that’s not really good i’ll leave that to my boss to figure out all right it’s your turn now to go through we have some practice problems aligned for this to get you more familiar with how you can use case when statements in order to pivot data using these different types of aggregation methods in the next lesson we’ll be building on this focusing on statistical functions such as min max average and median and diving further into revenue with that see you in the next one now that we’re warmed up using basic functions to analyze pivoted data we’re going to now shift our focus in using statistical functions for this specifically we’re going to be covering these functions we’re going to warm up by focusing on the easy ones first of average min and max in order to pivot that database and understand some data insights and then from there use the percentile count or continuous function in order to analyze the median revenue of sales and we’ll continue on that same trend of analyzing this based on all these different categories to see what is the highest performing category so where can we find out what statistical functions are available to us well we go to the source documentation here at postgress they have the section on all the aggregate functions which includes the statistical functions and scrolling on down we can see max and min which we’re going to be using shortly which find the maximum or minimum value of expressions across all non-null input values and then similarly we have a whole host of in-depth uh statistical functions those around correlation looking at r squar standard deviation and even variance so let’s get into actually analyzing using min max and also average i need you to start up a blank notebook for you to work with and so what are we going to be analyzing for this well if you remember back from last lesson we calculated the total net revenue by category broken down for 2022 and 2022 we’re going to be doing a very similar approach to keep it simple looking at things like min max and average because of this if you still have that query you can go ahead and just copy that query right above as we’re going to be reusing that and modifying that to apply these new functions so inside my blank notebook i’m going to go ahead and paste that right here and actually running it press control enter first one we’re going to try is average and this finds the arithmetic mean of all non-null input values so pretty simple in here we’re going to keep this query mostly all the same but instead of doing sums here we’re going to be performing the actual averages because of that i need to name the aliases appropriately naming them average net revenue 2023 i’ll press controll enter go ahead and run this and bam now we have our average values and this is pretty neat because if we remember back computers had the highest total revenue but yet in this home appliances have the highest average net revenue anyway if you want to visualize this we could click that graph thing and try to actually visualize it below but being that this is categorical data i don’t find that the graphs that ever provides are that good because this table is so small i actually sometimes can just take this and copy the entire contents and just paste it right inside the chat itself since it doesn’t take up too much space and give it the prompt to visualize this and then bam we can see the different average values for these different categories across the years and actually compare them seeing things like computers actually were lower in 2022 than 2023 now that we understand average let’s explore min and max and it’s going to be a very similar syntax to this so i’m going to use some ai to automate this i’m going to go ahead and just copy this query right here open up gemini and i give it the prompt add in min and max statements similar as done with these average statements and then below this just go ahead and paste it in let’s see if it can actually do this going to expand this out to actually be able to inspect this and it looks like we got it done so we don’t need to be all repetitive anytime there’s repetitive task and give to ai to actually do this i’m going go ahead and actually insert this into here and close out of gemini and then i have all of these syntax errors because remember we don’t have the magic command for sql at the front and now i can go ahead and actually run this pressing control enter and bam now in one table we have not the average the min and also the max all formatted and typed out correctly pretty neat with ai so let’s crank this up a notch and start looking at a similar analysis but now using the median for those that are not familiar with what a median is if you were to have a list of numbers and then you were to sort them in order the median is the middle number so in this case when we have these seven numbers right here six is the middle number whereas when we have eight numbers we take the average between the fourth and fifth number which could be only four and five and that becomes 4.5 now median is extremely important especially when you’re working with data in this case we’re looking at salary distribution this from my python course and we’re looking at salary distributions and you can see that we have the salary go up and then go down but then it goes out and we have like high out values way out past 350,000 if we just use the average this average is going to be pushed towards a higher number and is not going to be representistic of the actual data so median helps fix this issue by basically sorting all those numbers taking that middle number and getting a more representistic number of what you would expect to see in this case salary what would you expect to see i wouldn’t want to expect to see a higher salary when i know i’m going to get a lower so you may be like “this is pretty easy all i got to do is change all these average values to median and then run this unfortunately there’s no such function as median hence the no function matches this given name and argument type and that’s common across all databases whether you’re using postgress sql server or mysql we’re going to use this percentile con or continuous and that continuous portion is a key part because now this function that we’re using percentile cont is not only an aggregate function but it’s an ordered set aggregate function so what does this all mean not only do we have to use percentile con and what fraction we want to use for this in this case the median or half of it is 0.5 but we also have to use this other syntax here of within group and then order by so let’s actually break this syntax down using this percentile continuous function we need to provide it basically a list of ordered values it’s not going to sort it itself and be able to pick it out like other aggregate functions because of this we first in parentheses have this order by column this specifies how we want to order the values that we’re going to be picking out the median value from but this only sorts the values we actually need to bind it to this percentile continuous function that’s why we have this within group portion right here to bind that ordered set if you will to that function so let’s just take a simple example first using net price here i have a simple select statement of net price we’re taking it from sales itself and it looks like we have almost 200,000 rolls of net price let’s get the median value from this so i’ll first start by using that percentile continuous function notice they also have a percentile discretet that’s if you don’t want it to average if you have two numbers in the middle you don’t want it to average if you want to actually pick a certain value you use discretet i mostly stick to continuous and then we’re finding the median value or that that is at the 50th percentile hence 050 and we need to first bind what we’re going to be binding this so we’ll use that within group and then in parenthesis we’ll use that order buy specifically of that net price and then we’ll assign an alien an alien an alias of median price let’s go ahead and run this bad boy and bam we get that median price of $191 just out of curiosity i’m going to compare it to that average net price and similar to what we saw with that salary data that i was showing previously the average price is much higher and that’s because we have these high value items that aren’t necessarily purchased as much driving that average up so media in this case is a lot better at getting a representistic understanding of what the common net price is people are seeing so what are we going to be calculating this last example well we want to find out what are the median sales by category comparing 2022 to 2023 notice here we’re going to say sales i’m going to use sales more frequently um but this is technically net revenue but in the business side we typically just say this is sales i don’t like to start from scratch from this so i’m going to work with that very last query that we just did where we found out the average min and max four different categories so i’m going to go ahead and just copy this all and then paste it into a new code cell here remember we’re not going to be using this average min or max so i’m going to go ahead and remove it let’s just start by getting the median net revenue or sales for basically all the years and then we’ll filter down by 2022 and 2023 after so i’ll define that we want the median by specifying percentile continuous we’ll use the binding function within group and then we’ll use that order by and this will be done on the net revenue which is quantity times net price times that exchange rate we’ll give it the alias as median sales all right let’s see if this bad boy works controll enter all right not bad we have our median sales for our columns but fast forwarding to the future remember we want to call them on 2022 and 2023 so starting with 2022 first i’ll put year 2022 here so know that that’s what we’re working with basically we want to provide the necessary values right here inside the parenthesis to filter down for 2022 so because of that we need to use a case when statement so i’ll add in case and then from there i’ll press enter and indent this in and then we need to fill in when the column name equals a condition then we basically we want this value of the net revenue and so after that we’ll actually end it okay so we need to fill in this column name equals condition mainly we want to meet the condition of verifying the order date is in 2022 so we’ll remove this out and we’ll start by defining the order date we’ll use that between argument and specifying that we want between january 1st 2022 to january or december 31st then it’s equal to these values i’m going to go ahead and just for good measure to make sure it’s a little bit more readable put that into parenthesis so just to be clear right you can see this order by we have this pink parenthesis right here it’s then doing a case statement to determine if they’re within a certain date then it’s equal to this value else not going to have any values let’s go ahead and run this all right not too bad i want to add in 2023 now i don’t feel like retyping all the values so i’m going to use gemini for this and i’ll paste in the code giving the prompt of addin 2023 also under this thing and it looks like it did it correctly i’ll go ahead and insert this in double checking it yeah looking good and now running this final query we have the median sales for 2022 and 2023 so just taking it a step further actually analyzing this we can see that comparing those median sales to that total net revenue which is also total sales we can see some interesting insights specifically for computers from 2022 to 2023 the median sale actually went down and corresponding with this the total sales of that same category of computers went down so maybe it’s something you could bring up to the svp of computers all right so you now have some practice problems to go through and get even more familiar with using these statistical functions when applied with pivoting and using case when statements in the next lesson we’re going to be getting into advanced segmentation we’re going to be learning how to use keywords like and and when to break down analysis even further with that i’ll see you in the next one welcome to this last lesson on using case statements in order to pivot data and in this lesson we’re going to be going into advanced segmentation so what is segmentation well it’s a really important data analytics concept in order for you to take large data sets and break it down into smaller pieces in order to analyze different behaviors as a data analyst i’m applying this concept all the time when i’m using large data sets so i can dive deeper into the details and understand different behaviors so how are we going to do this well we’re going to start off easy in our first one we’re going to learn how to use the and statement within a case when statement in order to analyze multiple conditions for that net revenue of all those eight categories we’re going to break it down looking at segmentation of year based on 2022 or 2023 along with looking at whether it has a high or low value median price mainly look at the net revenue for orders that are less than the median value and look at the net revenue for those greater than the median value for a second and also final example we’re going to be looking at how we can use multiple when clauses within a single case block this is particularly important whenever you need different outcomes based on different conditions and for the example we’ll be doing we’ll be breaking down the revenue into multiple different tiers so instead of looking at orders less than and greater than the median value with this we’re going to take it a step further and we’re going to be able to look at orders based on where they fall in certain percentiles now before we get into both those examples i want to just demonstrate it real quick how to actually use both of these concepts the first concept is we could use and to combine multiple conditions within a case when statement and this is simply just done by adding condition one and condition two and use that and end statement so for this one we’re going to be looking at two things quantity and net price i’m going to go ahead and run this query right here we can see based on our order date we can see things like the quantity and then also the net price what we want to do is create a new column and classify whether these orders are a high value order so basically i have a quantity greater than or equal to two and the net price is greater than or equal to maybe $50 and then if it’s not that we just want to call it a standard order so going to insert a new line underneath this select statement starting with our case statement and then indent it in to insert in when we’re going to be checking two things right we’re looking at what is the quantity and that it’s greater than or equal to two and adding in the and keyword we’re going to look at the net price and whether that one is greater than or equal to 50 in this multiple condition case we want to categorize this as a high value order else we want to categorize this as a standard order we’ll end this case statement and give it the alias of order type okay running this pressing controll enter we can now see that this allows us to do multiple conditions and those that have greater than one or greater than 50 are categorized as high-v value orders the second concept to understand is we can use multiple when clauses within a single case block now there’s no limit to the number of wens we can put into here but basically it’s shown as every time you have a when you then need to have that then keyword and specifying what you want after that and then usually end it with some sort of else now i find myself using this type of approach of multiple when statements whenever i have to break it up into different categories for example we’re going to be following the same approach right looking at quantity and net price but we’re going to want to categorize this now so previously we were just categorizing high-v value orders those greater than two and greater than 50 and everything else is a standard order instead we want to more precisely fine-tune this we want to classify when it’s a multiple high-v value item so greater than two and we’re going to change the value to greater than 100 then we want to also check for single high-value items so those that are greater than 100 but are a quantity less than two so one and then we’ll categorize those that are multiple standard items so those that are greater than two but still less than 100 and then everything else is going to be a single standard item so we can build on this query that we already used previously one thing to note is like i said we changed this so this is no longer 50 i’m going to change that to 100 and call this multiple highv value order for this we just enter a new line enter in our when statement and then use what we’re going to analyze for is the net price greater than or equal to 100 then in that case we’re calling it a single high-v value item next when quantity is greater than or equal to two then we’ll have multiple standard items and then finally the else will be a single standard item okay let’s go ahead and run this bad boy and scrolling on down we can see that it appropriately classified based on these multiple different conditions pretty neat all right so if there’s anything you get out of this video it’s these two concepts because we’re now about to get into more technical examples to demonstrate how you would use this in the real world so as always i like to start out with what we’re going aiming to achieve in this and similarly we’re going to continue our analysis looking at our categories but for this we want to not only break it down by year looking at revenue in 2022 versus 2023 but the reason why we need this and condition is we want to segment it further in order to understand the low revenue and high revenue what do i mean by that in the last lesson we looked at what was the median order value for a single order well basically we want to see what is the total or net revenue for orders less than median and then what are those greater than median thus high now technically as we showed in the last lesson we have median values for each of the different categories in order to understand how this and condition works in here we’re going to keep it really simple at first and we’re just going to calculate a single median value for all the categories and apply it to all so let’s start by calculating that median value we’ll start with select and then use that percentile continuous function and then use within group as our bridge to then put in order by for calculation of our net revenue of quantity net price and exchange rate we’ll name this as the median for right now we need this from the sales table and since we’re working between 2022 and 2023 we’ll add a wear clause on this as well specify and use an order date between 2022 and 2023 and i have a syntax error because i applied an alias of s for sales we’ll be using this later so we’ll keep it i’ll add that s there run this again and we get a median value of 398 so remember what do we want to do we want to calculate basically the revenue that is less than the median value and the revenue that is higher than the median value so just as a reminder we’re trying to calculate with that median value of 398 for orders that are less than 398 what is that total revenue low revenue and then also the higher what is higher and doing this for 2022 and 2023 so what i’m going to do is go back to the problem that we used previously because we reuse this where we’re calculating those median sales um at the end of lesson two in the last lesson i’m going to go ahead and copy this and then back in our blank notebook underneath our median calculation i’m going to go ahead and paste this in now we’re not going to be using these median sales like we calculated it right here so let’s just run this to see what we have right now and it should just show all eight of our categories now we can add in those calculations so specifically for this one i don’t care about the 2022 and 2023 23 i just want to calculate the low net revenue and the high net revenue we’ll start with low first we know we’re going to be adding everything up so we’re going to be using the sum function for this and then we’re going to have a case when condition and it’s going to have that syntax of case when the condition then the value and then end it and we’ll end it with the alias of low net revenue so the condition is we want it to be less than that 398 that that order value is so we’ll add in quantity time net price times exchange rate and make sure that it is less than 398 this line’s getting a little long so i’ll go ahead and bump this on down and then also indent it in and now we need what is the value well the value is what is that revenue so i’ll copy the same formula that we used above command c and place this into value one so let’s go see if this works right now as written and looks like it does do these numbers make sense yeah they do so now let’s add a statement for the high net revenue i’ll go ahead and copy this all add a comma and then paste it into here changing this to greater than equal to 398 and then changing this to high and then going ahead and run this make sure we have no errors looks like we have everything here so now we’ve at least gotten that low net revenue and that high net revenue the next thing we need to do is now actually segment it down based on 2022 and then 203 and this is where we’re finally actually getting into what we’re trying to teach with this concept of using an and in a case when condition specifically inside of our case when we can use two different conditions using that and keyword so basically we want to add our multiple conditions right here inside of here before the then so what i’m going to do is enter down and then indent in and start that second and condition so we’ve already checked for the first condition of hey is it less than the median value the next thing we need to look at is the order date between january 1st 2022 and december 31st 2022 and i can actually go ahead and copy this and also place it in this condition as well i’ll then update this to be this is 2022 and this is also 2022 let’s run this make sure that it’s working properly and i got a little bit of a typo i added two betweens in here i don’t know what i’m thinking there try it again okay now it’s working all right this is looking pretty good now all we got to do is add in 2023 so i’ll use gemini for this cuz i don’t really want to fix all that code paste in the formula giving you the prompt of add in two columns for 2023 it generated it so i’ll add that code cell in and then from there add in that uh sql magic command run this pressing controll enter and bam now we have that net revenue for 2022 and 2023 whether low or high so that’s how you use the and condition but i’m going to be honest this query i don’t like hard coding in values like this and so i’m going to show you real quick a little advanced technique so that way you don’t have to hardcode values in so if we scroll back up to our original query right here that actually calculates our median value we can use a cte to insert in this value into that query now as a refresher for cte they start with that width command and then from there you’re going to be assigning the name of that cte so i’ll name this one median value and use as from there i’ll put an opening and closing parenthesis along with actually pasting in that value i like to indent it in to just make it easier to read we’re not using it yet but i’m just going to press control enter to make sure that my query is still operating correctly it is and then now all i need to do is insert it into this from command right here so i inserted it in as median value giving it the alias of mv and then if we remember the column name is median so i’m going to replace that 398 remember we can press command shift l to select all of it and then type in mv.median okay let’s run this bad boy hope it works and it does gets our final value now this is pretty good now that we can see these breakdowns between the years based on high and low net revenue we visualize this we can actually understand better what happened with the computer sector specifically remember computers drop down in revenue well it’s not for those low revenue or those value of orders less than the median value really what happened was is they saw a drop in the orders for those high value orders those that are greater than the median so pretty interesting insight that we found out and we actually break it down further in the next example in this example we’re going to be building on that last example further by using multiple when clauses within a case block previously we were only using one when clause but we’re going to actually step it up a notch and use two when clauses why is this important well this is going to allow us to segment within a column into in our case different revenue tiers so all of these will be categorized whether high low or medium along with the associated calculating for the total revenue so what does this high low and medium revenue even mean we’re going to be segmenting based on where an order falls within its percentile specifically if an order’s revenue is less than the 25th percentile we’ll cate categorize this as low between 25 and 75 is medium and greater than 75 is high now why this 25th and 75th percentile well it’s actually pretty common in statistics to use these values in order to bucket things into their different quartiles technically statisticians like to call that range between 25 and 75 the entire quartile range we’re just going to call it medium and then everything less than this low and everything higher than this high so that’s the basis on where we’re getting these numbers for now you may be like luke how the heck do i calculate the 25th and 75th percentile but remember the median is the 50th percentile so that’s why in this case we use that 0.5 so let’s go ahead and copy this that we used before and i’ll put in here.25 and we’ll call this that 25th percentile going ahead and running this we get an error because silly me can’t start an alias with a number in sql we actually need to use a letter to start so i’ll just say hey this is revenue 25th percentile and now run this okay not bad let’s do this for the 75th percentile and adding all in pressing control enter we have the 25th percentile and 75th 75th should be much greater than the 25th as expected looking good all right we’re going to be using these values in our final query so we’re going to be not going to be hard coding them in so i’m going to create another cte so i’ll go ahead and tab this over and then from there create a ct of percentiles and then assigning it inside parenthesis here so running this make sure it works just fine not going to cuz i need to insert a query below it i don’t want to start from scratch with that bottom query so i’m going to actually just going to scroll up to that previous one that we just created i’m going to copy this one and we’ll modify this one to make sure that it works pasting it in here first thing i’m going to just get rid of all of these conditions that we created along with that median value because we’re no longer using it but i will go ahead and add in that cte of percentiles and we’ll just name it something like percentile okay let’s actually try to run this and i can see what the error is now i have this comma after the end before the from let’s try this again okay we got all the categories as expected and we have our cte inside of there so the first thing i think the easiest is because we already have this group by and everything like that let’s add an aggregation in here to actually provide what is that total revenue so we use the sum function for this then we’ll add in the quantity time net price time exchange rate and we’ll give this the alias total revenue all right let’s go ahead and now run this all right so we have our categories and total revenues we now need to do one more step and this is actually what we’re trying to learn of implementing specifically breaking down all these different categories into those revenue tiers and so for this we’re going to be using the multiple when statements within our case i’m going to go ahead and copy this right here and then paste it in between here all right so the first thing that we want to check for is whether we’re mean that low tier condition basically that the order revenue is less than that 25 percentile so for the condition we’re checking whether this value here i’m going to go ahead and copy this and paste it in here is less than or equal to that revenue 25th percentile that we’re calculating up here so we brought it in with that alias of pctl and that’s that revenue 25th percentile and we’re going to assign it the value of low for the next condition i’m going to go ahead and just copy this right here paste it into condition two and i’m going to just say we want to check to make sure that it’s greater than or equal to the 75th percentile in that case it’s going to be high everything else is going to be classified as medium for the alias for this we’ll name it as revenue tier all right looks like everything’s in order let’s go ahead and run this bad boy press a control enter and we get an error which i’m catching it because it’s pointing out that it’s with the when clause right here now we’re aggregating right we’re doing the the sum of the total revenue based on these different tiers so technically we also need to do a group by for this so underneath here i’ll add in revenue tier sher run this again and bam now we got it not too bad now technically i would like in the order i’m a little nitpicky i would like the order low medium high so i’m going put number values out in the front of these in order for it to be able to actually order in the correct order so i need to actually add that in underneath the category name and we’re going to do an revenue tier run control enter we got a comma run control enter okay now we have it and better order high medium low 1 2 3 and this is pretty neat cuz we’re able to do multiple segmentation in order to analyze these different revenue tiers and we actually visualize it when we put into something like a 100% stacked column chart we can see that we have the high the light blue whereas medium and low are getting darker something like that computer sector that we keep on talking about they are very reliant on their revenue coming from those high ticket items those that are greater than 75th percentile whereas something like games and toys are highly reliant on low and medium value items so pretty interesting insight one last technical note for both the first and last problem we used these 25th and 75th percentile across the entire range of categories and similarly for that first problem we use the median value across all the different categories technically this isn’t necessarily the best practice you should do for this we went back to that first problem you’d actually want to calculate the median for each of these different categories and then from there actually segment it down and break it down further but whenever we look at the query it breaks down it gets a lot more complex and isn’t really what the focus is of this lesson focusing on that adding multiple when conditions or using that and condition but if you like to see the nitty-gritty technical details they are in the notes all right you now have some practice problems for you to go through and get more familiar with using these multiple different conditions for segmentation with that we’ll be moving into the next chapter on dates and we’re doing a lot of different functions with that with that see you in the next one welcome to this chapter on date calculations and in this we’re going to be learning how to use different date and also time functions and keywords in order to analyze data now the first lesson we’re going to get an intro and how this is useful in performing time series analysis specifically we’re going to use things like date truncate and two character in order to calculate things like the number of unique customers or net revenue per month in the second lesson we’re going to fine-tune how we can extract out certain components of the date and also use things like the current date or now in order to investigate certain time periods from when we’re analyzing it and in the final lesson we’ll cap it off with keywords like interval and functions like age in order to calculate things like average processing time and compare that to the number of orders we have and this is all very important and so kelly and i included this in these beginning chapters because you’re going to see as you go throughout the rest of the chapters a lot of the concepts were learning with how to manipulate dates are going to be used in those future chapters date and time data is everywhere you go you can’t get away from it now i highly encourage you for any of these functions or operators if you’re curious of learning more go into the source documentation which provide the link over here or maybe over here so we’re going to be using the date trunk function so what does this do well in date trunk you provided a field that you want output from it whether something like seconds minutes hours days weeks whatnot and you provide the source usually this is in the form of a date or time so let’s go over a simple example first i’m open up with a blank notebook here i just have a simple query where we’re looking at the order date because that’s what we’re going to be manipulating with this date trunk formula from sales and we only have 10 uh outputs so i’ll controll enter okay this is good now all these dates are the same um but i want to be able to see all the different dates so a little trick you can do is i’m going to use order by and then use the function random now whenever i run this pressing control enter i’m getting random dates right here so we can better see if it’s actually applying to a lot of different data anyway let’s get into that date trunk function so typing this function right here we can see that it also outputs in here hey we first need our date expression and then we need our date part which i just clicked to open up we can also use this documentation to further investigate what is going on here so pretty convenient of what’s going on here okay so we’re going to first input in that date expression and it’s a string so it needs to be in single quotes i’m going to put in month from there we need to put in the date part so i’ll put in order date now we’ll run this pressing controll enter and we get if we see these these order dates we can see that it’s just the month now notice the data type of this it’s getting converted to a timestamp and this is a little bit inconvenient and a little bit too verbose for me so we can clean this up specifically if you remember from a few lessons ago we can use this double colon sign which is the cast operator and we can cast this instead of as a timestamp as a date running control enter now i just have it output as a date take it one step further and also just rename this as order month and we’re good to go all right so what are we actually trying to calculate in this exercise this is the final table that we’re aiming to get to in it we have the order month which just showed you how we did and we want to get with this we’re going to use group by to analyze the net revenue and also the total unique customers so let’s start with that query that we just previously built we’re going to add onto this by first calculating the net revenue remember we use the sum function for this this is calculated by multiplying quantity times net price times exchange rate and this is our net revenue so i want to make sure that this is operating correctly and silly me we’re doing an aggregation of sum so we need to perform some sort of group by so instead of this order by i’ll put in a group by and specifically we’ll call out that we want to do it by the order month i’ll also go ahead and just remove out that order date so we don’t have to add it to that group by run control enter okay not bad getting net revenue per order month we only have 10 results right here i have it to limit 10 mainly i do that when building queries so they operate more quickly i’ll take it off at the end next thing to get is total unique customers so i’m going to go ahead and add that in we need to do a distinct count of the customer keys so count and then distinct specifying customer key and then we’ll assign the alias of total unique customers running this okay we got totally unique customers net revenue and order month so exactly what we needed out of this we can go ahead now remove that limit 10 and press ctrl enter bam now date trunk is really great especially if you just want to specify one attribute you want to extract out of it such as something like month as we did you could either do quarter year decade century or even millennium and so if i like to customize it more i like to use the two character function specifically you provide it something like a timestamp and then the text output and it outputs it in that text format scrolling on down we can see that it has a host of different options that we can use for this you can specify a lot of things like hour of the day year even things like month and the good thing about this is you can actually combine these together in a format or in an order that you want so let’s just show this simply by implementing in order date and formatting them as month and year we go ahead and press control enter and we have our random dates right here let’s now add this new function in in its own line so enter two car and then the next thing is the actual field itself and then next is what we want to output so in the case that we want something like just the year only i’m going to put it in single quotes and then go ahead and run it and we can see unlike the last one where we had to like cast it as a date and remove all the time and stuff it just outputs what we need and then if i wanted something else say not only the year but also the month i could just put it in there so double m in that case running control enter now we have the month and year so this table is super helpful in understanding what are the different formatting options that you have for this what you can use so back to the original example that we were working with we can actually replace this entire line and use this two character function specifying order date and then how we wanted it formatted and of course we’ll give it that alias similarly of order month so it’s performing the group by properly i’ll press control enter and so let me forgot a comma after this and so now i feel this output is a lot more readable regarding this order month because that removes that day and we can actually see what it is for each of these months the revenue and total customers now we because we aggregated this on a monthly basis vice that daily basis that we were previously doing we removed a lot of noise and from this we can see that in 2020 we had obviously some sort of worldwide event that caused an impact in the number of unique customers and also net revenue that we had but it looks like as of 2022 these numbers have returned back to normal except a slight dip in 2023 maybe something we’ll have to investigate later all right it’s your turn now to go and test these out we have a few short practice problems for you get more familiar with this in the next lesson we’re going to be jumping into even more complex formulas such as current date or even now with that see you there in this lesson we’re going to build further than we learned in the last lesson specifically by understanding more about how we can actually filter dates and even do it dynamically first we’re going to learn two more functions on how to format different dates and for this we’re going to be diving into how we can analyze things like the net revenue for each year for every category and then from there we’ll use things like current date and now to basically filter data by a certain time time frame from this time period now pretty neat all right first of the two functions is date part and this one extracts a specific component from a date or time stamp as we can see we have date part function unit and then what is the source or column name host of different options so with the sample query we can look at things like the year month or date here we’re using that date part function specifying those different components the applicable column and we give it appropriate aliases one thing to note with this which is not necessarily my most favorite part is that they come in with precision so they have decimals after it and i don’t necessarily want this depending on what unit i’m working with because of that i prefer to use something like extract and it has a very similar format to date part it’s actually based on date part and we can see as going through this we can do things like day decade dow and whatnot basically all the same things that we can use in date part we can use in extract the syntax for this is slightly different though in this case we’re going to use the unit and instead of doing a string for it we actually do an uppercase actual variable name and then we say from the source in our case our column name so this bottom query is using that extract and we’re going to do exactly the same thing that we did just above in that similar example using date part we specify year month day from order date and provided the appropriate alias for it let’s go ahead and run this bad boy and like i mentioned i like this one a lot better especially when dealing with things like year months or dates where i want in your digits for these values so let’s use this extract function in order to analyze the net revenue per order month now previously right we use this two car or two character function to actually analyze per order month what the net revenue is let’s instead create columns for months and then also for years so i’m going to go ahead and remove this portion right here and put in extract it gives us a hint up here we want to put in the part first well we want the year next we’re going to use the keyword of from and then the date expression specifically we want to use order date we’ll give it the alias of order year next we’ll get into adding that month one we’ll write the extract formula do it for month from and specify order date for this we’ll give it the alias of order month now the group by for this we’re doing two columns now so i’m going to want to actually do order year and order month this looks good let’s go ahead and run it and not bad it’s all over the place so i’m actually going to go ahead and change this to do an order by at the end of this so that we can get some semblance out of this data and bam this looks a lot better and now we have this in different columns so depending on how those that i give this data to they can slice and dice it even more easily all right let’s actually get into some new concepts and implement dynamic filtering by using things like the current date or the time now in order to filter back let’s talk about current date first so typing a simple select statement along with current date it provides me the documentation for this and it basically says hey it returns the current date as of the specified or default time zone parentheses are optional when called with no arguments basically you can provide a time zone if you want anyway running this we can see we get the current date i’m filming this apparently i’m filming this on valentine’s day that reminds me i need to call my fiance and actually wish her happy valentine’s day so i’m glad i saw that anyway that’s current date let’s go to the next one and that one is using the function of now similarly i can run a select statement with this just calling the function make sure you do have an open and closing parenthesis and we run this and we can see that it is valentine’s day at 2:30 in the morning okay actually not filming this at 2:30 in the morning this is actually green witch meime which is over in england so that’s what time it is there so that’s why for the current date it gives you the option to actually throw in a time zone in there to update it appropriately so what are we going to be calculating well the short answer is we’re going to be looking at understanding what is the net revenue per category for those orders 5 years ago back from today we’re basically building this table the important thing to understand is this this is a dynamic filter and these type of things are very important and understanding to do because sometimes you want to or you’ll have workflows set up that run queries automatically at midnight and you don’t want to be pulling in all the data maybe you only want the data for the last 5 years and things like this are great for that so let’s start with a base query that we’ve seen time and time again first we’re going to be extracting out the order date the category name and then perform a calculation for net revenue we’re going to be doing this from the sales table and left joining it with the product table on the product key and then because we’re doing aggregation above for the net revenue we need to actually group it by the order date and the category name pressing control enter we got this and it looks like these dates are unordered so i’m going to go ahead and throw in an order by run this and now we have the order the dates in order so we only need one do one more step but i’m going to break this step down because we want to include only orders within the last 5 years basically we shouldn’t be seeing anything from 2015 i’m in 202024 as of filming this so we’re going to create a wear filter in here to do this but i want to break it down slowly to show what’s going on step by step so i’m going to insert in how what components we’re going to use to filter within a wear clause we’ll start simple first we’ll look at current date and see what it outputs to here as expected we get to see it’s valentine’s day now in order to extract out these last five years we need to get what is the year in the current date and also what is the year in the order date so for this we’re going to use that extract command we want from it the part which is the year and we’ll do from we’ll keep it simple first with just the order date i’ll give it the alias of order year running this see it’s working just fine we’re getting that order year for all those different order dates next let’s extract out the year from the current date so we’ll just put in here that keyword of current date and we’ll say this the alias of current year run this okay not bad now we want the year that we’re going to be filtering by right we want it to be basically 5 years ago so all we need to do is i’m going to copy this one we’re going to be getting rid of all these um but i want this one right here and instead what we’re going to do is we’re going to do minus5 and we’ll set this one as minus5 clever i know running control enter we can see that the minus5 is actually five behind this so what we need to do in our wear clause is combine these in a way to where it filters for that so wear clauses go underneath from or the left join and for this we want to make sure we want to see the order year so i’m going to go ahead and copy this above c is greater than or equal to this minus5 value that we did right here and i’ll go ahead and post that in here let’s go ahead and run this crl enter and bam now this is a little bit hard to read but we can see just looking at the order date column these are the orders for the last five years i’m going to go ahead and remove these unnecessary values now we don’t need this anymore that was just for building this and we can see that we have this now this query’s built for the last 5 years now you may be like “luke this is it’s valentine’s day right now but this is going back to january 1st 2020 what if we went to be very precise about that?” and i’ll say “aha to that we’ll answer in the next lesson.” all right you now have some practice problems to go through and get more familiar with using these different things and creating your own dynamic filters in the next lesson we’re going to get into date differences basically using functions like age to measure the time between different dates with that see you in the next one in this third and final lesson on this chapter on date and time function objects we’re going to be going into now understanding how to calculate intervals in the first half we’re going to continue on from that problem from the last lesson and instead of making really that verbose way of calculating the last 5 years we’re going to use the keyword of interval to write much more succinct queries and readable queries to understand what we want to get an interval of in the second half we’re going to be going into a pretty interesting business problem of exploring average processing time so in order to calculate this interval between the order date and also delivery date which we know we’re going to use functions like age and also show what can be done with that previous function of extract first let’s explore how to use this keyword of interval interval can represent a span of time such as days months hours minutes decades or even weeks and we use this by using the interval keyword and then a value and unit so let’s test this bad boy out i’m going to run a sele simple select statement specify the keyword of interval and then let’s do something like five centuries with this we can see that it gets the title of interval and it calculates it to be 182,500 days anyway normal output for this is in days whether you’re using centuries or even use something like months running control enter comes out in days so how can we use this in the query that we used in the last lesson to filter for orders within the last 5 years i’ve simplified the query basically we’re pulling out the current date order date from that sales table and we use this formula of pulling the year out from order date and the year out from the current date and subtracting five run this we can see that the current date is valentine’s day and the order date is within that last 5 years now notice this right i called it out last time this goes all the way back from january 1st 2020 so technically this is slightly greater than 5 years so let’s write this query a lot more succinctly i’m going to go ahead and remove this portion right here and for this we want to make sure that the order date that we’re actually trying to filter for is greater than or equal to dates of 5 years ago so we can use once again that current date and we can subtract from it the interval of 5 years running this bad boy we can see that this one now does the last 5 years as shown by the order date and it’s very specific right it gets all the way down to filtering it to february 14th valentine’s day in 2020 so getting into cleaning up that full query from last time this is actually it right here if we run it again we can see that it does the current date the order date category name and net revenue so it breaks down by category the different net revenues this one technically remember wasn’t 5 years so what we can do is go back and replace this portion right here with that newly formated clause that we came up with and then whenever we go ahead and run it we can see that now we have it for the last 5 years all right before we get into age and also review of that extract function let’s look at what we’re actually trying to solve in this portion of the lesson if you recall back we have two columns an order date and delivery date column i forgot to put a comma here so it’s not appearing now it is um so we have things like order date and delivery date what we can do with this type of information is calculate how long what is like an average processing time for a customer to receive an order it’s a very important metric whenever used in business analytics so what we’re going to do by the end of this is show on a yearly basis not only the net net revenue which is those blue bars but also what is the average processing time for those years and we find that it’s going up so what are we using for this well we’re using the age function and with this we provide two in this case timestamps we provide dates and it’ll output an interval let’s do a simple example first running it just right inside of a select statement we’re going to be using the age function and then we’re going to provide it two dates now i have a couple of errors with this i’ll go ahead and run this first pressing control enter and we have this render age and it says hey no function matches the given name and argument specifically it says age integer integer i don’t want to evaluate integer i want to evaluate as a date the problem is with the date we have to provide it as a string so make sure you have single quotes around it running controll enter we have it now if you notice from this i did the 8th of january to the 14th of january and it’s saying it’s -6 dates for the age function to get a positive value you need to provide the end date and then you need to provide the start date so i’m going to go ahead and place these in the correct order running this get six days now let’s say we want to do some math with this i have currently six days and let’s say we wanted to subtract i don’t know five days from this if i put in here after this minus five and try to run this i’m going to get an error specifically it’s going to have that the operator does not exist interval minus integer right now this is an interval and we’re trying to subtract an integer we need to convert this portion to an interval sorry i mean integer need more coffee well we can use the extract function i’m going to go ahead and remove this all cutting it out we’re going to use the extract and we need the part and then specify the from keyword and then the date expression for this we’re going to specify day it doesn’t need to be in single quotes for this it understands that keyword of day i’m specify from and then for the date expression i’m going to go ahead and paste in that age now running this pressing controll enter we can say see that we get that six from this and i can do the minus five from this now pressing control enter we get one so let’s get into calculating the average processing time by year and we’re going to be doing this for the last 5 years similar to this table we also need to calculate the net revenue but we’re not going to do that until the very end because it’s going to make our query a lot longer with actually joining in the table that has the revenue data so let’s start simple first and let’s just look at the order date and delivery date and we’re going to be getting this from the sales table now let’s put in a new column in for the processing time we’ll throw that age function and remember we need to put the end date first so that would be the delivery date followed by the start time or the order date and we’ll name this as processing time this query is getting quite long so i’m going to go ahead and throw in a limit of 10 in here just to start with running this we can see we’re getting basically zero processing time everything’s getting delivered on the same day that it’s ordered i want to see a little bit more different orders so i’m going to throw in an order by random and run this and now we can get some actually that have some days in there to show that okay this is actually working so let’s start getting the average processing time and aggregating it based on year because of this we need the year for this i’m going to use the date part function and as the first argument we need to specify what is we actually want we want year and we want that out of we’re going to go with the order date of when it actually started we’ll give this the alias of order year now next thing we do is actually get into aggregating this age but remember we have this processing time is an interval of of the data type interval so 3 days 0 days it’s not going to be able to actually average that so we need to use that extract function first and i need to specify the part from this specifically it’s the days and specify that from keyword and then age delivery date and order date i’ll then put a closing parenthesis on this and then rename this alias to average processing time now we’re doing an aggregation so one we’re going to need to specify a group by and then because of this we don’t need to have that order date and delivery date because we have to aggregate by that and so i’ll remove this order by random and we’ll throw in a group by right here specifying order year also this won’t have a lot of outputs i’m going to remove that limit statement then running this and silly me i’m reading this here the delivery date must appear in a group by clause or be used in aggregate function basically i forgot to use the actual function right here oopsies throwing that in of average and now running this we are getting the average processing times all right we need to clean this up still these years are out of order and these amount of digits on here are just unreadable so i’m going to throw in an order by clause underneath here and we’re going to order by the order year running this we now have it in order and now let’s clean up this average processing time i only really want two digits and if you remember from the basics course we went over the round function in there and with the round function you provide the value or column x and then after that n is the number of actual digits that you want or decimal places after this so if you don’t use anything with zero digits but we want two so we’ll go ahead and put two on there run control enter bam got average processing time over well we want to do the last 5 years so from our previous example up above i don’t like typing code if i don’t have to i’m going to go ahead and copy that wear clause and then putting it underneath the from statement now running this we have for the last years the average processing time all right now just one last thing to do we need to now add in that revenue based on each of those years for this we’re going to be using the sum function to sum it all up and we’re going to be multiplying quantity time net price times exchange rate and we’ll give it the alias of net revenue all right let’s go ahead and run this not too bad typically with these high of numbers i don’t care about these two decimal places so i’m going to use the round function again and in this case i’m not going to specify an argument at all run this and okay it looks like it’s given it two decimal places with just 0 0 what if i can just specify this and looks like i can’t specify zero but instead what i can do is i could give it something like cast and then for cast i can specify that i want to cast it as an integer we’re going to control enter bam now we have what i want and then if we graph this we can see that the average processing time over time has gone up from around a little less than one up to 1.6 even with the dip in revenue or i think the number of orders probably loosely correlated we still saw the average processing time go up so this is a good little data point to keep track of and we can pass on all right it’s your turn to go through you have some practice problems to get more familiar with the extract age and also interval keywords and functions and from there we’re going to be going into the next chapter after that on window functions pretty complex topics i’m looking forward to get into it see you there all right welcome to this chapter on window functions this is probably the most requested topic for me to cover in this intermediate course so i was super excited to get into this now we’re going to break this chapter up into five lessons starting with this lesson focusing on the syntax of window functions doing some simple examples and explain it to you then we’ll start picking up the pace looking at things like aggregation ranking lag lead and then finally we’ll close it off looking into how we can use things like frame clauses well this doesn’t matter unless you really understand what window functions are so let’s look at a simple example so let’s look at a query that’s breaking down the net revenue by an order number in it i’m listing things like the customer key and then the order key and then the associated line number for that order calculating the net net revenue and then getting it from sales we’re then ordering it by the customer key so what’s going on here okay customer key 15 made only one purchase of over $2,000 but customer 180 did three separate purchases where two of these purchases of were the same order they just have different line items so now let’s say based on all these individual orders we wanted to find out because we want to do some deeper analysis what is just the average order specifically what is the average net revenue for an order what i could do is run an aggregation function removing all those other different columns and just run it here and see that the average order order value is 1,000 but i want it in this table and i can’t get that necessarily unless i actually get it in this type of format using this aggregation but this is where window functions come in instead all i have to do is just insert in our window function don’t worry we’ll go about it over in a second it’s using the over function in this case go ahead and run it and have an error because i got a comma in here and we can see that it’s the same value as below of 132 but it’s now in our original table just like we want it so we can do even more calculations with it so why use window functions they let you perform calculations across a set of tables related to the current row like we just showed and like we showed they don’t group the results into a single output row this is very beneficial as we’re going to demonstrate some future exercises so this is using it for things like running totals ranks or even averages anyway let’s get into the syntax for this we start by defining the window function or what we want to do if it’s an aggregation something like sum or count if it’s ranking it’s something like rank or dense rank the next is over and this defines the window for the function inside of it we have the keyword of partition by we’ll get that in a second let’s actually go back so let’s walk through that window function that we just saw without using partition by and i’m going to create a new line and for this the window function we’re going to use for this is average because we’re calculating what is the average net revenue from there i’ll put our variables in there of quantity net price and exchange rate then we’ll put over and it’s very important after this that we include open and closing parenthesis even if we’re not going to put anything in there and then i’m going to give it a very verbose title to make sure we understand what it means the average net revenue of all orders going ahead and running this we can saw similar to before it’s at 1,032 but now let’s say we wanted to filter this type of window function further maybe by something like the customer key and this is where partition by comes into effect it divides the results into partitions or better said divides it into separate groups without actually having to use such as a group by clause to do this so going back to our previous example i’m going to go ahead and copy this all so we can see it add a comma new line and paste it in and this one we’re going to find partition by customer key and we’ll say that this the average net revenue of this customer let’s go ahead and run it and scrolling down we can see for customer 15 it only had one order so that’s the average net revenue whereas customer 180 had multiple and the average of that was 836 so let’s just briefly explore the power of window functions by looking at a simple example i’m not going to ask you to follow or understand the syntax because we’re going to get to it later on but this is going to demonstrate the features that we’re going to be getting to in this chapter so here we are looking at things like customer key order date and net revenue i’m going to go ahead and run this so let’s say for each of these customers we wanted to rank their orders from highest to lowest based on net revenue well i could use something like this window function that’s using row number and some other stuff that we’re going to get to and in this case we can see that it actually calculates the rank for this specifically it has the highest at rank number one and the lowest at three for 180 now let’s take it to another level we could do something like calculate the customer’s running total so in this one we can see with 180 that has multiple orders first it’s at 525 and then it jumps up to 2500 these orders on the same day so the running total is the same we could also do things like get the customer total net revenue and this one isn’t really that impressive because yeah we could see that it gets the total but personally i like it because i can then use this to maybe calculate hey what percent is this order of the total net revenue of a customer in that case i can just add it in doing the net revenue divided by the window function to figure this out and so now i can the table by the way and now i can see what is the percent of the revenue for a customer so this makes even more unique of why window functions are so powerful so let’s actually get into applying those concepts so you can actually write those queries like i just ran through what we’re going to be finding is the percent daily revenue based on an order line item to do this we already know how to do net revenue we’ll need a window function to calculate daily net revenue and then we’ll calculate a percentage from that so let’s start building this query out we’ll list the order date the order key the line number which an order or an order key could have multiple different shipments with it so therefore it has different line numbers and then finally we’ll just start with the net revenue we’ll get this from the sales table and we’re just going to limit it to the first 10 all right so and as mentioned the line number right it just says 0 1 2 3 the highest number in this is six i don’t really like that these are two separate columns so i’m actually going to combine it i’m going to take the order key and multiply it times 10 so basically adds a zero to the end and then from there add in that line number and then i’ll give it the alias of order line number we can see that what it looks like actually here it gets accomplishes what we want so i can go ahead and remove line order and order key so the first thing we want to calculate in our final table is that daily net revenue in order to do that we need to use the sum function on our net revenue and now we want to use over and then inside of over that partition by remember we want the daily net revenue so we’re going to be putting the partition by of order date and from there we get that daily net revenue now now we want to calculate finally the percent that an order line item is of the daily net revenue this one’s going to be pretty simple as it’s going to be a lot of different copy and paste so first i’ll drop in the net revenue i’m going to multiply it times 100 so it gives us a bigger digit for that percentage and then from there we’re going to divide by all of this window function right here which i’m going to copy and paste into here and we’ll give it the alias percent daily revenue not too bad it’s all over the place i want to actually see this ordered for this day to see what is the highest so i’m going to put in an order by specifying the order date and then the percent daily revenue but for this one i want it in descending order and bam we get this final table showing this percent daily revenue based on the order i went ahead and graphed it so we could compare the different order line items for that day and we could see that some of the orders i mean these are taking up of 20% up to 10% of the entire daily net revenue and conveniently up the top of the chart but the total daily net revenue so it’s pretty convenient for window functions that we can get all this type of data into a single table and it makes it a lot easier later on whenever we dive deeper into it and maybe visualize it one minor note on this query it is getting a little bit verbose in that a lot of this is repeating stuff that we could reuse and that could be done using something like a ct or subquery what i could do is actually just put it into its own subquery of the core items that we need from this so the order date order line item net revenue and daily net revenue and then from there put it into something like a subquery so i’m going to go ahead and tab this over and so that way we can do a select star from and then put this all within parenthesis and we’ll give this alias of revenue by day so it still has the same output in below but now instead of having to repeat all that different code here like i did to calculate the percentage i just come up here and then insert a new row specifying i want to do 100 times the net revenue divided by the daily net revenue and give it the alias of percent daily revenue now running this boom this has everything that we have or want out of it and in my mind it’s a slightly easier to read and to get through when sharing with others so let’s now get into performing a cohort analysis in this last example and cohort analysis is going to be done a lot throughout this project because it’s pretty popular in business analytics all right what the heck is this well a cohort is a group of people or items sharing a common characteristic and then the analysis of this examines the behaviors of this over time specifically the behaviors of that group being a personal item so what does this even look like well for this example right here this is what we’re going to be doing and analyzing or putting people into cohorts based on the year of their first purchase and then from there calculating what portion of the revenue they are contributing to the net revenue so down at the bottom is the purchase year and then over on the y axis the net revenue in 2015 where this is the data that starts it starts in 2015 everybody contributing this is from cohort 2015 so that’s all the net revenue then we get into 2016 we have their 2016 cohort along with it’s a small contribution from the 2015 cohort in 2016 we work our way all the way to 2019 and we can say see once again that the cohort of that year is the largest contributor whereas those from previous years are less of contributors now it’s important that you understand for this example that the cohort is based on the first year that you made a purchase so what are we aiming to get out of this well we want to have this final table where we have the cohort year or the year of their first purchase and then from there the purchase year or the apparent year of the net revenue with the total revenue for that cohort so we’re going to start simple first with our first query looking at using a window function to extract out the cohort year based on a customer so we’ll start with the select statement specifying the customer key we’ll also do order date so we can see what’s going on there and we’ll get this from the sales table we’re going to limit this to only 10 values also have a comma right here we don’t want that going to press control enter and bam okay so we’re getting customer keys and order dates i’m also going to go ahead and just for good measure i’m going to order by the customer key so that way we can make sure that we’re looking at this all appropriately specifically if there’s grouping such as here is 180 i see them all together so now let’s use a window function to get our cohort year we’re going to start first by just getting what is the minimum date out of or for a customer so in the case of this 180 i would expect it to be this order in july so we’ll start this window function using the minimum of specifically order date and we’re going over and then inside of parenthesis we want to put the partition by of the customer key and i know it said date right now but we’re going to just name this the alias cohort year because we know we’re going to change it okay press control enter okay looking at 180 it is in fact that lowest date for order date as the cohort year now what we want to do is extract out that year from there so i’m going to run that extract function on this and we need to specify the part first so that’s going to be year and then from and then everything after this is that date expression so then i’ll put a closing parenthesis all the way in the end run this one thing real quick i did show that how it was 2018 but now look at this if we go to something like customer key 387 we can see that their first purchase was in 2018 but then later on in 2023 they still have that cohort year of 2018 so we know our formula is working so let’s go ahead and clean this query up because i don’t need this order date at all for what we’re doing it for so i’m going run control enter now i’m noticing we have duplicates because customer key is appearing more than once so what i can do is add a distinct statement right after this and now when i do this boom i’m only getting distinct values for the customer keys and the cohort year so this table’s a lot more concise um we also don’t need this limit 10 anymore and technically we don’t need an order by either this is good start so we figured out that cohort year for the customer this is once again the final table we want to get to now what we need to do in order to basically add these additional two columns on of the purchase year and the net revenue is we need to calculate this if you will separately and join in that cohort year using something like a cte so let’s put this all into a cte that we can then join to that sales table to basically attach on for all these different customer keys their associated cohort year and then we can aggre aggregate and find out what is that total revenue so we’ll use the width keyword specifying this as the alias as yearly cohort we’ll use as and then an open parenthesis we’ll tab this on over and then put a closing parenthesis and then i just want to make sure that this works properly so i’m going to do a select star and do from that yearly cohort above and run this to make sure that it is outputting correctly yep still the same table okay now let’s join this on to our sales table for this is very important we get the correct join for this specifically we’re going to be connecting to the sales table so i’ll put that right here and then for a join we’re going to be doing a left join we’re doing a left join because we want to make sure that we have and keep all of the different sales values from it and then we’re joining using yearly cohort which has been distilled down to remove any duplicate data so we’re not creating duplicate rows for each of these i’m going to give them an alias this one s and this one y and then as far as how we’re going to join this you’ll be on the customer key from both of these tables let’s go ahead and well let’s actually do a limit 10 because there’s a lot of data all right so just inspecting the table we can see we have the customer key of 947009 and then it is joined on that customer key along with its associated cohort year so just as a reminder of what we need to get to now we need to get the cohort year and then the purchase year or the year of the order date and aggregate all this to calculate what is the net revenue now when we do this aggregation we’re not going to use a window function this time we’re going to use a group by on these different years so let’s clean up these columns that we’re actually using we’re going to use that cohort year and then also the purchase year which is based on order date so we need to extract out the year from order date and we’ll define this as the purchase year let’s just make sure this is correct before doing our aggregation next okay good we have all the order years and purchase years now we want to move into getting a sum of all the revenues so we’ll use the sum function specifying the quantity times the net price times the exchange rate and we’ll give this the alias of net revenue and so because of this i’m going to be doing a group by specifically on that cohort year and also the purchase year which we’ll need to put the function in here going ahead and running this we can see we have our results and anytime you’re finding your or getting to your final results you need to make sure that the numbers are making sense specifically i know that the net revenue for 2015 was around $7 million and i can see from this that for 15 i say 2017 mean 2015 so for 2015 is owned 7 million and this checks out also silly me i could also use purchase year in this case doesn’t necessarily have to be the function itself all right so we want all the values for this because we’re almost there i’m going to go ahead and remove that limit 10 go ahead and run this and bam we have our final values where it shows based on a purchase year how much a certain cohort contributed to the revenue for that year and this is the ultimate visualization that we get to and we can see that pretty interesting enough the cohorts from previous years don’t really contribute that much to the overall net revenue so we have a little bit of a retention issue all right it’s your turn now to go in and get more familiar with window functions by doing practice problems in the next lesson we’ll be diving we’ll be diving deeper into aggregate functions and basically fine-tuning our knowledge of how to use window functions with that i’ll see you there welcome to this lesson on aggregation functions using window functions anyway we last lesson we went through and started to apply aggregation techniques to window functions but we’re going to build slightly more further on this covering three key concepts so in the last lesson we actually used the min aggregation function to analyze the impact on yearly cohorts on the total revenue as we went through the years well in this one we’re going to do a simple analysis basically reinforcing what we learned with cohorts but this time using the count function in order to analyze the total number of unique customers and how they impact based on their cohort into future years next we’re going to move into using the average aggregation function and for this we’re going to be focusing on the long-term value of a customer basically using window functions in order to calculate what is the total amount of revenue that a customer has contributed and we’ll not only be able to break it down on a customer by customer basis but we’ll also be able to analyze it from a cohort year perspective as well and finally we’re going to wrap it up with some simple examples on understanding how to filter window functions basically where you should be applying your wear clause in order to filter a window function properly all right let’s get into it so for this example we’re going to be using count in order to aggregate our window function the syntax is all the same so major concepts remain all the same let’s get into what we’re going to be solving for this we’re trying to find out the number of unique customers which we’re going to use the customer key for this and find out based on their cohort or the first year they bought an order how they contribute to future years this graph right now is showing the total number of unique customers every single year and then from there broken down by cohort so we can see from 2019 we had those from 2015 16 17 so on for the final output we’re going to be doing it very similar to last time where we want a table of the cohort year and then the purchase year and then the number of customers or the number of unique customers based on a cohort year and purchase year now you could start with the query from last lesson and modify it to fit your need for this but i find this question is actually more simple than the last one so we’re going to start from scratch also it’s just good practice so for this we want to get not only the customer key but also based on a customer we want to get its cohort year or the first year it made an order and then also a purchase year when the year of a purchase was we’re going to be ultimately using that customer key to get the unique count anyway let’s start programming start with a select statement adding in our customer key next we want the cohort year so similar to the last time we first want to get that minimum order date for our window function and then from there we want to do it over the partition by customer key i’m going to name this alias right now cohort year cuz we’ll eventually get it into a year format right now it’s obviously just date for this we’re going to be getting this from our sales table let’s go ahead and run this just to see scrolling down to that 180 customer key we can see that it is all from june so this is looking good next thing we want to do is extract the year out of this so we’ll do an extract we need the part which is year and then from and then the date expression which we’re going to wrap all in parenthesis and then we’ll put another closing parenthesis on there to for the extract we’re control enter and we have the years now next let’s get the purchase year and we don’t need to do a windows function for this right we just need to extract the year from our order date so i’ll do an extract the part is year and then we’ll do a from and then the date expression is order date we’ll give this a name purchase year and go ahead and run it okay overall looking good everything look like it’s calculating correctly now what we need to do is move into actually getting the count of the unique customers using that customer key and you may falsely think that this is actually going to be wrong code right here but you may falsely think that you could use a group by to do this specifically we’d want to do something like count the different customer keys or i should say count the distinct customer keys and then from there add a group by to do by cohort year and purchase year however when we ever go to run this we get the following error message window functions are not allowed in a group by basically we can’t combine these window functions and group eyes so trying to use group eye in order to calculate this and save some code not going to work here just wanted to point that out but what we can do is make this into a cte and then use that cte to run a window function on to get the customer key so for this to create our cte i’ll give it the alias of yearly cohort open parenthesis and put all the syntax in there next just to make sure that everything is working correctly i’m just going to call a simple select star on from yearly cohort run this and it’s still running properly okay we’re good to go let’s refine this now now remember this is the final output that we want we want cohort year purchase year and then number of customers so let’s work to build this table for this i’ll remove the store put in cohort year first put in the purchase year and then next let’s build the window function to go through and count the unique customer keys but we don’t want it just on one thing we want it based on both the cohort year and the purchase year so in this case customer key 180 was a unique customer in 2018 which is also the cohort year but then as a cohort year 2018 was a unique customer and also two 2023 so for this we’ll first start by doing a count and one thing i’m not with this right this has some duplicate data we want to get unique customers so technically i’d only want to see for 180 this 2018 2018 but then also for this 180 this 2018 for the current year and 2023 i wouldn’t want to see duplicates so what i can do first is i can add a distinct up here onto this query running control enter and then it’s not really showing because we remove the customer key i’ll just put it in for the time being running this again we can now see that for customer key 180 now it’s just those two entries so for this we’re going to be doing a count of customer key or you can do countst star over and then this is when we would get into our window function using partition by both the purchase year and then also the cohort year and we’ll name this as num customers so let’s go ahead and run this all right not too bad the one thing to note right is this is has multiple different duplicate lines because we have all those customer keys in there so once again what we can do is we can just add a distinct right after the select statement so that way we can get it filtered down to only unique values and then from that we can see that okay this is all on order now so now we need to actually do an order by so we’ll add an order by doing by cohort year and then purchase year and scrolling down we have what we want now and i know based on previous calculations that we had in 2015 only 2825 unique customers so this validates or help understand that this data should be correct so if i were to visualize it this is what we get and it comes out very similar to our total net revenue so overall not a lot of unique insights that i found from doing this compared to net revenue but at least we explored it before moving on i want to touch on a short example specifically around what we talked about just recently on this error message that we got when we ran this query where it said window functions are not allowed in group eyes technically this isn’t entirely correct as i’m going to show in a second we’ll be able to run window functions with group eyes but overall i don’t recommend using window functions and group eyes within the same query and we won’t be doing it for the remain of the course so i want you to learn this major concept now so let’s look at this simple example we’re going through and we’re going to collect the customer key and then using a window function we want to count how many orders that a customer has and so we’re going to partition it by the customer key and this will be the total orders i’ll go ahead and just run this and so we can see that customer key 15 has one 180 has three orders so they have a total of three orders everything’s working fine but now let’s say we want to calculate the net revenue but this time we want to group this all up because i’m tired of all these separate rows and so we’re going to use a group by with this to find the net revenue so i’ll put in the average and this will be of the quantity time net price time exchange rate and i’ll give it that alias of net revenue we’re doing an aggregation so like usual got to use the group by and we’ll do this of the customer key now when we go to run this query it is going to work notice remember 180 is at total of three orders and i’m getting an error message because i’m silly and i didn’t put a comma after this column go ahead and run this now and magically this query does work now right because we have an eye with a windows function in it but now going to that customer 180 they only have a total of one orders in fact if you look at all of them and i can move into this bigger table all of the total orders for every single one of this column here is one so what’s going on here well what’s happening is window functions in the process of running through this run after a group eye so what’s happening is everything is getting grouped together and then the window function is running this causes a major issue of conflicting aggregations so if you’re not getting an error message stopping you from this you’re probably not going to get the right results there are better alternatives which we’re going to go over and mainly that’s using cte or sub queries and breaking up your queries to separate them with our previous query what happened was we ran our group by aggregation to find our net revenue it condensed all those customer keys down to one value and then secondly it finally ran that windows function so that’s why it feels there’s a one value for all these total orders cuz it only sees one after the group by so let’s fix this up so this actually works and see how we’re going to be doing this in this case i would want to run the ct first so i’m going to get rid of this aggregation of this average and we’ll give this the alias of order value also i’m going to be removing this group by because we’re not doing the aggregation anymore we’ll then put this all into a cte so there’s no aggregation inside of this one we’ll then just query this table getting the customer key and total orders to make sure that it’s aggregating properly i’m going to go ahead and press ctrl enter and with this one we can see that 180 has in fact three and now we can go through and actually do our aggregation with that cte specifically we would get the average order value and give the alias of net revenue and then perform a group by on customer key and total orders going ahead and run this bad boy we can see we have 180 with three orders and the correct value there so it’s working so for the remainder of the course you’re going to see me anytime i need to do a new group eye or a new window functions i’m going to just create a new ct and then do it there all right getting into that second exercise we’re going to be focusing on the average function and using this in our window functions overall the syntax is the same so nothing changes there but we’re going to introduce a new business concept specifically this one of customer lifetime value and as the name implies it’s the total revenue generated by a customer over their lifetime with that company we’re also going to explore some other concepts such as the average order value or the typical amount spent per transaction but that’s less of a focus for this more of ltv so for this the main concept of concern is lifetime value which we have the abbreviation of ltv and it is the total revenue generated by a customer for a business over their entire relationship with that company so what are we going to be ultimately calculating for this well we want to find out based on a customer so in this case the x-axis is that customer id we can see what their total lifetime value is and even compare it as with this dash line to the average lifetime value for that particular cohort that calculation is a little bit more tricky to get to but we’re going to get to it so the final table we’re aiming to get to is this based on a particular customer key we want to be able to extract out not only the cohort year but also the customer lifetime value and what is the average lifetime value of that cohort so we can compare that two now this type of analysis is really great because we could do something like target these high value ltv customers because they’re more likely to make purchases and that’s typically what businesses do they’re not going after the lower numbers they’re going after the higher numbers enough happen let’s actually get into it and for this first query we’re just going to focus on three things the first is getting that customer key the next is we want that cohort year which as we’ve seen before is extracting out using the year now there is an aggregation function in this of the minimum order date so we are going to need to do a group by after this but anyway next thing we want to get into is actual a sum of their total purchases so i’ll run a sum function put in the quantity times net price times exchange rate and then give this the alias of customer ltv specifically we’re summing up all of the revenue for that customer so it is that we’re going to take this all from the sales table and like i said we need to do a group by specifically by the customer key let’s go ahead and run this all right not too bad we have basically the first three columns of well the four that we need for this and speaking of that fourth column that’s what we want to get of the average customer lifetime value for a particular cohort but remember we learned previously can’t be inserting window functions in a group by so i need to put this all into a cte and then do the window function we’ll start with that width keyword giving the alias of yearly cohort then signing it this alias obviously putting it all within parenthesis like usual i want to double check my work so i’m going just do a select star from that yearly cohort and everything’s outputting like we saw previously good to go so far inside of our main query we want to one we want to have all the different columns so i’m going to do a select star it’s only three feel fine doing this but next is where we actually want to do that window function using average and for this we’re going to use that value of customer ltv over in parenthesis going to do a partition by and we want to do this by cohort year we’ll assign this the alias of average cohort ltv okay let’s go ahead and run this not too bad one thing is i probably want this ordered in a particular order specifically on the customer key and the cohort year so i’m going to stick an order by in there and specify cohort year and customer year and bam this is the final table that we need for this and this can tell us some different statistics that we can now use like i said we could send this off to maybe something like the sales department or marketing department and they could do targeted ads at these high-value customers in order to have a potential or more of an impact on revenue now i also graph the average lifetime value for each of the cohorts and as expected it does decrease over time that’s expected because they have less time in the cycle than say somebody that 2016 or 2017 guess the one thing to note is 2015 and 16 or less than 17 so the first few years we started off we didn’t do as well with customer retention and extracting value out of it so pretty neat insight out of this all right last part in this lesson and we’re going to focus on two examples very quick in how to use where within a query to filter properly and this is really important especially for the practice problems we have for this in order to understand that you’re filtering properly so let’s start easy first how can we filter before a window function well we could use this where statement here and it is going to apply before we actually invoke the window function itself let’s actually test this with a simple example so for this i’m querying to get the customer key and we’ve seen this windows function before of extracting the minimum year to get that cohort year based on that customer year i’m going to go ahead and run this and there’s trusty number 180 we see that it is in cohort year 2018 so we know the problem or the query worked out properly so let’s say we have a scenario where we only want to look at cohorts from 2020 onward basically we don’t want to put people in cohorts before 2020 we want to just analyze from 2020 onward this is a great example of filtering before a windows function in this case we can use the wearer and we’re going to specify that the order date is greater than or equal to january 1st 2020 now let’s see what happens with customer key 180 okay previously it was bucketed into as its first order in 2018 but now since we’re saying “hey don’t pay attention to that anymore i just want to focus from this point onward it getting reclassified as 2023.” so that’s how you filter before window functions the wear clause can be right there in the statement underneath the select and it’s going to get applied before the window function runs now contrast that with filtering after a window function in this case we need to do something like a ct or subquery we’re going to do a cte here we would need to get that cte and then from there filter so let’s continue on with this last example to show when we might want to use this so the first thing i’m going to do is i’m going to remove this where because we’re not going to do that anything with it we’re going to put this portion into a cte we’ll give it the alias of cohort and then i’ll do a opening and closing parenthesis to put it all within then we’ll do a select star and we’ll do this from cohort so now let’s insert our wearer and in this case right we want to filter after the windows functions specifically we want to remember previously customer 180 was in that 2018 time as its cohort year let’s say we just didn’t even want to look at any of the cohorts if they were broken into that cohort we don’t want to even classify them at all after 2020 so for this we want to specify where it’s greater than or equal to and the year in this case would be 2020 now what i would expect from this is that customer key once again is going to disappear also this from is messed up right here it’s not it’s from cohort okay let’s go ahead and run this and bam we notice now that 180 is removed from this because of how we actually applied this after the window function to remove those cohort years from the original purchases anyway wrapping your mind around how wear function are applied before or after window functions does require some practice so we got some practice problems for you go through and test out and get more familiar with it all right in the next lesson we’re going to be jumping into functions around ranking and that one is pretty exciting so we’ll see you in there all right we’re continuing on in this chapter of window functions now focusing on how we can rank different values and use a certain order to rank them for this we’re going to be covering three main types of ranking functions row number rank and also dense rank i’ll be explaining the difference between all these and we’ll be doing this by ranking customers based on how many orders they’ve completed so more as they completed higher the rank they are but before we even get into any of those functions we need to first understand how to use order by within a window function in order to get the correct ranking that we want now previously with sql you’ve seen order by used typically after the from statement to actually order your values but we can use it inside of the window function and what this can do is order our values within a specific partition that we’re running this window function on and order by as a reminder always defaults to ascending but you can specify descending so what are we going to do in well with the sales table you’ve already seen the customer key order dates net revenue what we can do is get a running order count and what this will do is based on an order so in this case for 180 it has it first order in june or sorry july so we have our first order and then in august on the same date we have two more orders so then it bumps up to three similarly for customer 387 they have four orders on their first day and then the next day or the next time they complete an order they bump it up to five so let’s build something similar i’m going to throw in a select statement along with customer key order date and then net revenue we’ve seen this all before this is going to be from our sales table i’m going to go ahead and run this just to see what it’s outputting okay sweet not bad let’s now just get with this a count of the orders based on using a window function based on that customer key so i’m going to insert a count function and we’ll just do it on count star we’re going to do this over and then i’m going to do a set of open parenthesis i’m actually going to indent this down to make this easier to read and for this we’re going to partition by customer key we’ll do by order by in a second i want to go ahead and actually see this first now we’ve seen this before but i want to call out some things specifically notice that the customer keys are different from before so it actually went through and ordered it with that partition by except it didn’t order it by or didn’t order the order date because this one for 180 in june or july is after the august anyway that’s something to note for later but we do find we get the correct calculations for this because 180 has three orders and we can see all of them here so now let’s insert in our order by i’ll put it right after the partition by and specifically we’re going to be doing it by that order date and this can control our row processing order let’s go ahead and run this bad boy and so inspecting this table we can see now that not only the customer keys in order the order dates in order and whenever we go through the count itself for 180 it has one and then the next time in august there’s two more so now it increases by three so our function’s working so for these aggregate functions like count average or whatnot it’s going to determine how values are accumulated row by row also i realize i never gave this an alias so i’m going call it running order count anyway let’s now use one more aggregate function to demonstrate this further specifically i want to do a running average of the net revenue so basically i after the first order i expect to be around 525 and then after these next two orders i’d expect it to be an average of all three of these and it’s going to do this line by line for this i’m going to insert a new line i’m actually going to just go ahead and copy a lot of this because the boiler plate code itself is going to be approximately the same instead of doing a count we want to do an average and specifically we want to do it on that net revenue so i’m going to copy that and then paste it into here we’re still going to be partitioning by the customer key and ordering it by the order date in order to carry carry out that rowbyrow execution and we’re going to name this running average revenue okay let’s go ahead and run this and now inspecting it we can see that yeah for the first one they only have one order next one of 180 the first order the average is in fact the same as it is but then when we move into the next round of orders it’s averaged among all three of these so for 180 at this point in their order history the average order revenue is around $836 with that knowledge let’s actually get into our ranking function specifically first we’re going to be focusing on row number and understand the importance of how it needs to interact with order by now in postgress they have quite a few different ranking window functions but in this lesson we’re going to be focusing on these top three right here row number rank and dense rank for row number this returns the number of the current row within its partition counting from one so for this let’s just label the rows in our sales table with a row number for this we’re going to select all the rows of the database and we’re going to say this is from the sales table since we’re doing all the rows i’m going to just limit this to the top 10 run control enter okay this is our values back let’s now get into using this to assign a row number at the front of here one quick note for this data frame that’s appearing here is this is the index right here but it’s not necessarily callable the 0 1 2 3 4 5 so we really can’t use that that’s why we actually have to generate this anyway after the star we’re going to start a new line cuz i want all the actual columns to or yeah all the different columns to appear for this we’re going to specify the row number and then run over and i’m just going to do an open and close parenthesis we’re not going to use uh a group by just yet i’m going to go ahead and run this and if we scroll all the way over we now have the row number right here 1 2 3 4 5 6 7 8 9 10 as expected and it looks like our data set is in order now i don’t really like where this row number is appearing i actually want it at the front of the data set and i’m also going to give it an alias of row num anyway let’s move it to the front so important thing to note is yes this does provide the row numbering but this actually does this in a well chaotic order and it’s not guaranteed that it is going to be assigned based on how the data set is in the system so i don’t recommend doing this i always recommend anytime you’re using any of these numbering functions to use an order by so what is this order going to be based on well every order has a unique order key and also line number additionally with this i’m going to also use that order date to make sure that we’re maintaining in that date order i’m not 100% sure if the order key may mix around in certain locations in time so for this i’m going to press enter and now i can enter in my order by and i’m just indenting this in to make it easier to read we’re doing an order by we’ll specify that order date first and we’ll just run it as is just to show this it’s still providing those row number in sequential order by order date but like i said we want to be very specific to make sure that it’s doing it correctly so what i’m going to do is also add in that order key and then that line number control enter and bam so this has what we need in regards to row number let’s now take this a step further combining it with partition by specifically let’s say that we want to start or have a number for like our daily order number and so every new day we want to start this over let’s look first what would it what is it at on the 2nd of january 2015 and we do this by inserting a where statement and this is saying hey filter this for where order date is greater than this this is only done just to look at that uh on the next day running controll enter and silly me already forgot what we learned in that filter lesson right whenever we’re doing the wear right here underneath the uh window function it actually will apply this filter data to there and so in this case it automatically did start uh numbering rig again at one but generally if i didn’t have that wear statement wouldn’t do it anyway not necessary for you to actually follow along and do this code i’m just doing this for demonstration purposes i put all of our original query inside of a cte called row numbering then i called it to look at the first 10 values in it anyway with this same queries below now i want to filter for the second basically where order date is greater than the first running this one we can see that that row numbering starts you know at 26 27 or whatever we want to do a new window function in order to assign a new numbering each day so let’s go back to that original query that we have remove that ct so we can make it easier actually to run through all this for this we now want to add a partition by right above the order by and for this we want that new numbering to start every single day so we’re going to give that the order date as the variable for this okay going to go ahead and run this and actually we’re not going to see any difference in what’s displayed here but we do see down here that in 420 that it only the numbers only go up to like 97 so it does look like it’s working what i’m going to do is i’m going to now just go ahead and copy this all paste that into that cte so we can demonstrate this again and then run this remember previously it was starting the numbering around number 24 or something but now on the second it is starting it at the first so this is working so let’s now get into comparing the three major types of function we uh using for this row number rank and dense rank note all of them provide big or an integer value from this they all have a different way of ranking depending on what your use case is so let’s look at a simple example for this so let’s say we went through and calculated how many o orders each customer did and this one up here they’ve had a total of 31 orders well we’re going to go through and rank them using row number and then rank and dense rank and then seeing how they actually differentiate from each other for this let’s first just pull in the information we need using a simple select statement we’re going to use customer key and then to count all the orders we’re just going to do a count star to basically count the line as an order and we’ll assign this as total orders we’ll get this from the sales table and we did an aggregation method so we’ll do need to do a group eye of the customer key so let’s go ahead and check this bad boy out and with this we can see the different customers and then the orders the or the total orders are all over the place they’re actually get where we need to order this but we’re going to be ordering it in our window function so i don’t want to necessarily do that until after our window function also this is just too many values i’m just going to do a limit 10 for the time being all right let’s get into now building our window function first with row number to assign a row number based on what are the total number of orders they have so for this i’ll start a new line we’ll insert our row number function we’ll do it over and then inside of here we don’t need to do a partition by because well we’ve already grouped by our customer key to find out what the totals are so all we need to do now is just put an order by in here specifically we want to order it by that count star and we’ll give this the alias of total orders row num real original i know all right let’s go ahead and run this all right bam what we have here is well not really what we want uh so these all have total orders of one and it is uh providing a total orders row number one two all the way to 10 but i actually want to be ranked from highest to lowest so as remember from the beginning we can actually insert in a descending comment right in that order by now when we run it we can see that we get this total orders row number and we’re starting at the highest of 31 all the way down notice with this when we get to numbers like 26 26 and 26 repeating it does assign a number of four five and six but technically these are all tied ranks and so that’s why we need to learn other functions like rank so i’m going to go ahead and we’re going to insert another line in here i’m going to copy this row number because a lot of this is just boilerplate that we can repeat instead of row number i’m going to change this to rank and then for this alias instead of row number num at the end and i’m going to add the i’m going to change this to rank running this now okay we got the total orders rank and if you notice from this one whenever we get here and we have repeating values of 26 this is going to assign at four four so if we actually see then when we get to 25 it assigns it the number seven so then we’ll skip five and six and now you’re probably like well loop what happens if i don’t want to skip five and six in my ranking method and i just want to continue on ordering from there well that’s where dense rank comes in so let’s once again going to go ahead and start a new line paste in our old code change this one to dense rank and then also update the alias to dense rank running this one i put a comma at the end of this don’t need to have it going to run again we now have this new one where okay we get here we have the repeating fours and then when we get to the next one it jumps or it stays uh consistent in number and jumps to five and then we have some uh similar numbers again of 24 and so these are all sixes so when i need to order something or number something it really depends on what is my criteria on whether i’m going to use something like row number rank or dense rank that’s why got some practice problems now for you to go through get more familiar with these functions in the next lesson we’re going to be getting into lag and lead which we’ve been doing functions that really look at only the current row it’s on but we can actually use functions that look either before or after certain rows pretty powerful all right with that i’ll see you in there all right welcome to this fourth of five lessons on window functions and in this one we’re going to be getting into functions like lag and lead these type of things in a window function allow us instead of looking at the current row to allow us to look at things like the row above it or the row below it so we’re going to be exploring these main functions and we’re going to be doing this first with a very simple example where we can go in and look at our 2023 monthly revenue and be able to evaluate our month overmonth growth because now we can look either before or after row and be able to calculate this from there we’re going to shift into our final scenario which is slightly more complex in order to analyze the growth of cohorts over the years and basically see how they change from year to year so what functions are we going to be exploring for this well there’s generally about five different ones that you can use let’s start with the easy ones first we have first value last value and nth value for first value it returns a value evaluated at the row that is the first window or first row of that window frame the last one does obviously the last one and then for nth value you can specify an an integer inside of there and it will return that row now for lag and lead they’re very similar in that this one you’re providing either a row that is lagging or a row that is leading but we’re already to get too deep into it we need to actually explore this with an example so what i want to do is first we need to calculate this we need to get in 2023 what is the monthly net revenue and then we’re going to be applying these functions in a window function in order to evaluate first last lag lead and try all these different ones out so let’s start simple with just building this query so i’ll start with the select statement and the first column we want is the monthly v variables so i’m going to use the two care function for this i really like the output of this it’s a lot easier we’re going to run this on the order date and i want it in this format we’ll give it the alias month next is we want the net revenue so we need to use the sum function for this as always it’s quantity time net price times exchange rate we’ll give it the alias net revenue we’re getting this all from the sales table and we’re doing an aggregation so we need to do a group by specifically we want to do the group by by month let’s go ahead and run this bad boy okay first thing i’m noticing is it’s returning it back but it’s ordered all over the place so i’m going insert an order by we’ll also do this by month and we want to analyze this for just 2023 so i’m going to insert in a wearer and we’ll just do an extract to extract out the year and analyze for 2023 so with extract we’ll specify the part from and then order date and we want this equal to 2023 it’s a digit so we don’t have to put that in a string and bam we have what we need now now we can actually start getting into running all these lag lead and stuff functions now because we’re going to be running window functions on this i’m going to put this all into a cte we’ll use the width statement we’ll give it the alias of monthly revenue and then i’ll provide some open and closing parenthesis and then i’ll do a select star from this cte and make sure it’s still outputs yep still good to go so let’s get into exploring these we’re going to start with the easy ones first like i said of first value last value and nth value so for this i’m going to specify first value and we need to put something in here specifically we need to put the the value expression that we want out of this in our case it is net revenue which is right here inside of our cte the next is an over and then inside of here we don’t need to do a partition by because it’s everything’s already grouped but we do need to do an order by specifically where do you what do you want us to choose the first value from in our case we want the first value based on the months not on the value of net revenue so i’m going to put month in here and we’ll give it the name or alias first month revenue going ahead and running this we can see that we do in fact get that first month into all these different columns let’s now look at last value let’s change the function name and then also the alias running this one now this one unfortunately whenever you read it you find out oh heck this is not the last month’s revenue for each of these and that’s because the actual syntax inside of here of the last value of how we need to order by needs to change specifically i’m going to delete it and put this in here and we need special conditions of to use rows between unbound proceeding and unbound following when we look at it we can see that it is actually the last month net revenue anyway just wanted to demonstrate demonstrate that because it takes a little bit more to fine-tune this one we haven’t covered un unbound proceeding or unbound following we’re going to be covering that in the next lesson so stay tuned for that one all right next up is nth value i’m going to go ahead and copy this first value and then insert it down here underneath and then change the formula name of nth value also for this we need to specify the integer expression for what number of rows after this to do so right now we’ll just do three rows down and we’ll call this third month revenue okay running this bad boy we can see that we get the third month’s revenue now we do have this nonvalue in here once again if you want to fix this which we’re going to cover in the next lesson we can insert this statement right here right after this running this we now have the third month filled in for all this don’t worry those all make sense tomorrow when we cover all those but at least you got the basics now let’s wrap up the simple example with lag and lead so for lag we’re going to be looking it’s going to be a lag so it will be the previous month we’re going to look for this returns values evaluated at the row that is offset rows before the current row within the partition if we want to it’s optional because it’s here in square brackets but we could put an offset integer similar what we did for the nth value and we’re to offset that we’re not going to do an integer for these examples we just want the previous and then use previous to find the next months so going back to our query i removed some of the other ones because i don’t they’re it’s getting too much in there we’re going to specify this as lag with the parameter of net revenue we’re going to still order by month and this will be the previous month revenue let’s go ahead and run this and inside of here we can see yep this is in fact the previous month’s revenue this does take a parameter like i said you can do that offset so if i wanted to do two in this case run control enter it’s now offset by two values before it goes down we’re not using that for our case we’re just going to go we’re doing trying to calculate eventually month over month so we’re going to leave it at one and run this okay let’s now use lead i’ll specify the formula first and instead of previous month it is going to be next month go ahead and run this and we can see that it is actually the next month’s revenue for all of these so you’re probably like luke what the heck does this even matter yeah you can find this out but how does this even help me as an analyst well let’s say that i wanted to find my month overmonth growth which is pretty common in the finance industry for evaluating your performance so here i have a chart that’s showing basically our bar chart of the different revenue each month and then the line chart is showing what’s happening what’s the rate of revenue growth month over month here we can see that in may we had a substantial increase in growth and that’s because we had a pretty low one in april anyway it’s pretty big predictor in the business world so let’s get into calculating this so in order to do this we care about the previous month’s revenue in order to calculate this so we don’t really need this lead function right here i’m going to go ahead and remove it so what we need to do first we’ll just take net revenue and subtract it by this value right here to get basically our change every single time and we’ll give it the alias monthly revenue growth okay now we can see from this that it is calculating that growth an easy line to see is row two we went from the previous month at 4 million to that month of 2 million so we lost 2 million yeah calculations are doing well okay we want a a rate of change because of this we need to actually divide this value of net revenue minus the previous month revenue and we need to divide that by our original value which is our previous month revenue so i’m going to go ahead and copy that again paste that down here let’s go ahead and run this and bam there we have it we are now calculating that rate of change and we can basically see that um for this for in march we had about a 50% reduction in revenue whereas in something like may we had almost 150% rate of growth just to be clear this is decimals so this is a the percent if i wanted to i could just do 100 times this value and then we can see this percentage a little bit easier with this so let’s get into example to show the benefit of these type of functions that can be used and previously in the second lessons of this chapter on aggregation we went in and covered what was the average lifetime value based on your cohort if you recall back your cohort you’re assigned a cohort or customers assigned a cohort based on the year of their first purchase and we notice this trend that following around 2016 we see the lifetime value drop during these and that makes sense because their actual total lifetime is slightly shorter but we did have this unexpected rise in from 2015 to 2016 anyway what happens if we want to go through and actually analyze what are these different drops between each one of these ltvs well we can use our lag function for this now in order to do this we need or the table we need to start is this we need the cohort year verse their average cohort lifetime value now we basically calculated this back in lesson two of this chapter on aggregation here i have the formula here and actually what we got to inside of the lesson was this final table which consisted of one ct and then another formula underneath it anyway i took it a step further inside the notes so for those that have access to the notes you can go right to it and all you need to do is copy this the other option just pause your screen and copy this in also this next example we’re getting into isn’t that long so you can just watch along if you don’t even want to do any of these so we need to run window functions on this after i’ve gone through and inspected this it’s a ct inside of another ct but then we have to do the select distinct because we have multiple different rows so i’m actually going to put this one also into a ct i’ll give it the name of cohort final i need to go ahead and put a closing parenthesis on this and then do a select star from cohort final make sure everything’s appearing just fine underneath here and it is okay now we can work from here to insert in and we want to create our first column to look at what is the previous year’s lifetime value so for this we’re going to be using lag i’ll do a select star to basically show both those rows and then do a lag and the value we want to put in here is what value we want actually to appear and that is the average cohort lifetime value we’ll do over and then inside parenthesis we’re going to do an order by and we’re going to order by that cohort year and we’ll give it that alias of previous cohort lifetime value and okay we’re seeing that it is the in fact the previous cohort lifetime value all right all right final thing i want to do here is calculate that percent change so that year overyear change or better that the year of the cohort over year of cohort change for this remember our ratio is a final minus original over original so i’m going to take that final value of average cohort lifetime value and then subtract our windows function so command c this command v and then from there i want to divide this by the original so once again paste in that previous cohort ltv and we’ll give it the alias of lifetime value change okay we’re going to go ahead and render this okay it’s not the correct value i expect this to be more of a a decimal number i think this has to do with basically my order of operations here i think i have that parenthesis in the wrong place i want to do the subtraction first and then after that the division okay this is giving it to us i want to actually see these as a percentage so i’m going to put a 100 at the front multiply this and bam now we can see our lifetime value change yeartoyear as expected we had a slight increase in 2016 and then from there it went down now if you actually go through and visualize this looking at this is the average cohort lifetime value uh in the bars and then the actual rate of change we can see that the rate of change actually is picking up so although i would expect it to go down i wouldn’t expect it to go down at this high of a rate so maybe something we need to dig into in a real life scenario if this was happening all right you got some practice problems now go through to get more familiar with handling these type of functions and window functions in the next and final lesson of this chapter we’re going to be going into further detail and syntax understand to be able to use like we demonstrated that last value function how it wasn’t working properly without further syntax specified to it we’re going to be going over that in there all right with that i’ll see you in the next one welcome to this fifth and final lesson on window functions where we’re going to be focusing on frame clauses now up to this point with window functions we’ve only really focused on two things of the window definition that’s the portion after the over and that is looking at how we can use partition by and order by but there’s actually one more thing to cover with this and that’s the frame clause this aspect helps control what amount of data we want to actually control putting inside of the windows function what do i mean by all this well as we’re going to be solving in this say we have something like the monthly net revenue this is from 2023 as you can see it’s highly volatile going up in february and then going back down and then going back up well this is where frame clauses come to the rescue what we can do is look before and after certain rows and in this case average them and so we could in in this case perform a threemonth running average to basically smooth out our line this is very common in business analytics especially with seasonal data that has these types of ups and downs you want to remove all the noise and actually be able to look at it more clearly so postcrest has some documentation that goes all into this but it gets quite complex so i simplified it in our notes so this lesson is going to be focusing on using the frame clause of rows basically looking at what rows we want to put inside of this window function now as hinted to this comes right after our order buy and we can either include something like the start frame or we can use that between keyword to signify a start frame and then also an end frame but what the heck are the start frame what’s this end frame well there’s five main things we could put inside of here and is the majority of this lesson of what we’re going to be getting into for we’re going to be able to see how we can use current rows preceding rows and also following rows don’t worry we’re going to break each one of these downs so you’ll be more than familiar with it by the end of this now with postgress you can also specify besides using row you can also use things like range or groups this i would classify into more of advanced sql so we’re not going to be really covering it in this course additionally i had chat gbt make this fancy dancy table down here and i want to just show with this range and groups also isn’t supported in a lot of other popular databases specifically mysql and sql server so i don’t really want to waste your time if you don’t have those type of keywords available to use that’s why we’re going to focus on rows anyway you need to learn anyway to be able to apply range and groups if you want to learn that later on now for this entire lesson we’re going to be analyzing our monthly net revenue similar to what we did in the last lesson because as you remember we had some unanswered questions on how to use some of those functions without what we’re going to learn in here we’ll get to that by the end anyway you should remember this query or have it in your system already right this goes through and gets not only the month but also the net revenue for that month pulls it from the sales table and it only extracts 2023 i just want to look at one year so there’s not a lot of data we’re messed with since we’re doing an aggregation function we need a group by and then finally need or buy because it gets all out of whack and you should see something like this looking at our monthly net revenue if we graph it looks something like this that we saw at the beginning goes up in february and then also has a strong dip down in april then returns back to normal we’re going to be working towards getting a running average with this but we first need to understand current row which the keyword of this one before we move for any further so i want to run a window function on this query so i’m going to put it into a cte we’ll give it the alias monthly sales and i’ll put it into parenthesis we’ll select both the month and also the net revenue and pull this all from monthly sales let’s go ahead and run this and it’s exactly the same thing that we saw before now we can actually run or use a window function here instead of on here like we said before can’t be using window functions with the group by we can it’s really complicated we’re not going to do it anyway we’re going to do the window function below specifically all i want to do is get the average net revenue for this month so basically repeat that same value so we’ll start by calling average on net revenue we’ll go over i’ll start a new line and indent down and then before we actually anything else let’s just look what it generates it’s going to generate the average across all 12 months so we want to do this or we want to order it by the month itself so i’ll do an order by and then specify month now running this query we’re still getting the average but it’s slightly different now for january it’s still the same and that it’s the january average but if we look at something like february it’s not only it’s getting the average based on january and february for march it’s getting it based on january february march anyway we want to control this average so let’s move forward we’re going to start by renaming this column so i’ll give it the alias of net revenue current because we’re about to use current row now this has the following syntax of rows and then the start frame we’ll eventually get to this one of rows between but we’re just going to start simple with this one first and then remember our start frame or end frame can be any one of the following we’re just starting first with just current rows where we then move into calculating the average or should i say the running average all right so i’m going to insert in rows and then from there current row now this is selecting to run this window function on this current row so there should be no difference between any of these promise you we’ll see more of an impact in a little bit but i do want to demonstrate how you can also write this rows between and we need to do our start frame so current row and our ending and we’ll do once again current row as you would expect it’s only looking at the current one so it’s going to be the same across all of these let’s get into our next keyword of looking at how we can use something like n proceedings looking at preceding rows or preceding values this is going to be the final table that we get in it we still have our monthly and our net revenue and what we’re going to look at in this case is just one row back and the current row in order to get the average right here at the first one we expect it to be the same as this one but whenever we get to the second row right here it’s going to look at this current one and also the preceding one and get an average so the average of uh 3.6 million and 4.4 million is around 4 million and so for this we’re going to use inside of our start frame we’re going to use n proceeding specifying n as a number so getting back to our query right now we have in there to do rows between current row and current row we want to go one row back and also look at our current row so i’m going to remove this portion and we’ll specify one proceeding oh not receding but actually preceding okay let’s go ahead and run this and as we saw that in that demo table we’re now taking the average of the current row and the previous row we get 4 million in this case so we can take any number of values also we could just make sure that this is actually working properly by putting a zero instead in here instead of one which means the current row and we’re getting all the same values as before but we’re going to change by back to one now i’m going to take a step further just for demonstration purposes you don’t have to do this portion but i went through and we did before we did one proceeding i wanted to see what it was going to look like for also doing two proceeding and three proceeding and i got this fancy dancy table and from there plugged it into chatbt to actually visualize it and what we can see from this is that with each preceding row that we include so we include more to take an average of it this line becomes smoother and smoother it goes from it starts with a darker line with just core net revenue and it gets lighter and lighter depending on the preceding amounts that we used i know there’s a lot of overlap here so i also took it like this and i graphed each one of them individually showing how over time it gets smoother smoother and smoother so now you’re probably like luke is this what you do in a real world scenario i’d say well not typically just the proceeding but i combine this with something like following and so we’d use values before and after the current month and get something like a three-month average which let’s do it now so just as a reminder it’s going to be of the syntax and following where you can specify the number and it gets that many number of rows after the current row so back to our original query that we’re working with instead of doing one preceding and the current row what i’m going to do is now change this to one proceeding and one following running this query we can see that all our values now especially even that first month is smoothed out because it’s not only taking the current month but the following month whereas something like june is taking not only may’s month but also july’s month and then averaging it together to get this value this i feel is more representic of what i’d see in the business world i went ahead and visualized it and this shows how this actually smooths out our net revenue line by performing this three-month average now you could take it up a notch and do something like a fivemon or even seven months uh running average but at that point i think you’re going to be removing a lot of key insights from this so i’m going to stop right here at that all right last two start frame and end frames to end with and this is unbounded preceeding and unbounded following if you notice carefully all they’re really doing is replacing the n with unbounded and this says hey we want to use all rows from the start or maybe all rows from the end so let’s actually just do just that in here we’re going to place one on these with both of unbounded and what do you think’s going to happen here well if we use unbounded on both it’s taken the entire window function or window frame into the account for printing this average so we’re basically getting the average of all these 12 months now typically when i’m seeing anything like unbounded used i’m usually seeing it with something like current row running this we can see that the first row is equal to basically itself and then as it goes along it’s taking into account all the values behind it along with the current row and it seems like the line is just getting smoother and smoother and smoother as it goes along so where am i typically seeing these unbounded parameters being used well if you remember from that last lesson when we were looking at same uh chart of the monthly revenue we were able to use like lag lead functions specifically first value last value and nth value let’s go ahead and run this we saw that for first value it actually did give us the first value but then the last value it didn’t work out properly it just gave us what the current row and then for the third most or whenever we did nth value and specified three it gave non values for the first two but then finally gave us the third value for everything else well this is where unbounded comes in so let’s fix these functions be able to do this and then i’m going to indent this down to make a new line to make this a little bit more readable and then from there i’m going to insert in our frames clause specifying that rows between and then rows between unbounded proceeding and unbounded and f unbounded following running this one now whenever we look at that last month revenue we can actually see that it actually does equal the last month basically we had to open up what it was going to look at for that window function by using this frame clause similarly we can do the same with that nth value i’m going to go ahead and just copy and then paste that right into here now running this and we can see that now that third month’s rent is appearing in every single line regardless if it’s before or after so bam we’ve now covered all of the major aspects of using window functions you now have some practice problems to go through and get more familiar with using these different frame clauses inside of window functions and then in the next chapter we’re actually be getting into and how you can install this database locally and run it locally so you can have a workflow that’s actually workable with that i’ll see you in the next one all right welcome to the second half of this course don’t know why i had to jump in like that wanted to have a dramatic entrance for some reason anyway in this chapter i’m going to be taking you through all the steps necessary in order to install postgress locally onto your computer get you set up with its editor of pg admin and then also get you set up with an even better editor of dbaver so let’s break this down in this lesson we’re going to be installing postgress or the database itself locally onto your computer we’re going to be downloading it from the internet and then it’s going to install postgress but also pg admin now pg admin pg short for postgress uh is the editor used in order to interact with postgress databases so anytime you need to start or stop the database or even if you want to run a query with it we can do that with pg admin which we’re going to demonstrate all during this lesson now if you already have postgress and pg admin installed you don’t need to do it again but in this lesson after we do the install we’re going to go directly into actually loading the database specifically our contazo database that we’ve been using in those jupyter notebooks once we get the database set up we’re going to do a quick walkthrough of the entire pg admin ui so become more familiar with it now there’s one major flaw with pg admin and that it only connects to postgress databases and after this course you may be proceeding on to learn other databases because of that we’re going to be installing in the second lesson dber now this is a database management tool so can only connect to different databases you can also run queries on it to see the output we’re going to be using the community edition of this and it’s free and open source and has everything we need to do to get started this is the most popular database tool that i know of so i’m super excited to use this and everything that you learn for using dbver can also be applied with other databases which dbaver can connect to one last note before we begin some of you may run into installation errors or other errors along the way i highly encourage you to use something like chatbt to help you out it’s a lot quicker than trying to post a comment and helping or hoping somebody else comes in to help you out now let’s say you can’t figure it out or you’re on something like a chromebook and can’t install postgress in that case you can continue to run all of the different queries in our sql notebooks they’re going to work exactly the same and have the same output but as far as interacting with the guey and stuff like that you’re going to have to figure that all out yourself because obviously it’s going to be different than deep so first we’re going to navigate to the download page from postgress and from there you’re going to select your operating system that you’re currently on i’m on a mac so select that we’re going to be using the interactive installer by edb so we’re going to select right here of download the installer which everybody regardless operating system it’s going to get navigated to this page where you can then select your operating system once again and download it for mac or windows you’re going to want to launch this installer if it gets a warning message it’s okay click open it we’re now going to walk through the actual setup wizard that it has included for all this we’re going to leave all the defaults the same core things that we do want to make sure are installed which are by default our postgress server and also pg admin which is the guey interface next is the password and i’m actually going to set this one to a really easy one of password now my database i’m not going to have any confidential material on it and this database that we’re installing isn’t secret at all so i don’t care if somebody else accesses it but it doesn’t really matter because it’s local anyway so other people can’t necessarily get to it unless i have it access to the internet anyway that’s a long story key thing if you’re only going to be doing this course with this feel free to just set it to password you should be okay but if you’re not set it to something else and remember it keep the port number the same of 5432 it’s common to postgress databases and we’ll keep the default local and we’ll go ahead with this setup’s complete i don’t need to launch this stack builder exit i’m going go ahead and click finish and i’m going to verify this is now installed by going to my applications folder under postgress 17 i have these different options of what’s installed we’re going to be opening up pg admin this is the guey interface for interacting with our postgress database it’ll start loading up with this open we have two main panes in here we have our lefth hand side pane which is our object explorer which shows all the different databases we’re connected to right now it’s asking me to connect to the server specifically postgress 17 which is the one we installed so i’m going to go ahead and put that password in of password and i’m going to click this of save password so as we can see postgress 17 is a server we have one server and then from there we have databases inside of that server right now we only have this one standard database that comes in all postgress uh servers called postgress we’re not going to touch this bad boy i don’t really care about it but we can see that hey there’s only one database in here we also have options to adjust login or group roles and then also table spaces we’re also not going to be messing with any of this this dashboard over here on the right hand side i find pretty useless it just tells me when i have interactions inside of my server and when it’s getting used so now let’s install the kazo data set locally for this we need the database file for it which is right here of this kazo_100k.sql file it’ll go ahead and start downloading you don’t need to do this but i went ahead and opened this file just to show you the contents and in this it walks through actually creating all the different tables that we need inside of our database along with loading in all of our data into it it’s pretty long file so let’s get this file into a database and for this we need a database for this so we’ll rightclick databases select create and database we’ll name this contazo_100k keep all letters lowerase the owner will be maintained as the super user of postgress so we can use that same password to access it we don’t need to change any of these other settings right here they’re all good enough we’ll go ahead and click save now we can see we have two databases underneath here and it automatically dropped everything down underneath here now if i go under schemas and then it has a public schema i can see underneath tables if i click this to actually drop it down to see any tables there’s no tables inside of it so this is where we need to actually load that sql file into this database first thing you need to know the location of where it is i recommend just put it on your desktop we don’t need it after it’s done so you can just delete it back inside of pg admin i’m going to rightclick that contazo_100k database and i’m going to go here to psql tool this is effectively like using a terminal to interact with our database i’m going to start this command off with a forward slash then i this is going to tell it to execute the script that we’re about to insert into this and so inside of single quotes i’m going to then put the file location and i’m going to insert that in of users luke bruce desktop and then the sql file itself make sure that it’s exactly right on a mac if you go to the file itself click option and then rightclick it you’ll get this option here of copy the sql file as path name on windows all you need to do is shift and rightclick the file icon and select copy as path okay we got it in going to go ahead and press enter it says that pg admin like to access my desktop yes i want to allow this and it’s going through here and actually creating all the different tables and altering them and i can see from this that we’ve put in it looks like six different tables and it tells us all the different counts of the rows that we inserted into those tables so i’m going to come in here and go to tables and try to see it there’s no tables in here but all i need to do is just right click ino select refresh so now it should have it and we can see scrolling down the tables we have six tables inside of here which from this menu i can actually dive into in the case of sales actually dive into the different columns and everything else that has associated with this i can also just do a quick check of this by rightclicking something like the sales column going to count rows and it tells me at the bottom there’s over 199,000 rows in this sales table but how can we actually query this database of contazo 100k well first we need to make sure that it’s actually selected and then come up here and select query tool we can also see that they have a shortcut of option shift q it opens up in a new tab right here i see these other tabs here if i don’t want any of these other tabs i can go ahead and select x and close it out up here at the top it tells me which database i’m connected to if i had any others i could switch it right up here we have our query window which i’m going to put in a simple command to look at the sales table and the top 10 results to run this i’m going to come up here and select this play icon for execute script or i can press f5 and all the results are displayed here below i also have this scratch pad over here on the right hand side so if i don’t have queries that i want to keep track of i can just put it over on the right overall i don’t find myself using it that much other key features of this area are you could open a sql file right inside this window or if i want to save this i could save the file we also have options for explain which we’re going to go into more detail in some upcoming lessons now down here at the bottom we only have the data output but also any messages and notifications inside of that output they actually have a few unique capabilities with this in that you can copy any of your different exports of data out of it if you want to put in gbt or something let’s say we have a more complex query that actually does some analysis such as this one right here that looks at the total yearly net revenue well we can not only save results to file but also we can graph and visualize it right here i select line chart and then we want the year for the x-axis and then the total year net revenue for that y-axis and then select generate and not too bad to actually get into visualizing queries pretty easily in this last thing to note with pg admin is i can also do things like view the erd or the entity relationship diagram for the database by rightclicking it select erd for database and with this this is showing our sales table i can scroll in through this and actually see the sales table along all the different keys and columns in it and with this table how it’s connected to all these other different tables in it so a great way to visualize your database and tables that you’re working with all right we now have some practice problems for you to go through and get more familiar with this pg admin guey like i mentioned at the beginning we will be transitioning next to dbver but i do find myself from time to time having to jump in and use pg admin so it pays off and understanding the basics of this tool that’s why you got those practice problems all right with that i’ll see you in the next one welcome to this lesson on dbaver in this we’re going to be walking through setting up and getting dbver connected to our contaza database first thing we’re do is going to download the community edition of dbver which is free then from there walk through the steps necessary in dbver to connect to our postgress database and then finally once we have that set up we’re going to actually do a walkthrough of the dber ui understanding how we can run different scripts and how we can set up our project inside of it all right with that let’s get into it all right if you navigate over to dbeaver.io this is the homepage of dbaver community this covers a few details about the tools you can read further specifically dbe community the edition we’re downloading can connects to a variety of databases and has all these different editing and viewing options it’s by far talking to all my data analyst friends and also looking at the research it’s the most popular database editor so that’s why we’re using it now dbver needs to make money like any community so they also have a pro edition i’m going to go ahead and click this you don’t need to and so with that they have a few different edition editions that you can get and use some get pretty pricey if you’re a business but as far as the basic sql and coding that i run i don’t ever need the features that are inside the light enterprise or ultimate edition i can get it all done with a community edition but if you come a power user highly encourage you you buy a subscription because you support building out dbver further all right cool story luke let’s actually now get into downloading db and close the download and then from there you select what operating system you’re on and install it i’m going to be going through with mac windows is going to be very similar so i’m not going to cover them separately after your installer file loads you should click it and open it up on mac it’s pretty easy all you have to do is drag the beaver over into your applications folder and now it’s here i’ll go ahead and open it up if it asks if you’re comfortable with opening this app up yeah we know where we got it from i’m going to open it with dbaver opened up and launched um you may notice first that mine may be dark and yours may be white i have dark mode enabled on my mac so i guess it automatically picked it up change it to dark mode anyway it says “hey do you want to create a sample database that can be used as an example to explore basic db or features?” we’re not going to do that we’re going to just install the contazo data set and then i’m going to take you through this so it should have immediately popped open with this of a connect to database and now we’re going to get into installing the database if this select database didn’t pop up that’s okay there’s a few different ways you can get it up and we need to go through it anyway one other thing before that it does have this popup that says “hey do you want to share your data in order to improve performance i’ll leave it up to you on whether you want to do this or not.” so to create a new database connection you can either go up to the file menu and go to databases and select new connections or you can just come right here to this fancy dancy icon and select new database connection now this is one of the reasons why i recommend dbver so much is because it connects to a host of different databases and so that way you can connect all your different ones that you’re working on as a data analyst so in our case our canazo is a postgress database we’ll select that now we need to go through and fill out the connection details we’re going to be connected by host specifically our local host so it’s locally on your computer the database name is not postgress it’s the contazo 100k make sure you spelled exactly the same as what’s appearing in pg admin next we’re going to move into the username which we maintained it as postgress and then the password if you named it like me the password is just password all lowercase i’m going to leave save password enabled because i don’t want have to log it in every single time from here it’s already picking up that we’re using postgress 17 and everything else looks good let’s go ahead and test connection in my case it’s saying that the postgress driver files are not installed we need to install them basically like if you install a printer into your computer or attach a printer to your computer you have to install driver files to attach to it so similar here nothing wrong with this we’re going to go ahead and download with that we get our test results back and it says that we are connected now if you are not if you have issues with that one check all those credentials make sure they’re correct but two what may happen uh to you is that your database may not be started and so you may need to open pg admin and actually open it all the way up to the kataza data set and make sure that it’s actually running on your machine typically for both mac and windows your postgress databases should start when you restart your computer so you shouldn’t have to do this but you may have unintentionally disabled this feature and so you may have to restart anytime you restart your computer with all the credentials put in and the testing of the connection set we’re going to go ahead and select finish so let’s now walk through dbver and get into understand the ui and also running a few different files okay so we have this pane right here on the left hand side and that is our database navigator also it holds our different information on our projects which we’ll get to projects in a minute anyway this has all of our database information in it if we want to see it specifically underneath database navigator if for some reason this disappears like i accidentally close out of it you can go into the windows menu item and from there show the actual view of database navigator pop right back up so what’s inside of here well very much similar to what we saw in pg admin we can see all of our different databases in here we have our contazo 100k database we also have these folders on administer and system info these are ones that i’m using less i’m typically staying inside of here specifically inside this contrao 100k go into schemas under public because it’s the public schema we care about and i can go into actually viewing all our different tables if i drop something down like the sales table i can see if i wanted to go into all the different columns in it along with what is the data type of those columns i can also see a host of other information like foreign keys and whatnot anyway one thing that you may have noticed about this is that there are numbers over here on the left hand side these aren’t the number of rows but instead if you hover over it you can see that it tells you how much disk space that that specific table takes up so you can get a general idea of how big these tables are just on dispace alone so i can see that sales and also the customer table specifically are pretty big relative of course this is actually a pretty small database now what i like about tools like dbaver is how easy it is to dive into these tables without having to write a sql query specifically if i wanted to see what was in the sales table i can rightclick it and then just go to view table now this side is the database editor and it actually has a tab view it’s like i could do something like this open also the currency exchange and it has multiple different tabs that i can cycle through now with this i can view a bunch of different things underneath properties i can look at all the different columns foreign keys constraints whatnot next up is data i can obviously look at the different columns inside of here and scroll through it a lot easier similar to excel spreadsheet and then the other one is the er diagram or the erd and this shows how your tables are connected all together i actually feel compared to pg admin this one is more realistic and shows how they’re all connected whereas i don’t know if you remembered from pg admin but they all like connected into a single line and went all over it was a hot mess so db does a little bit better at this anyway the view that i’m typically looking at most is this data one right here and i can look at as a grid or also as a text text i don’t find very useful at all um except if i need to copy and paste it grid is mostly where i’m staying now this guey in here has a lot of different options that you can use to interact with these tables and view them specifically you could enter a sql expression to filter it down you could also actually put in custom filters in here to filter it down down at the bottom we can do things like add rows remove rows typically i do this with sql i’m not going to mess with it here in dbe can also cycle through the different pages and whatnot one that i do find useful however is this of export data and anytime you have any of your data that you have and you want to get it out of here you can put it into a variety of different sources typically i’m doing something either of exporting it to a csv or export it to sql which will make it into a sql insert statement all right so enough of that let’s actually get into setting up our project folder i don’t need these two tables open up it’s also asking me if i want to save these changes in the data set database i didn’t really change anything or i don’t want to change anything so i’m going to click no so we’re going to be creating a project folder i’m going to click projects right here in order to be able to save our sql files if we want to as we go along right now we just have this general right here which has bookmarks dashboards diagrams we can also see it right below here i don’t really care about the general one i want to now create a project specific to this course that we’re working on so i’m going to come up to the top right here and select create project and i’m going to call this intermediate sql project real original i know with this project i’m going to leave it to the default location which is inside of the dbe folder i could uncheck this and then re change that to wherever i want it to be just so you’re aware i’m going to leave it in the default location i don’t want to add the project to a working set so i’m going to go ahead and select finish so now i have this intermediate sql project and my general my intermate sql is my main project or my active project so i’m actually going to rightclick it and say set active project and then it should shift to bolded additionally if i go back up to windows in the file menu and go over to project explorer i can have that now appearing below if you didn’t close it out it was general probably it should have switched to that anyway i like this type of view because now i can switch between them but if you notice the database navigator we now don’t have our sql database in there anymore so what we can do is go back to projects and it actually makes it pretty easy in here right here under general i have the kazo but what if i tried to click the connections of the intermediate sql project there’s no database that it’s talking about so we loaded the database into general we want it to move it over down here and so bam now when i open this project folder which it’s the de uh the default one in this case now it’s inside of here in the database navigator as well so this is pretty neat of how i can keep this all grouped together in a single project now by default there’s four different folders in here they all should be empty of bookmarks dashboards diagrams and scripts bookmarks are just as they imply bookmarks if you have something that you frequently go to you can just put it there in this case let’s say i frequently go to the sales table i can stick it in bookmarks and now makes it super easy anytime i need to go to that just click on it and bam it appears right here next we have dashboards and nothing in this but you could create a new project dashboard if you remember from pg admin they had a actually a default dashboard that shows all the different sections transactions stuff like that i’m not a database engineer i don’t really care about all that so we’re not using that next are diagrams if i wanted to i could create a new erd i could call it contazo erd now this does have our five core tables in here but also it has a host of other different tables that just come natively inside of a postgress database whenever you install it so they’re all going to be there if you make it this way you can filter down we’re not going to go into that all right the last thing is scripts how the heck do we create a new sql script well you can do this from sql editor in the menu or just come up to the top here and select open sql script now there’s a few different options that popped up here since we’ve done this first it tells us what is the active database and it tells us what is the active database schema so this is especially important when you’re working with multiple databases to make sure that you’re running the queries on the correct database now notice whenever we open this up inside of here we also the script itself we also have a new script underneath here i’m going to go ahead and minimize these we don’t need this anyway we have script inside of here if i wanted to i can rightclick it and go to something like rest rename and then we can name it appropriately like this is just a test script and i’ll make sure that’s a sql file press okay and it’s since been renamed so let’s run our first sql query we’re just going to make a simple statement of we want to select all columns from the sales table and we want to limit this to 10 results if you notice this i was typing in all caps as i was going along and then it made it lowercase after we’re going to fix that in a little bit anyway if i want to run this single query on a mac i’m going to press command enter on windows i’m going to press control enter also if you forget you can just scroll over these icons and click it and it also gives you what the shortcut is now similar to what we saw before with how we can view different tables and outputs i’m going to have a tab here and then underneath this i can actually explore it in different ways with text or grid i can also cycle through it if i want to export the data so a lot of different options to manipulate this and dive into all of it let’s run a slightly more complex query to just demonstrate the the power of this i’m going to make this into a cte and then we’re going to run a query on that cte so i’ll enter this down put in a width keyword we’ll call this sales copy because that’s what it’s going to be give it the alias of as and then open parenthesis now i need to clean this up i like indentations and things like that i can actually highlight this all rightclick it and then go into format and i have this option for format sql on a mac the shortcut is control shift f so i can actually just do that instead of doing control shift f and it makes it slightly more readable although it didn’t end in anyway as always with any ct i’m going to go down here and do select and star and then we’re going to be doing this from the sales copy table above now if you notice this it automatically gave me this error message saying “hey sales copy is not located above.” and actually if i even tried to run this with this by pressing command enter um it tells me sales copy doesn’t exist but i can clearly see that it’s up here that’s because dbaver automatically treats any blank spaces or blank rows as a endline delimiter basically treats it as like a semicolon at the end so what we need to do is subtract that out of there and i’m still getting an error message i don’t know why i am but oh it’s running now and it cleared okay i just had to run it once anyway i don’t like those two things right now i don’t like how it’s automatically making everything lowercase and i don’t like that it automatically gives me this error message when there’s just a space in there so we need to change some settings before i want to proceed on if you’re on a mac you’re just going to select dbeaver up in the menu and select preferences on a windows i think you’re going to select file after you select settings this preferences window will open up and this allows us to go in and actually control things inside of the editor itself i want to control things in the sql editor specifically for the formatting right now the keyword case is set to default which is lowercase i want it to be upper so i’m going to change it to that you can also control your indent size down to like two i like bigger indents so i’m going to do four also if you notice previously it wasn’t indenting in those things that are in parenthesis i like that so whenever i click this it does indent it in so i’m going to have that selected as well last thing to uh update is under sql processing and moving this over in this we have blank line is statement delimiter always we remember sometimes we may have blank lines in there i don’t really like this setting so i’m going to change this to never you can also change it smart but i’m not guarantee it okay we’re going to do apply and close now i’m going to select all of this press control shift f and it formats it exactly like i like so basically it changed all those keywords to uppercase and indented it in like i like not too bad now that was just one query i could put a semicolon in here and then let’s say i wanted to do another query on top of this i can keep it in the same script some things i didn’t call it before but anytime we’re typing any words you’re going to have this autocomplete and it also tells you what is going on there similarly if i’m doing something like a function count in this case it tells me hey it’s a built-in function in the database i can use this and then after i insert something like from it also it automatically knows hey he probably wants to put in a table so i could put something like customer in here now i have multiple scripts inside of here so what i could do is if i just want to uh enter this script i’m going to go ahead and close this out down below if i just want to do that script right there i’m going to press command enter and it’s only going to run the one script tells me there’s 104,000 rows now the other thing i can do let’s say i want to run all of these scripts they have this icon right here for execute sql script for me it’s the shortcut of option x on windows i believe it’s alt x i can go ahead and well we’re going to close out of this first we’ll select here and press option x and it automatically opens up each of these in different tabs now one thing to note is like okay how do i keep track of what are all these different queries that i ran right here well you can put a brief comment up at the top using two dashes and we’ll call this one sales copy and then the one at the bottom we’ll call this customer count now running this again pressing option x it prompts me hey there are three unpinned results tabs do you want to close these tabs before executing the new query i want to do this all the time if i’m running a new query i just want to see the new results so i’m going to say “hey don’t ask me again.” and i’m going to say “yes i do want these closed.” and that didn’t work because i actually told you wrong we need to you need to actually specify that this is a title so you specify title colon and then whatever it needs to continue on after that for what the title is i’m going to do that for both of these press option x and now both of these are named both below this is very convenient when you have multiple queries and you’re going to have obviously multiple different tabs also there is this one of the statistics tab basically just tells you the statistics that it ran two queries how long it took and whatnot so now with this test script that we’ve created if i wanted to i can see that it’s not saved because it has an asterisk i can go into file and select save or press command s or control s and the asterisk went away and now i can close it and if ever wanted to go back to that certain script i can just pop it up here and run it as necessary bam so now hopefully you’re follow along and you went through and installed dbaver because you need to do that unless you plan on using uh jupyter notebooks or collab to run the future queries anyway we now have some practice problems for you to go through and get even more familiar with dbver of all these different settings and actually getting familiar with running sql queries with that we’ll be jumping into the next chapter on building views so that’ll see you there welcome to this chapter on views now views only takes up really a small portion of this the majority of this chapter is going to be an intro to the project using views now in this we’re going to be going through three lessons in this lesson specifically for this video it’s going to be an intro to views how to create views how to delete them how to manage them and why they’re so important in the second lesson we’re going to be using that view that we’re creating in this lesson in order to analyze it further and answer one of our second questions in our project now our project in total has three questions which i’m going to showcase here what we’re going to be doing in a little bit and you may be like luke what happened to question one well question one we actually answered or start to answer it earlier in the lesson we’re just going to be building on it further in some future lessons don’t worry i’ll be getting you up to speed okay and then the third lesson that we’re going to be getting to in this is actually installing vs code which is a code editor that makes it super easy for us to build up our portfolio project and then share it onto the internet now before we get into views i want to just showcase what we’re going to be building in this project specifically we’re going to be sharing this to your github profile and it’s going to detail everything that you’ve done now if you’re not familiar with github this is a location that you can store and also share or collaborate on files here in this uh menu area this shows all the different files in this repo as we can see we have some sql files and then a readme which i’ll discuss more in a little bit and then we have like something like this which is an images folder if i click on it i can see that they have something like image inside of it anyway getting to that readme the readme on the front page of a project is going to be displayed right below it so here i can go through and actually document all the different analysis that i’ve done so if i have some employer interested in different analysises that i’ve done they can come to my github and view all that here and now you may be like luke why the heck do i need to install vs code you already had me install dbaver what the heck am i doing with this well vs code if you’ve taken my basic course you know is really powerful not only in writing sql queries but also in other coding projects like using python or whatnot anyway what the special use case in this project is is actually building our readme here i’ve typed out all the different portions of the readme and if we actually view it here i can see it all dressed up on the right hand side how it’s going to appear on something like github unfortunately dbaever doesn’t have these capabilities along with the fact that i can also go through and push this and put this onto github right here from this guey so loads of benefit those that have come from a basic sql course you’ve used vs code you’re familiar with it there’s not going to be a lot of stuff new that i’m covering here you’ll probably be able to even skip this lesson on vs code so let’s get into views well first of all what the heck is a view it’s a virtual table that allows us to show the results of a stored query in it for example we’re going to be going through in our next example and creating a view you can find underneath the views folder underneath a public schema and we’re going to create this one called cohort analysis whenever i click on it it’s that virtual table so this is a has all the different results for a certain query specifically i can go here under properties and look under source and actually see what was the sql query taken to actually generate this virtual table and so with this virtual table in this case it’s called cohort analysis i can open up a script i go ahead and clear all this out and say i want to select all the rows from the name of the view cohort analysis is even appearing right here telling me that it’s a view when i run it i get all the results of it below now views are super important and are necessary to level up your sql skills they allow you to or basically prevent you from having to go through and write the same query over time and time again because you know what happens whenever you have to write the same query over time and time again you’re eventually going to make a mistake with a centralized view this prevents that and also ensures that if you have this dedicated view that any other queries that depend on that view will get updated if for some reason you have to update that view anyway i’m getting ahead of myself what’s the syntax for this all it is is we need to use the keywords create view give it an alias and then provide all of our different sql that we had below it to actually go into that view so let’s go in to create our first view i’m actually going to go ahead and delete this view that we’re going to create because you don’t have it yet for this just open up a blank script in this we’re going to do a simple query that allows us to get the daily revenue for this we’re going to use the order date and then also we’re going to use the sum of quantity times net price times exchange rate and give it that alias of net revenue this is from the sales table and we need to perform a group by since we did that aggregation all right let’s go ahead and run this bad boy and it looks like it’s done all correctly one thing to note i didn’t filter this or put this in any order one thing to note is you can actually do that in here i can just click one of these filters and say hey order by we’ll say in descending order and it shows me okay we start in april 2024 and go backwards with the total revenue pretty neat all right so this is the view or that we want to create so let’s create it using that syntax specifically i specify create view give it the name of daily revenue and then just use as don’t need to put this in parenthesis i’m going to go ahead and run this pressing command enter and you should get something like this at the bottom telling me that the query is in fact finished now if i go to views there’s nothing there what i need to do is i need to actually refresh it you could do this by right-clicking and clicking refresh or you see the shortcut right here of f5 i’m just going to do f5 so now in this case that daily revenue is there i can double click on it open it up it has a few different tabs underneath it like i said the properties underneath it so we can see something like the source which gives us that query that we needed to create the view so we don’t need to save our query separately it’s right there it also shows our data and then finally our erd in this case it doesn’t really connect to anything else just its own table bam that’s it now if i wanted to access this view all i have to do is just do select star and specify i want this from daily revenue and since i’ve put that semicolon in the last one it’s only going to run this one when i run command enter now all the results are appearing below okay let’s say i’m done with this view or i don’t need this view anymore there’s a couple ways i can get rid of it i can rightclick it and just come down here to delete it’s going to then prompt me are you sure you want to delete this view of daily revenue and it asks do i want to cascade delete basically if there’s other views based on those views it’s going to delete all of those as well so you need to decide whether that’s applicable or not and then click yes or no or not we’re not going to actually delete it via that method and i’m just going to confirm it’s still there by refreshing this and showing that it is in fact still there instead we what we can do once again put a semicolon i can do something like drop view as a keyword and then specify that view of daily revenue okay let’s go ahead and run this pressing command enter it tells me underneath it was completed pretty quickly and coming over here pressing f5 we can see that view is no longer there very important note is that deleting views is permanent you can’t recover it once you do that so make sure you really want to in fact delete that view now that we got the basics of views let’s actually get into creating the view needed to answer a few of the different questions we’re going to be answering in our project once again a reminder we’re only going to be answering three questions for our project and we’ll be working on that second problem in the next lesson anyway you haven’t created this yet but this is what we’re going to be getting to eventually and like i said we’re going to have our view in here our different sql files to answer our three questions and then our readme this create view is what we’re going to start working on in this lesson we’re not not going to necessarily finish it in this lesson we’re going to finish it in the text cleanup lesson but we’re going to get a little bit of a start so what the heck does this view actually provide us that we’re actually going to use so we’re going to be diving into shortly a more advanced cohort analysis than what we’ve done previously and we need a table a view if you will to help us out and speed up that analysis specifically this table is going to be basically broken down and aggregated to provide us key things about a customer specifically when were their orders how many order they had when was their first purchase date what cohort they fall into and then additionally some customer information from the customer table this is going to be super helpful especially for something like total net revenue which does that quantity times net price times exchange rate it’s just already there i don’t have to worry about the calculation everything’s there so let’s just start building this view and we’re going to be doing this by just checking out our query we’re going to start with the sales table only bringing in the information we need first i’ll do a select statement we’re going to do select starf right now and then we’re going to be coming from sales now we’re actually going to be doing multiple tables in this so i need to go ahead now and i’m just going to add this alias of s i can also press tab and it adds that and then running this we can start picking out things that i want out of this with this actual table below i know i want the customer key along with the order date as always i want that total net revenue so i’m going be doing quantity time net price times exchange rate and giving it the alias of total net revenue we’re going to do one more thing also to get a count of the number of orders and we’ll do this off of the order key now because we do that aggregation we got to do a group by and i’m lazy i’m just going to go ahead and copy this up layer and place it below all right let’s go ahead and run this looks like i got a typo over here look at this syntax highlighting helping out to figure that out running it now bam we got our results that we want below everything look like it’s aggregating correctly now with this table i also think want things like the first purchase date and the cohort year this is going to take window functions going to do remember i don’t want to put that in a group by so we’re going to need to create a cte and then do it anyway what i’m trying to get at is instead i’m going to move over here to the customer information and we’re going to extract some key customer information to put into our source table so we need that from our customer table because of that i’m going to do a left join which allows us to keep all that information from the sales table and thus attach any related things from our customer table attached to it i’m going to give the customer alias of c and we’re going to link this on the customer keys of both tables i’m going to just run this to make sure we have no issues okay it’s running just fine so what information do we want to add on i’m going to do a c do star so we can add all of it on we’re going to actually refine it down and it’s telling me i need the c.customer customer key in the group eye we won’t have to keep this but this will just help clear up this error that i’m getting from using that let’s try that again all right so now scrolling over we can see that we start to have the customer information in here so i want things like the country full the customer’s age the customer’s given name and then also their surname and that should be it and now we need to put this all in the group eye because remember we’re doing an aggregation right here so i’m going to come down here and actually put that underneath here clean this all up and then we don’t need this customer key anymore i don’t believe so i’m going to remove that now let’s try to run this query make sure it goes and everything looks good we have all those different columns in it okay now what we need to do is extract out for all these different customers here what is their cohort year or the year of their first purchase so what i’m going to do is put this all into a cte i’m going to indent this over and then also space it down so we can put that width and i’m going to give it the alias of customer revenue assign it as do an opening parenthesis and then finally a closing parenthesis then to make sure that this is all correct i’m just going to do a select star from our customer revenue running this we can see that okay it is providing the exact same information that we had for run a good path now we need to do window functions in order to basically use that order date to get what is the minimum order date for a customer in order to assign that cohort year so for this i want everything from our customer view table i’m actually going to give it the alias of cr and i’m going to do cr.star star and then i want to get that minimum order date so we’re going to do minimum specifying our order date there’s a window function so we’re going to do over and then we want to partition it by the customer key so like 180 here we want to look at that and see what is the minimum of this and then we’re going to give it an alias of first purchase date okay let’s just go ahead and run this to see how it’s doing and we can see so something like rows two and three we should see for i got to expand this out we should see the minimum order date is 2018 in this case also 2023 so the cohort year for this or the minimum purchase date should be 2018 which it is now we can go ahead and build another column for cohort year and all this is going to be is just a copy if you will but we’re going to be using extract and then with that we’re going to just be copying the contents above of that minimum order date pasting it in here and then giving it the alias of cohort year let’s go ahead and run this rushing too fast i realized okay i have to extract something from that window function right i have to extract year from the windows function so now let’s try to run this we can now see that for customer 180 and rows two and three it is in fact the cohort year of 2018 this is good so now let’s create this into a view that we can then reuse we go ahead and enter a line down here we need to use these keywords of create view we’re going to name this cohort analysis and then once again we’ll use that as we don’t need to put it all in parenthesis though okay let’s go ahead and run this pressing command enter and it ran and super fast the view is if it’s not appearing remember we need to run f5 and now it’s appearing underneath here shows all of our different columns in here on the dr diagram also on the data tab so now with this analysis it makes it super simple what i can do is just create a new well i need a new script so i’m going to say new script here let’s say i wanted to analyze something like the total revenue per cohort super simple now to do with this view i specify obviously that cohort year the sum of our total net revenue and then we want to do this from our actual view which is our cohort analysis we did an aggregation so we need to do a group by specifically on that cohort year running this we can see our different results i didn’t do an order by i’ll just actually use this and order in descending order and so now in a super simple query i can get that at a lightning speed because i don’t have to do all that other analysis that i did before in that view because it’s already captured before we wrapped up this lesson this is a future loop as you can tell i’m in a different flannel we made a little bit of a mistake in our view specifically with naming a column that with the number of orders i didn’t give it an alias what do i mean by this okay going into cohort analysis anytime i want to use it i’m going to press f5 to just make sure that it’s fully up to date and if we go into the data we can see that everything looks like it’s fine except here for this column this is the number of orders but we left it unfortunately as count and that’s not a descriptive name we really need to change it to a more descriptive name and so this problem actually comes up quite frequently so this is actually good use case to go through anyway as remember when under properties and underneath source we can see all the different code now unfortunately with this command right here create or replace view previously we just saw create view create or replace allows us to replace it if it already exists now unfortunately i can’t come through here and update count here as num orders because that’s what the alias i want it to be and then this countdown here as numbum orders and then if i wanted to run this if i clicked save down here it allows me to say hey do you want to execute this it says cannot change the view column count to num orders instead you should use something like alter view or rename column to change the name of the view instead now alter view is a great thing to know of and what it can do you can go through and add additional columns remove columns and in our case rename columns so we’re just going to use this syntax to rename it but that’s only going to be a partial solution we’ll see so we’ll use the keyword of alter view we’ll name the view itself of cohort analysis and then we’ll use rename column also they have the syntax highlighting saying that it’s wrong because the table reference expected don’t worry about this it’s actually a f a false warning it’s not correct and so what column do we want to rename we want to rename that count and what do we want to rename it to is numbum orders now going ahead and run this command enter looks like it ran fine when we come back over here we can see that has a star next to cohort analysis that means it updated so we need to press function f5 we need to select inside the database navigator sorry press function f5 to make sure that it updates and i would actually recommend just closing out of the old one because we’ve changed some properties in it if you didn’t do it already and so we don’t want to mess with this we want to see what the newest one looks like so it says hey do you want these changed to persistent database no i don’t want them to so clicking cohort analysis again to get the newest up to date we can see that okay it doesn’t it didn’t change count up here but it did change it down here to give it the alias as numbum orders and i’m a perfectionist and also this is just good practice in general i want to change it in both locations in order to do that we actually need to drop this view like dropping a table and then create this view again so what i’m going to do is just copy all of this code we don’t need this alter view script anymore i’m going to go ahead and paste that in here remember we want numbum orders right here and then down here since we’re actually using it we can actually just remove it now before we run this create or replace view we need to actually drop this view this one’s simply written drop view and then we list the view name of cohort analysis i’ll put a semicolon after this and then i just want to execute this entire script right here so i’m going to press option x and it said hey it ran those two queries and it got done with it once again i’m going to close out a cohort analysis just make sure we have this select inside of here press function f5 and open up cohort analysis looking inside of our source and we can see that it updated numbum orders in both locations so crisis averted with getting that column up to date and keeping our query concise all right now we have a few examples for you to go through and get more familiar with creating views we’ll be using some of the previous examples that we’ve done in previous lessons in order to build views with so you can reuse them in the next lesson we’re going to be building further on this view that we just built in order to answer that second question in our project to further analyze the cohorts all right with that i’ll see you there welcome to the second lesson and in this one we’re going to be diving into a question for a project specifically how do customers in a particular group generate revenue regarding the particular group we’ve broken it into groups before doing cohort analysis is what we’re going to continue on from this now spoiler alert for this analysis we’re going to be looking at the different cohort years and at the customer level seeing how they spend money specifically seeing how they spend over time if you will generally it’s good practice to have customers spend more because it means more money and so we would expect that over time a company would learn and be able to extract more value out of customers unfortunately we find out just the opposite so let’s quickly reexamine what we’ve previously done on cohort analysis i’m not going to walk through this entire query we did this inside of our window functions chapter and with the results of this query we were able to plot out and see how what is the impact of a cohort on future years total revenue so as expected net revenue is going up and there’s contributions to these net revenues every year from previous years specifically members of previous year’s cohorts because your cohort year is based on your first year purchase so honestly this didn’t really uncover a lot for us does it tell us really that much we went even further and also did an analysis looking at the number of total customers and from this we saw that it went up as well once again not a lot of insights from this so what do we need to do well using our previous view that we created in the last lesson we’re now going to take that a step further and we’re going to analyze for the total revenue and the total customers but then finally get what is each individual customer’s revenue well on average at least so let’s jump into building this query for this we’re going to be using that cohort analysis i can dig into it and see that it contains all the same values that we did in the last lesson but from this i want to get based on the cohort year what are the total number of customers using that customer key and then also that total net revenue for that cohort so for this i’m going to start a new script and i’m going to go ahead and fill in the from specifically from cohort analysis and i like to do this mainly because when i go to fill it in if i do something like cohort year which is what we want one i can see that this column does in fact exist and also it does the correct syntax highlighting as i go along now with this we want to get the total customers per year so we’re going to do a distinct count so i need to do count or distinct inside of count specifically on that customer key we’ll give this the alias total customers now we need the sum of the total revenue so inside of our sum function i’ll use that total net revenue and we’ll give it the alias of just total revenue all right we did an aggregation function so we need to do a group by on that cohort year okay let’s go ahead and run this and just see what we have so we get back those total customers and then the total revenue now let’s look at this visually because i think it’s important to understand why we’re actually taking this a step further diving down to that customer level to analyze this well here i’ve plotted it where the bars are the revenue so you see it on the left hand side and then the line is the count of the total customers which is over on the right hand side as expected you can see that these lines basically correlate well to an extent to the size of the bars themselves so simply put mo customers equals mo revenue which that’s nothing new here and that’s not really any new insights that you’d go to your boss and tell them we actually need to dive deeper into finding out some key characteristics about the customers to actually give them insights of what their spending habits may be like so let’s get this customer revenue all we’re going to do is take our total revenue up here and divide it by the total customers itself and then we’ll give this the alias of customer revenue i’ll go along and run this query and now we have the customer revenue on the code here just a shout out to that views table look how simple this query is now now that we have the data in that view that makes this super uh quick to actually do this anyway back to actually exploring this customer revenue revenue over time we can see that it’s basically dropping over time let’s look at it visually and with chad gbt plotting this i have it showing that over time these customers spend quite a bit i’ll be honest uh they’re at around $3,000 per customer but then it starts to go down this is a exponential trend line that i had chad put on there anyway this is concerning that customer revenue or the per cohort year their revenue is dropping year after year i would expect like i mentioned at the beginning that either remains the same or goes up over time that’s not necessarily a good thing for this now i will say this remember that older cohorts so we’ll say in this case cohort 2016 they have all these years to contribute to their cohort so you could be part of cohort 2016 and also buy something in 2024 and so i would expect in general that earlier cohorts would have a higher customer res revenue so we need to adjust our query to account for this but you may be like how the heck do we do this do we use some sort of window function and limit the time of each of the cohorts and what is that is it like one day or one year that they’re in their cohort that you allow it to attribute to the customer or to the revenue for that cohort well i actually did some further analysis on this you don’t need to actually run this query and what does it show well we’re not going to walk through step by step all the parts of the query because that’s not important the main thing is what it provides out of it and that’s that what i have it plotting or what i had it do is go out and calculate what contributes to the total revenue based on the days since this first purchase so in total about $127 million were spent on day zero i.e the day of the first purchase and then after that it dropped significantly to like 31,000 51,000 and whatnot anyway with this total revenue i went and took it a step further and put it into a percentage and we can see that it goes from 61% to less than a percent i also plotted it for more of those visual type and so what we can extract out of this is that in general or on average a customer spends for the total revenue that it spends spends about 60% of it on the first day and then minimal after that so what we’ll do is go back in and adjust our query to take account for this and for a cohort year we’ll only look at the revenue for that cohort year if the purchase was completed on their first day and we won’t take into account anything else because the majority of purchases are done on the first day so how can we do this well conveniently in that view that we created we have not only the order date but also the first purchase date so we can use those two dates and match up where they’re equal to each other to get only get those purchases so i’ll put a wear statement in and we’ll set the order date equal to the first purchase date and that’s really all we have to do for this now pressing command enter we have some updated results and it looks like our customer revenue dropped a little slightly and plotting it we can see yeah it drops down slightly below 3,000 although it was before around 3,000 anyway the main thing here is now whenever i have this exponential trend line which i thought that you thought like with removing those previous years that had more spending actually it’s more pronounced that the future years such as 2022 and 2023 spend even less so this is a pretty big breakthrough that we’ve come to basically uncover in this and could lead to especially at the trend that we’re going at right now this could have serious implications on the business and would be a great insight to bring up to our superiors or to our stakeholders so that’s the end of what we’re doing for answering this question on analyzing customer groups as i feel like we’ve found a pretty significant insight with that what we’re going to be doing in the practice problems is actually going in and doing an analysis of the revenue and the total customer count but looking at it over time on a monthly basis to get to find out why do we have certain years lower than others and to uncover other insights that i’ll detail more in the beginning of the next video after you get done with those practice problems we’ll be jumping into installing vs code which we’re going to be using to document the insights for our project specifically in the next lesson we’re going to be documenting what we learned from this question specifically with that see you there welcome to this last lesson as we’re going through this chapter on an intro into our project specifically for this we’re going to be going through and setting up vs code now as a refresher on why we’re doing this and not using something like dbver dbaver is great at actually going through writing sql queries analyzing them and improving them but when it comes to actually sharing it and collaborating with others using things like github or even documentation tools like markdowns it gets quite hard so for both my workflow and kelly we like to use this in cooperation with vs code and this code editor is going to allow us to do two major things for this the first is we’ll be able to build a readme or a markdown file that will document all of the different analysis that we’ve done whenever we want to go and share this and the second it makes it super easy to push this up to github and share it with others to see the work from our readme or markdown file now if you take my basic sql tutorial you’d probably have vs code so you can skip that portion of the lesson but we will be going on to how to actually build out that readme specifically for question two which we answered in the last lesson but before we jump into that we’re going to quickly go over the analysis you did in the practice problems that we uncovered even further insights in the last lesson we went through and evaluated how do different customer groups generate revenue specifically we broke it down by cohort year and we found out what is the average customer revenue per cohort year at this macro level we were able to see some call out specifically that there’s a general trend going down for c uh per each customer revenue which is not good and so as our practice problem assigned you went further into analyzing why do we have these dips was there something deeper going on in the data set besides just customers spending less so to catch people up that didn’t do the practice problem we went through and analyzed customer revenue and total amount of customers on a monthly basis we got this final table which has that total revenue total customers and then the customer revenue let’s start with the customer revenue first because we’ve just been talking about that as we saw in that last lesson we saw that it’s slowly going down over time so analyzing at the monthly basis not really helping out that much now if we look at something like the total revenue and the total customers and we plot this we get something like this where the blue bars are the monthly revenue and the line chart here is the total number of customers so looking at general trends overall if we actually plot a line of best fit we would say or we would think that our revenue is going up over time or our net revenue is with the exception of a pretty big dip down in 2020 probably due to some sort of pandemic that happened during that time period and then it rose after that and then it was slightly less down in 2023 anyway the major insights that i think we are applicable to us from that last analysis is if you actually look at it how we said previously you know more customers equals more revenue it does match up but then when we get to 2022 and 2023 we can actually see that there’s pretty large gaps in between here there’s a lot of customers but the revenue is not matching which helps us explain even further what’s going on in this graph basically yeah we’re getting higher number of customers but customers are spending less anyway pretty interesting insight on this let’s get into installing vs code if you navigate over to the link on the screen you’ll get directed to the download page for visual studio code more recently microsoft has been advertising this with github copilot so it has this hey it’s redefined with ai and they’re really pushing that we’re not going to go too much into ai features we’re just going to be downloading this code editor you should download some sort of file click it get it launching and in the case of mac it unzips this file and it’s automatically the visual studio code app which i can just take and drag and put into my application folder so it’s in a much safer more secure location if you’re on a windows machine it’s going to walk you through an installer so quite a bit more steps but it’ll actually direct you on where you could actually put this vs code and if you want an icon anyway regardless you get a system message asking if you want to install this app that’s installed from the internet yeah you’re fine with it open it upon launch you’ll get this welcome message that will actually guide you through a step-by-step process that if you want to do you can do but we’ll be covering all the key features you need to know for this so don’t feel like you have to do this so let’s briefly explore visual studio code before we actually get into installing or setting up our projects folder that we’re working with over here on the lefth hand side is our activity bar and whenever we press our activity bar a sidebar slides in or out depending on if we want it there this first one’s an explorer we don’t have a folder open yet i’m just going to open a dummy folder you don’t have to need to do this and anytime you’re opening any of these it asks if you want to trust the authors i’m opening from my own computer i trust myself i think so at least anyway this basically shows a file breakdown of what’s inside of this folder and then folders themselves have these carrots that you can drop down or open if you want to see inside of it if i actually want to see these file locations you can just rightclick it and then on mac it’s reveal and finder on windows it’s going to be reveal and file explorer anyway you can see that the structure of this is the same as what we’re seeing over here in that file explorer all right other things in the activity bar we have a search functionality so if i want to search sql all the different occurrences will pop up here and i can go to it and it will take me right to it next is on source control which controls how we’re going to get this onto github we’ll be covering more of this and interactions with github near the last chapter or in the last chapter so don’t worry about this too much oh and i guess what i forgot to mention previously whenever this popped up over in this right hand side so if i’m to close this sidebar right here this is our code editor itself so if we actually open back up sorry and open that second query i’m going to close this now we can see i’m going to actually expand this by pressing command plus or control plus on a windows we can see that we have that sql query right inside there and if i needed to add anything like i did want to use an alias right here i could just type it in and then now we’re noticing that up here in the top there’s this white dot appearing that means it’s the ch we have changes this is not saved you can just save it by pressing command s or control s now what we’re going to be doing later on is actually going into the readme and building this readme out and what i really like about vs code is as you can see we have all this fancy dancy markdown language typed into here and if i wanted to see what it actually looks like with the readme selected i could select this right here and it allows me to preview the readme with all the different images and whatnot right next to it as i’m scrolling through so one of the main benefits why we’re using vs code all right i’m going to go ahead and close all this out also going to zoom back out so we can see everything um okay last two things they have a debug run and debug section we’re not going to be using that and then finally extensions it’s really popular if you’re using this for a particular programming language like python or whatnot to have the appropriate extension installed so in this case you install python to use python we’re recommen so overall there’s not a lot of extensions or really any that i think you need to install for this if you do want to install one just to see what it’s like i recommend this one on code spell checker when i click it it opens right up next door and if i want to install it i just click install it asks if i trust this publisher yes i do and now i have this code checker inside of here so if i actually went back to that sql file we had previously it will now go through and flag some of these keywords that don’t have an underscore and it calls it an unknown word you can actually go through and try to do a quick fix with it but those are the column values that came with the database so we’re not going to change them at all mainly i find it useful for if say i need to create a new alias and i’m going through it and i wanted to sum something like total customers and i assign the alias if i were to assign an alias with misspelling in it like this when butchering customers it’s actually going to call it out and so i know that i misspelled it there anyway that is extensions no i don’t want to save any of this the other two things in the activity bar to be aware of are your account right here and then any settings specifically what i find myself gravitating towards using a lot is this command pallet which has the shortcut of command shiftp or control shiftp that’s the one shortcut for vs code i would highly recommend having memorized when i do this this search bar comes up at the top and then i can search any type of settings i want to change in vs code so say i wanted to change the maybe the color theme of this i would type in something like color oh i can see that i have preferences color themes and then it allows me to go through a menu and select a host of different options in here the last thing to note is the status bar down at the bottom we won’t be using it too much like in our case right now i’m zoomed in and i could go back and reset it you’ll also have information down like the lefthand corner if we’re using git and then if there’s any issues going along with it let’s now get into setting our projects folder up that we’re going to be eventually pushing to github we’re going to be setting it up building out our readme and also adding all those sql files or the last sql file from the last lesson for this we want to open a folder that has our project in it but we need to create a folder if you will now back in dbe if you remember we created a project folder already and it has bookmarks dashboard diagram and even all of our scripts in it i’m not about reinventing the wheel i think we should just use this project right here as our project folder itself so we can do this a couple different ways i want to find the location of this so i’m going to rightclick it and i’m going to say hey show resources in explore now this is the projects folder i’m actually going to back back out just one location so that we can see okay so this is the folder itself of this intermediate sql project along with those folders underneath it i want the file path location to this specifically i want to go to this folder location when we go to open this in vs code so i’m going to open up a folder in vs code on macs unfortunately the folder location that this is within is hidden so i’m going to hit a shortcut of command shift period and i know in my uh home folder of luke baruse that it’s in the library folder and then from there i can navigate to the debaver specific folder going into my workspace i then see the project itself and then i can open it it’s going to ask if you trust the authors of this file in this folder i do i’m also going to just enable this to trust the files and all folders within here so now we have inside of our explorer right here we have a few different folders if you will i’ll be honest we’re not going to use any of these at all actually one thing to call out is you may visually only see the bookmarks diagram and scripts but then we also have these other they’re called dot files and once again if i press command shift period on this we can see these dot files they’re actually just hidden files i’m going to maintain them hidden by pressing command shift dot anyway key thing here is those folders and files aren’t important along with we can be selective on what we actually put into github so we will need to be because we don’t really want to put these up there anyway anyway let’s make our first file we come up here to the top and we select new file i’m going to give this the name of two i like to do two to basically designate hey this is the second question and call this cohort analysis.sql and as you notice as soon as i name that sql file i got this new icon right there that shows me it’s a sql file when i press enter it automatically opens in the text editor to the other hand side what i can do is now copy that query that we did previously then inside of vs code paste it all in i have this white dot saying that it’s not saved so i can press command s or control s and it’s now saved in there so i’m going to go ahead and just close this all out one thing to note inside of dber underneath that projects folder itself we’re not seeing any of the different files pop up like we just created that sql file that’s because we haven’t refreshed it if i actually rightclick select refresh the query now will appear inside of this project folder if you’re clicking refresh and it’s not refreshing or showing that i actually had to just restart db to get this to work so yeah just word of warning anyway this sql file is now here and so i’m actually going to close out this script and this one so if i wanted to i don’t necessarily have to go back into vs code if i want to edit it i could edit it from right here say in this case i call this ca and then i save this pressing command s whenever i come back in here and actually check this sql file i can see that the alias got added i don’t want it i’m going to add command s so let’s get into building our readme file as a reminder that’s going to be basically the front page of our project detailing all the different analysis we did breaking down each of the three questions that we’ve gone through or will go through now key things to note for github we want this file to be called readme.md and that’s because github will specifically pick up on this naming convention and then display this below here so we’ll get into creating a file i’ll call it readme and all caps locks then this icon changes to that readme icon and for the file it’s a markdown file so i’m going to give it m then go ahead and press enter and it’s open up right next to it first thing i’m going to do is just start by giving it a title remember we can do different headings depending on how many hashtags we have i’m going to give it this one of intermediate sql sales analysis but what the heck does this actually look like we can click this icon right here for it to appear right on that right hand side so as we go through and type different things we can see how it is actually formatted as we go through this now what sections are we going to be putting into this well really it’s up to you you don’t have to follow all or even any of the things that i’m going to put into here but i’m going to recommend these major sections first we’re going to have a short little overview then from there we’ll get into our three business questions just giving the short description and then from there getting into the analysis approach breaking down each one of those we’re going to be doing question two on the cohort analysis and i’m going to walk you through that shortly now below these three questions in the analysis approach i only included one example right here we’re going to have our ending which has things like our strategic recommendations what we got out of this and any technical details of what we actually used to build this so let’s start going through and filling this in we’re going to start with business questions here i’m going to put uh one two and then three for the second question we did a cohort analysis and with it we were asking how do different customer groups generate revenue now i’m not really liking how this is formatted so i’m going to use some extra markdown in here putting double asterisks before and after cover analysis and then it like bolds it makes it stand out more so now let’s go into filling in the analysis approach that second question i’m going to go ahead and just copy this one right here paste it below and we’re going to start going to for this i’m going to title this section cohort analysis next we need to put in an analysis approach that we actually used here so i put some short bullet points in here of how we track revenue and customer counts per cohort what is a cohort is that we’re grouping it by year of first purchase and we analyze customer retention at the cohort level the next thing i like to include is the query itself now you can go ahead instead of doing a link we’re going to go over link shortly you could put in a code block so i’m going to just do three back ticks in this case you can find it up here top of your keyboard anyway i could just copy this query right here and then put it into our readme and it’s displayed right here i could also format it as sql by putting sql after those ticks and then it’s getting colorcoded like this oh this is all smushed i’ll be honest i’m a fan of dry or do not repeat yourself we already have this code somewhere so i’m actually not going to put that right here instead what i want to do is put a link to this sql file and we can do this by putting square brackets and in square brackets is what the text is going to be i’m just going to name it the name of that file and then in parentheses is the actual file location on a mac i’m going to press backsplash i think windows you can press forward slash and then all the different things that i have access to are going to appear right here i’m going to select that first one of the sql file and then yeah now over here on the right hand side i can see whenever i click it oh the file itself actually pops up so i know the link is working properly and these links are also going to work on github when we get there all right next section i have are on visualizations and that’s if you’ve generated any images you don’t have to do this per se but in my case i really like doing this so what i’m going to do is i’m going to come over here and i’m going to create a new folder and call it images i like to organize all my images in one location so i’m going to take that image it’s on my desktop i’m going to drag it over into the folder itself it’s right here conveniently it’s just named image i’m actually going to change that by right-clicking it and selecting rename and call it this of two_cohort_analysis okay now going back into the readme itself the image name is just the alt text you can put with it mainly we need to be more uh pertinent about what the actual image name is once again i’m going to sl backslash and then from there i want to go into the images folder and i want to select two cohort analysis oh it’s popping up right next to it no i’m good after this we’re going to dive into key findings and i’m going to summarize this calling the main points that revenue per customer shows an alarming decreasing trend over time i call out specifically that 2022 and further years are just declining over time although net revenue is increasing is likely due to a larger customer base which we found out when we did deeper analysis and this finally brings us into the final section of what are the business insights and so for this i have the following that the value extracted from customers is decreasing over time and needs further investigation we need to find out what is the root cause of this in 2023 we also saw a drop in the number of customers and so we also saw a drop in revenue because of these two facts alone the company is facing a potential or actually what we saw in 2023 is seeing a revenue decline so overall this is a good step in the right direction on what we need to recommend on where we need to go all right it’s your turn to now go through and build out that readme document and hopefully you’ve been following along with installing vs code and whatnot we do have a few practice problems for you to go through and get more familiar with vs code if you want that practice along with we’re going to have that template for you available in order to build out this question number two all right in the next chapter we’re going to be getting into data cleaning my favorite part of data analysis so i’ll see you there welcome to this chapter on data cleaning and in this we have three lessons we’re going to be covering for this in the first two we’re going to be covering some core concepts you need to know about data cleaning specifically this lesson we’ll be going over conditional expressions for handling nulls things like coales and null if in the next lesson we’re going to be going over strings because from time to time you’re going to be dealing with strings and you’ll need to clean them up and maybe put them together or even separate them at the end of that lesson we’ll be applying all the concepts we’ve learned in order to further refine our view on cohort analysis finally in the third lesson of this chapter we’re going to be getting into answering question one from our project which focuses on customer segmentation now our project consists of three questions and in the previous chapter we focused on that second question on cohort analysis in this one we’re going to be using customer segmentation in order to find out who are our most valuable customers and we’re not only going to be using that cleaned up view of cohort analysis to help answer this but also some functions we learned earlier on statistics so we’re focused on two functions for this lesson and you may be like luke how the heck did you pick that out well if we go into the postgress documentation underneath the sql language we can see that underneath the functions and operators there’s a host of different ones that we’ve covered if you’ve covered along since the basics course we’ve covered and touched on a lot of these and we actually have covered on conditional expressions navigate under this we can see that for postgress there’s four main types and the main one is case which we covered back in basics but there’s two more that we need to cover around coales and null if now postgress has this one on greatest and least these functions have different capabilities depending on which database you’re working in also kelly and i don’t really use this this much so we’re not covering greatest and least anyway let’s get into how we can actually use coass and nullif in a very simple example you don’t have to follow along with this i’m just doing this for demo purposes so the easy way to demonstrate this is with a fake table i’m creating here i’m calling this a data jobs table it has three columns in it technically four i guess if you count the id and what does it contain well let’s just run this query to actually see we get this table and in it we have things like a job title a column on whether is it a real job and then a final column on salary notice inside of here that there’s some null values in here we’re going to be using coass and nullif in order to clean these values up depending on what we want so let’s say for this column on is real job we wanted to fill in null values specifically let’s just assume that the database administrator assumed that all null values were no but we needed to make it no well we can use the coales function and in this it returns the first non-null value from a list of expressions right now we’re just going to use one expression we’ll move on to two after this but we can provide a default value in this case of no and ultimately in our case this is going to be used to replace a null value with a default value so here is a query that returns back our original table let’s modify this to fill in null with no so i call that coales function for expression one i leave it as the column of is real job and then for the default value or the last one we’re just going to put in no let’s go ahead and run this bad boy oops forgot to put a comma run it again okay we can see now we have this column called coales after the function and it’s filled in yes no kind of a better practice would be to actually assign this an alias when done so that way we can actually see it and bam we have the updated column title now what’s going on here with that coales function where we have this second expression well let’s say we wanted to fill in this null value for salary but we didn’t want to use a default value we wanted to just fill it in with if it’s null maybe just put in something like the job title specifically depending on where it matches up you would fill it in for the appropriate row that it comes from let me demonstrate it okay so we’re going to use that coales function again we’re going to leave salary in there and then for the second column we’re going to specify job title i’m going to leave the default value blank for right now finally i’ll give it an alias of salary pressing command enter now whenever i run this i’m going to make this a little bit bigger says error colas types integer and character varying cannot be matched the problem is salary is an integer and job title is a string so anytime you’re using this to have a column replace other they have to be the same data type in this case we’d have to cast salary as a text or varcar in order for it to match that same one that is job titles now when i go ahead and run this it actually works below and we have in fact filled in the appropriate column from that job title into salary you could put a default value in here i’ll just name it default value but in our case when running it not going to come up so let’s reset this back so we can get into null if now with our original table back say we had a scenario where we knew certain values weren’t correct or we didn’t want them in there and we wanted to make them into a null and like in this column of is real job kind of isn’t really an answer maybe we want to now make this into something like null now with null if this returns null if two expressions are equal otherwise returns the first expression and this one’s even more simple in that it can have either expression one or expression two where they can be either columns or single values let’s jump into it so let’s say we wanted to replace this kind of with null we call our null if function is real job would be expression one and then expression two would be that kind of as usual i’m going to give this the alias of is real job okay let’s go ahead and run this okay we in fact replace that kind of with null now you don’t also have to just do a default value i could do like i said an expression so i could do another column so in this case i could do salary once again i got an error message and it revolves around having a mismatch between the data types i can just fix this by casting salary as a text running command enter and bam anyway the point null if right none of these comparing these as it goes through none of these match so it doesn’t convert any of the values to null this value was always null anyway let’s jump into some real bro practice problems now previously whenever we’ve been doing any of our analysis all of our customer keys have conveniently always had some sort of purchase associated with it what we’re going to demonstrate is that all the customers in that customer table don’t necessarily have an associated purchase with it and whenever we merge them together they can actually have non values or none values or null values now if we were to run an average to find out what is the average net revenue per customer whenever we just have these nine values they’re not going to be counted but say we do want to count them because hey they are customers and we want them to be zero instead that’s going to affect the average overall and we’ll actually get to demonstrating how much it’s going to change the average revenue per customer quite a bit now let’s get into combining our customer keys with net revenue to show those customers that don’t have any purchases previously we’ve gone through and in our sales table gone through and got the customer key um got the net revenue by multiplying quantity times net price times exchange rate then obviously we’re doing a aggregation and so we need to group by customer key now running this we have net revenue for all these different values in here if i try to filter to find any net revenues that are null if i go to run this we’ll see that down below there’s no values in there so we hadn’t been seeing this previously but what we can do is with all of these revenues that we have right here we could merge this onto our customers table and then this will expose customers that don’t have a net revenue so what i’m going to do is convert this into a cte use a width statement calls this sales data and then assign it in parenthesis as always i like to make sure that this works so i’m just going to select star from sales data and go ahead and run this yep working below now what we want to do is i’m actually going to go into kazo erd is take that customer table that we have here and merge onto it that sales table so we’re going to make the customer table our a table and then sales table our b table so what we want to do is using our customer table use a left join to join on our sales table so we’ll move the sales data down we’ll say that this is going to be the left join and we’ll give it the alias of s for the sales data and then for the from we’re going to be doing from customer with the alias of c let’s go ahead and just run this to see if it’s working and i got this error message saying syntax error at end of input basically i didn’t say where or on what we’re going to actually merge on specifically we’re going to be merging on the customer key of both of these different tables okay let’s try to run this now all right we have the customer keys and all the information from the customers table we don’t need all this information per se we just want to make sure we have all the customer keys along with all the different net revenues and as you can see there are now no values in here because there’s customers that don’t have net revenue so let’s modify what we’re actually bringing in here we’re bringing in from the customer table the customer key and then from that sales data uh cte above we’re bringing in net revenue running this boom simplified version of actually being able to view this so first let’s fill in these null values with a zero just to demonstrate it in a new column we’re going to call that coales function running that on net revenue and we want to place those nulls with a zero running command enter bam we got this over here so not bad now what we want to do is to show the difference between these we’re going to run an average on only net revenue and a average on the net revenue with zeros filled in so basically all customers i’m going to remove that customer key so that way we don’t have to do a we want to do an average on all of that so i’ll call the average function on that first column and an average on that other second column for zero filled in for the null values running this we can see that the averages are quite different right so the first one is around 4,000 and the second one is less than 2,000 now these names for columns aren’t that descriptive so i’m going to name the first one as spending customers average net revenue because they’ve spent money so that’s the only the customers that we use for this and the next one is all customers average net revenue now running it more descriptive titles for this and viewing it visually we can see that when we look at all customers the average net revenue is actually less now this was mainly done for demonstration purposes cuz there may be situations where you do want to consider all customers in our case we are going to just consider only the spending customers in our analysis and not necessarily all customers so that coales we’re not going to do a real world example of null if because it’s going to be frankly very similar except opposite if you will but what i have are practice problems for you to go through now and get familiar with both of these options in the next lesson we’re going to be jumping into understanding how and all the different functions for formatting strings so with that see you there and in this lesson we’re going to be going over further on data cleanup specifically around strings how to format them we’re going to be covering four key functions that i find myself using from time to time and then from there going into modifying our view that we created on cohort analysis specifically we have columns on a first name and last name we’re going to combine it into one let’s get into it now in the last section we were looking at function operators specifically going down here we were looking at conditional expressions in this one we’re going to be going back up into this section on string functions and operators now inside of here there’s a host of different functions and operators that we can use on strings and the first one we’re going to be jumping into is this one here on lower how to convert something to lowercase and with any of these functions they’re going to take string values so in that case i’m going to do that lower function and i’m just going to put a string in in there and we’ll just put my name in all uppercase we’ll go ahead and run this we can see it outputs it below in all lowercase if we have lower we probably also have something like upper running this we can see that it’s all upper this would usually in the case that you have some lowercase values in there and it would raise it all up if there were some lowercase values in there the next is the trim function we’re focus on the one up here this one down here is a non-standard syntax so we’re not going to use it and from this it relieves the longest string containing only characters and by default it’s a space let’s actually just look at this real quick to understand what’s going on so in the case of our example if we’re using this trim right now whenever i run this command enter there’s no really change in this whatsoever now let’s say that there was a space at the beginning and we’ll do a space at the end running command enter you can see that there’s no spaces when if we were to just run it without this trim function i’m going go ahead and actually just remove this running command enter we can see that it does in fact enter spaces in there even when i check it so using this function is very important especially whenever you’re working with databases with very dirty data and you need to remove any different spaces now let’s say that we had some symbols in there like we had dirty data and we had some symbols surrounding this that we wanted to actually remove in this case i have two amperands around each when i run this command enter we can see we have this but we want to remove that from here well going back to this definition of it we can specify whether we want to trim based on the leading trailing or both being the front or the back of a string and by default it does both is well both is the default then we can specify the character text which is what we want to remove and then from the string text so inside of here i could do something like both i want to remove that amperand sign and i remove it from this let’s go ahead and run this and it removes the both those amperands on the front and the back also i notice that my e is missing in here now going ahead and run it boom now that’s what we have so what we’re going to be cleaning up with this view well if we open it back up go into cohort analysis we can see underneath that data tab we specifically want to focus on this that given name and surname which will be like last name and first name anyway we want to combine these into just one column we don’t need them to be separated for our analysis now because of this we’re going to have to actually update our view for what we have currently now with this we’re going to be basically removing two columns and then adding a new column so because of this we can’t necessarily just run create or replace view since we’re altering columns we need to run like alter view but that’s even going to get complicated i’m going to recommend we just start over with this query and drop this view so i’m going to go ahead and go ahead and copy this command c and then in here i’m going to go ahead and paste it now remember we want to combine our given name and surname i’m actually going to just run this query to show what’s going on here press command enter i have this as in front of here that doesn’t need to be in front of here so i’ll move that up top run it again okay we have all of it as we saw before the given name and surname so we want to combine these two going back to the documentation on string functions operators scroll on down until we get to other string function operators they have on here the concat function this concatenates the text representations of all the arguments null arguments are ignored so for given name and surname what we can use is this with the concat function specifically i’ll type out concat open and closing parenthesis around here so we have the given name and surname and we’ll name this as the clean name okay let’s go ahead and run this and now we can see the names are now combined okay not too bad now one thing to note is well we need spaces in here and sometimes i find especially with text columns there may be extra spaces in here so one let’s just add that space i’m talking about i’ll do a i’ll do a single quote space single quote and then comma run command enter and now we can see that that there’s a space in between here but like i said sometimes the names may have spaces around them so just as good measure i’m going to put trim around both the given name and around the surname okay running this pressing command enter we now have all the values cleaned up in here and we did some protection so now we need to actually update this cohort analysis where if we went to look at it remember if we just tried to run this right now so create a replace view as the cohort analysis pressing command enter i’m not going to get it because of the column issues that we addressed before so we need to actually just drop this database or drop this view first so we’re going to call that drop view on cohort analysis and then run everything underneath it i’m going to run this all by pressing option x and looks like two queries are done as always i’m going to just close out of this to make sure i have the most upto-date one click inside of here press f5 to refresh and open up cohort analysis scrolling all over we can see we have now that clean named inside of here so our view is good to go now for the project all right you got some practice problems now go through and get more familiar with these text formatting functions in the next lesson we’re going to be jumping to another question for a project on customer segmentation looking forward to it see you there welcome to this third and final lesson in this chapter on data cleaning and for this we’re going to be focusing on question one for a project specifically this is going to build further on analysis we actually did earlier with segmenting customers and some discussions on customer segmentation specifically we’re trying to find out who are our most valuable customers for this we’re going to be breaking up our customer into tiers using percentiles into highv value midvalue and lowv valueue customers now this is a very typical business process that you would find yourself doing in order to target certain customers and then distribute marketing that fits their need and so shout out to kelly for coming up with this example because i feel it’s a really good demonstration of what you find yourself be doing as a data analyst as always i like to start with what is the final data set we’ll be getting for this and so we’ll be calculating or actually finding out based on customer key and that clean name that we did in this chapter to determine what is their total ltv lifetime value or their if you will net revenue and then based on these values we’re going to use percentiles to categorize customers in either to low value midvalue or high value we’ll also take this calculation a step further and also dive into analyzing not only just having those names that way marketing can target these customers but also actually understand these values such what are the percentages of these different segments how much they’re contributing and whatnot so let’s start a new sql script documenting this analysis similar before we had a our own script for sql here i’ll go ahead and we’ll start a new sql script then i’m going to go up here and then rename this we’ll name this to one_c customer segmentation.sql okay this should be good all right now one thing to note this is going to be inside of our scripts folder but we don’t necessarily want it here if i rightclick this and then go into show resources in explore underneath scripts i can see it’s right here and i actually want it higher up so i’m going to move it out if you’re on windows you do something similar with your file explorer and then down here it’s not actually showing up i can press function f5 and that sql script disappeared but now i’m actually seeing this one and also readme is popping up now i guess i didn’t uh refresh as well anyway i can now open this back up this is what the sql file is we want to work with so first three columns of interest that we want to get into here so we want that customer key we also want that cleaned name and then from there we want the revenue for each of these customers or that total lifetime value so we use a sum of total net revenue and we’ll assign this as total ltv just as a reminder going back to that cohort analysis we could have multiple entries in here like 180 did multiple purchases on different days and we had that in a total net revenue so that’s why we’re renaming this new column total ltv because now with 180 we’ll have the total lifetime value we want this from our view of that cohort analysis and we’re doing a um aggregation so we need to do a group by using the customer key and then also clean name so let’s go ahead and run this and see what we have i have no active connection so if there was a reminder if you’re already connected reconnect to your database and i just need to reselect it up here now everything’s looking good let’s try to run this again all right bam this is what we want clean name customer key and then the total ltv for each of these i can even i can even do the order by descending or actually i want to do order by ascending and see that hey okay 180 is now combined into one looking good now that we have this total ltv we can now bucket these customers into high value low value and what’s the other one midvalue now we’re going to be doing this on percentiles using the 25th percentile and 75th percentile so because we’re using or running a percentile on this aggregation right here i’m going to put this into a cte we’ll call this customer ltv and we’ll put this in parenthesis from there on this ct we’re going to run that percentile continuous function remember we’re doing the 25th and the 75th percentile basically everything between the 25th and 75th percentile is our midle so i’ll do 0.25 and then we’ll do the nomenclature of within group because we want to group it by a certain thing and we need to order the ltv or the total ld ltv column to make sure we’re pulling out the correct um ltv as we go through and sort this and then we’ll give this the alias of just ltv 25th percentile let’s go ahead and just make sure this is right so i’m going to do a from the customer ltv pressing command enter boom okay 25th percentiles at 843 i did this already i know that this is actually correct so let’s now get the 75th percentile i’m going to go ahead and just copy this all because it’s just going to take some changing to do to it and then putting it inside of here changing that two in multiple locations to a seven and then running this bad boy boom so just so you understand what’s going on here those that spend around $843 are at the 24 25th percentile and so if you spend less than this you’re less than the 25th percentile whereas the 75th percentile those are around spending around $5,500 if you spend more than this you’re greater than the 75th percentile these will be our high value customers and those less than 25 will be our low value now what we can do is let’s just go back and i’m going to run just this query up here now what we can do because we have those percentiles we can use this basically customer ltv cte and we’re going to convert this percentiles one into a cte as well we can categorize or bucket them using a case when statement of whether they’re high value or low value or mid-value so we’re going to be making this into a ct i’m going to tab this over put a comma and we’re going to name this customer segments and then as once again opening and closing parenthesis so that way this is in a in a cte from this we’re going to select and i want all the customers from customer ltv so i’m going to do a um we’re going to give it the alias of c so i’m going do c.star and i’m going to go ahead and just put this down here of from customer ltv and like i said that’s going to be of the alias c and it’ll clear that little syntax error let’s actually just make sure that everything’s appearing right down here i have a comma after this so i need to remove that it’s appearing down here now we need to go through and now make that case when to basically bucket all of these into their different tiers gonna move this down some so it stops uh so it stops cutting it off okay we’re going to do a case and then we’ll do when and the first one i want to categorize is everything less than 25% as low value so when total ltv is less than this ltv 25 percentile which i’m realizing now we haven’t imported in now we don’t necessarily need to do a join with this what i can do is a comma because we’re not join it to the data i can just list it of customer segments and give it the alias of cs so now that’s available we can say cs.ltv 25th percentile then we want to assign it the low value we’re going to do one tac low value we stick a 1 2 3 at the front just to make the easier if we want to ever sort it um if you just do low value only and then try to like sort by the name alphabetically it like throws a fit mainly meaning you can’t sort it like that anyway let’s go into the next one and i’m just going to copy this because a lot of this can be repetitive and for this one we want to get everything that’s midvalue so everything that is less than or equal to the 75th percentile so that mid-range is going to cap encapsulate everything that’s equal to the 25th percentile up to the 75th percentile and equal to it and then i’ll change this to two mid value now since we got everything underneath the 75th percentile we can now categorize everything else as high value all right let’s go ahead i’m going to remove this space here let’s go ahead and run this and fingers crossed i see my issue i have a syntax error at or near when and that’s because i don’t have a comma after here also i never gave this alias or this case statement a name specifically we want to name this customer segment all right let’s go ahead and run this bad boy okay it’s working now let’s make sure that these are categorizing correctly if i remember previously i’m actually going to just select this one time and press command enter oh and i realize now it’s uh not going to let me do it like this unfortunately i’m going to just copy this go into a new script because i want to actually show this then paste this bad boy in and run this and i’m silly i need the other ct anyway you don’t have to do this main purpose of this is just to see what these numbers are remember it was 843 for the 25th percentile and 5,500 for the 75th percentile now running this complete one are these numbers making sense yeah because 5500 should be the high value it’s greater than that for this second entry and then looking at these these fall in between yeah it looks overall let’s look for a low value okay we got a low value down here of $23 falling in okay data looks like it’s calculating correctly all right so this table right here would be great to now export and send to our business colleagues to basically find those people that we want to target i don’t know why this window is so wide like this um but on mac let me know if you’re having these same problems it shouldn’t be this big anyway i’m not going to do this right now but this would be great to send to business colleagues and for them to actually now send targeted campaigns to these individual items depending on what our strategy is and how they are segmented but let’s dive a little bit further first to analyze how much do these different customer segments how much um how much are they contributing what is their customer revenue and also not only what is individual and average customer spending but also what is their total revenue so what i’ll do is i’ll now convert this into a ct as well cts on cte on cte i’ll give this the name of segment values and then as and then once again open and closing parenthesis with this we’re going to just go first and get the customer segments and mainly that customer segment column i mean and we’re just going to get this first from that new cte of segment values okay let’s make sure that this is just working correctly and we can see it’s doing this all down here so the first thing i’m going to do is get a sum of all the different revenues so we’ll run sum on total ltv and we’ll name this conveniently total ltv because we’re doing a summation we also need to do a group by on that customer segment all right we’ll go ahead and run this all right not too bad so this is telling us the total amount and our high value is at 135 million whereas our low value customers have only contributed 4 million if we plotted this on a pie chart to see how much they actually contributed part i only recommend pie charts if it’s three or less values we can see that low value is oh my gosh we got to do something here and target these lowv value customers better so this is great the analysis that we found out of this midvalue is around 33% which you would expect it to be about a third and then the high value is almost 2/3 so that’s pretty i mean really high for high value so based on just this little data piece alone this is evidence enough that we need to do some different marketing strategies especially with our lowv value customers now because we put those numbers in the front of this customer segment if we wanted to we could also do an order by and we could do that on customer segment and we could put it in descending order running this we’re now getting those high value up top mid value low so that’s why we put those numbers in the front for those columns so we can sort it more easily anyway let’s calculate a couple other things mainly i want to find out what are the number of customers in each one of these segments so that way we can then go through and find out what is the basically average ltv or lifetime value for a customer in a certain segment so getting the count first we’re going to be using the customer key for this we’ll assign this as customer count running this we got the counts and as expected one and three should be equal because there’s 25% in this 25% of that and then this one right here should equal the basically double of these um because it’s the 50th uh it’s 50 percentile or 50% in between so now that we have this total ltv and this customer account we can divide these to get the average customer value so i’m just going to take this and then divide it by this value right here and this will be our average ltv bam all right now i’m going to close out of this right here so this is pretty interesting our highv value customers are submitting or submitting on average around $11,000 whereas our low value are only around $350 pretty substantive probably why those low values only contributed around 2 or 3% of that total revenue now there’s a host of different marketing strategies you could go about doing this you can feel free to pause the screen and look at into each one of these of what you could go for doing this isn’t necessarily a master class on marketing strategies it’s on data analytics we’re not going to spend too much time on this but i did want you to understand what are some different capabilities we can do with this powerful data now there’s no practice problems for this lesson but i do expect you to go through and update your project readme specifically i added a little description of what we’re doing for all the different segments i added a link to our sql script along with that visualization that i showed you earlier breaking down those things because that was the key insight we got from this i broke down the statistics talking about the highv value midvalue and low value segments how much they contribute of each and what their contribution of revenue is and the big disparity there and then i wrapped it up with business insights what could we potentially do to target highv value midvalue and low value customers all right it’s your turn now to go through and update all that we’re jumping into the next chapter in query optimization where we’ll not only go query optimization but also answering our third and final project question see you there welcome to this chapter on query optimization for this we have three lessons we’re going to be going to the first two are going to be focused on understanding how to use the explained keyword along with some query optimization basics the second one’s going to jump into more intermediate and advanced ones and then finally in the third lesson we’re going to wrap it all up with our final problem for our project now in this video in the next one we’re going to be going over query optimization techniques and i have a list here of beginner intermediate and advanced techniques you should be familiar already with beginner ones but we will do a refresh during this video and then in the next one and the next lesson we’ll be jumping into that intermediate and advanced and this will all be done while using explain and analyze to break each one of these down now for the third lesson it’s conveniently on the third question or the last question in our project specifically we’re going to be doing retention analysis analyzing who hasn’t purchased recently we’re going to get a visualization similar to this and wherever we break it down by the different cohorts years and see how many customers are active and how many are turnurned or didn’t purchase something recently this is a super common business concept to understand and coincidentally kelly was just telling me that she actually was implementing it in her job today so let’s get into breaking this down we’re going to be using these keywords of explain and explain analyze for each of these they just go at the beginning of a sql command whether what you’re using but what’s the difference between these two well explain demonstrates the execution plan without actually executing it whereas explain analyze basically means like it’s going to analyze it and it actually does execute it so we understand what the execution times are so say we have this simple query of select star from sales i could use explain at the beginning of this running command and enter and it’s going to tell me the query plan i’ll break this down in a second now we also could use something like explain analyze right and remember this one is one row when i run explain analyze we have two more rows mainly this one has the execution time it has well not only the planning time but also execution time so you may be like luke when the heck would i use explain and when would i use explain analyze like why would i want this if this doesn’t even tell me the execution time well let’s say you’re working with an extremely large database like millions or even billions of rows it could be extremely cumbersome to run this query and cost a lot of money not only time but also money so there may be cases that we would only want to use explain but since this database we’re working with is so small we’re going to always be running explain analyze with all the queries we do that way we can also see the execution time so let’s break this down on what this is actually providing so this first row here says that it does a sec scan which means it does a sequential scan basically going row by row by row and it specifies that it’s doing this on the sales then from there we have three variables inside of parentheses here cost is just an arbitrary unit and that’s just assigned by postgress if you want to be real about it it’s just made up but quantitywise it remains consistent the one thing to remember is that these numbers just because say you have a cost of 500 and then another one you have a cost of a,000 the query is not going to necessarily take double the time it’s just going to take longer anyway with this cost you can see it has the syntax of this starting value then this dot dot dot and then the next value after this this is the start cost and then this is the final cost so ultimately this query cost in this case that is shown in demo 18.5 next are the rows and so that’s the estimated number of rows and then finally the width is basically still that row size but what it is in bytes going back to our original query we can see that we have a cost a final cost of 4500 there’s almost 200,000 rows and the width is 68 bytes ultimately this took this query took 30 milliseconds to run and the planning time or what it was going to do whenever it was planning on how to execute this query took less than a millisecond now all the times with dealing with all of this are going to be in milliseconds so you may be like luke what does this even matter like we’re talking about 30 like half a second well once again this is going to come into play whenever you’re dealing with databases that are millions and billions of rows those milliseconds aren’t going to be that anymore and i’ve had queries run as long as an hour so query optimization is a must for you to understand now expand this out we can actually see there’s some other things as well to cover here specifically going along with that execution time we have the actual time the rows and then loops rows remain the same in this case loops is a more complicated topic and really relies on if we’re basically performance and sort of recurrent loops especially whenever we do joins we’re not going to worry about that too much but what i do want to focus on is this actual time right here and this tells us that hey we started this query at 017 milliseconds and it ended at 14.8 milliseconds and then the time after this of the execution was the time it took to display it and do all that now it’s important to understand that with explain whenever i run this one it does not have that extra parameter over there as well i didn’t have it uh pulled out at the moment but we still have that same thing of cost rows and width okay so let’s build on this further by calculating the net revenue per customer and seeing how this query plan changes for this we’ll say we need that customer key and then like usual we’re going to be doing a sum and this will be summing up the quantity times net price times the exchange rate and we’ll give it the alias of net revenue okay let’s go ahead and run this bad boy and i got ahead of myself we got to do a group by anytime we do an aggregation so i’ll be specifying that customer key and then running this okay now with this what’s going on here is there’s actually two steps here each of the steps are denoted by this basically this arrow right here so this right here is a step and then this up here these three rows are now a step the first step would sort of counterintuitive but that first step is that sequential scan on sales it’s the most indented one in the fact that we’re doing the scan on the sales table getting all the rows we needed of 199,000 and we can see that that took 9 milliseconds to do then the next step goes into here performing the hash aggregate basically it does a hashing system in order to perform the aggregation we’re not going to go into hashing right now the important thing is understand that we are doing a sum function which is an aggregation it tells us it takes from 54 to 56 milliseconds so about 2 milliseconds to do this and this is done on only 49,000 rows and that’s because that group by or that customer key condenses it down the amount of rows under this it has other other information like group key and then also how much memory was used ultimately this query ended up taking slightly longer than we did previously now we’re up to 57 milliseconds total i’m going to add just one more thing to this and let’s add a filter to it and we’ll say we want orders only from 2024 so we’ll say that it’s greater than or equal to 2024 january 1st okay let’s go ahead and run this and we got an error for this why do we get an error right here well it’s because i have it out of order and that’s because even in the execution aspect we’re going to filter our sales table by that in 2024 and then perform our group by and aggregation and we can actually prove this by our execution plan in the fact that in our first step right here our sequential st scan it actually goes through and filters by those dates so that are in uh 2024 then after this which after we filter it for 2024 we can see that we have down to 10,000 rows then it sends it into our aggregate to do the group y and our sum and this takes 27 to 28 so this is like well even less than a millisecond and ultimately because now we do this wear clause we have a much shorter execution time so not only are we learning about how to read query optimization we’re understanding why do we have the order of these keywords such as where and group eye anyway it’s important to note that we’ve been using explain and explain analyze but over here on dbver they have an explain execution plan now if i try to run this with this explain analyze up here and click this and click okay it’s going to give me an error because we already have explain in there so it’s important that you select what you want to use and then use the explain execution plan or the shortcut of command shift e now this is going to pop up and asking what you want to do if you don’t want to do the explain analyze you want to leave that unclked i usually just maintain all of these clicked including the analyze and then from here click okay this i find is slightly less descriptive but it is more ordered in the information that it provides it’s still pro uh still in that same order of sequential scan is the first step and then the aggregate is next starting at the bottom going up but as far as the times and every and the cost they’re actually more in a readable format than that execution plan anyway is available if you want to use that way we’re going to compl continue to use explain analyze throughout the reigning of this video and the next video cuz i find that post useful last thing note is if you encounter any keywords you don’t know the best thing to do is just go ahead and copy this all and go into your favorite chatbot just paste it in and have it go through and actually explain what’s going on here step by step by step so in the remainder of this video we’re going to be going over some beginner optimization techniques that we’ve touched on briefly throughout this course but actually using explain analyze to prove why you should be doing these in the next lesson we’re going to go into more intermediate and also briefly cover some advanced techniques in order to further level up your optimization skills for this one on basics we’re going to be covering three ones and we’re going to be going over examples on the first two on why we use select star why we use limit and then for the third one we’re just going to just briefly discuss of using where instead of having we’ll start with the easiest one to actually prove it’s efficient and that’s using limit if i just run select star from sales on the entire sales table running command enter it’s taking around 18 seconds and what what you will notice for this i’m going to run this a few times the time actually jumps around so on average it looks like it’s around i don’t know around 24 or so anyway i have this in a not not optimized sql query i’m going to come over here to the optimized query so we can compare them before and after and we’ll put a limit statement we’ll just say we want 10 and this bad boy we get it in 03 milliseconds run this a few times yeah it’s maintained pretty consistent around 03 compared to our previous of almost 21 so there’s your actual proof that those limit statements are very helpful in minimizing the amount of data and saving you time next is on select star you’ve heard me time and time again saying “hey i don’t recommend using select star to select all the columns of the table.” so let’s try to optimize this and you know what i’m just going to list one column and that’s it customer key whenever i run this we can see actually i need to run a few times we can see that it’s over 30 seconds whereas the not optimized one whenever i’m running this one it’s less than 30 seconds what the heck’s going on here well in some cases like this one postgress makes it super efficient for them to retrieve data using this select star nomenclature and so yeah it is more efficient in some cases to use select star but i’m still sticking with it in the fact that i do recommend especially when you get into bigger databases millions and billions of row i would still stick with only listing one or however many columns you need for your analysis and not using select star now the last one to look at is using where instead of having and unfortunately you may not always have control over just easily switching from where instead of having so let’s say we have this query here where we’re actually getting the customer keys along with all their net revenue for it now if we wanted to filter this data based on the net revenue and maybe get some that are higher than or less than a certain value we would use a having clause in this case and we say hey we want that having greater than 100 or greater than a thousand and if we remember from order of operations that we first do that sequential scan so we get all 199,000 rows then when we’re doing the aggregate we then are doing the filter in this step with that 199,000 rows now we’re moving back to that original query to demonstrate this now with a wear clause unfortunately the having benefit is using it in aggregation but we may have a case where okay we can alter this instead to have it to where we want to get customer keys that are we’ll say less than 100 so not using that aggregation but more posts on a customer key anyway with this one the main point is that the filtering is done in that sequential scan out in the beginning and as we can see from this because it limits with how many rows are done our execution time is a lot shorter now you may be like luke you’re using where with a customer key of less than 100 and you’re using having the aggregation that we did of greater than a thousand yes i know these aren’t necessarily comparable but there may be a situation where yeah you know you want these net revenues a certain value and thus you want the maybe the order keys of a certain thing and you could then filter instead by the certain order key values or specifically not order keys sorry customer keys mainly what i’m getting at is if you have a choice that you could potentially modify to do where instead you need to take advantage of it all right you now have some practice problems to go through and get more familiar with using explain explain analyze explain feature inside of dbver along with testing out some of those basic techniques that we just went over the next lesson we’re going to be going over some intermediate and also advanced techniques along with a real world price problem all right with that see you there welcome to this lesson on optimization techniques we’re going to be starting by jumping back up where we picked off last and jumping into intermediate intermediate techniques we also briefly cover advanced techniques but overall they’re going to be outside the scope of this course and you’ll see why then at the end of this we’re going to be going into optimizing our query that we built in the last chapter on data cleaning basically applying all these techniques we’ve learned into how we can make a query run faster so what are we going to be covering for these intermediate techniques well we have four ones to cover but the first one we’ve really been covering in the last lesson and in this lesson of using query execution plans basically using that analyze basically using things like explain explain analyze or even dbver’s built-in options now we’re going to be going over three other scenarios besides this on minimizing group buy reducing joins when possible and optimizing order buys so let’s say we have this query here where we’re going through and getting things like the customer key order date order key line number and then also getting an aggregation of the net revenue which i need to add an alias of net revenue okay let’s go ahead and run this just to see what’s going on anyway we can see from this that well it’s two main steps of doing a sequential sand and then actually aggregating with our group five but our execution time even running this a few times is pretty high up there i mean sometimes getting as much as 100 milliseconds once again we’re dealing with milliseconds but if you have databases that have millions and billions of rows this can easily turn from milliseconds to seconds soon as those queries get longer than something like one or two seconds they get annoying af anyway with this query itself i’m just going to select it and run it we may not necessarily need to find out every individual line number and so if we were to go ahead and remove something like n line number in our case i’m going to go ahead and move it over to this optimize area and then take it out here along with taking it out here and then running this oops got a little bit of typo try again okay we can see that now we have a much lower execution time here at 67 seconds but consistently less than 100 that was just by removing one group buy so an important concept to understand is it really necessary to do all those group buys it can get costly over time and in this case we’re almost saving half the time if you will just by removing one group by next concept to get into is minimizing the number and also types of joins if you will on when we’re doing a query in this case let’s say we’re pulling in multiple tables into our sales table we’re also pulling customer product and date table i’ll go ahead and just run just the query itself and we can see we have yeah a lot of information in here now running this full query to actually run the explain analyze we can see that this query takes over 100 seconds running this query a few times we can see it runs around h around 80 milliseconds anyway pretty intensive anyway if we go back to that original query in this case we can see that we’re pulling in the year from the date uh table what happens if we remove this interjoin and just added in a way to extract out the year out of the order date so i’m going to go ahead and just copy this all paste this into the optimized i went ahead and already moved the inner join down here and then we’re going to just write an extract function using year from s.order date and we’ll give this the alias of year okay and we can clearly see whenever we run this this is providing us the exact same information of that year running the query completely now i need to move it up some running this one we can see well it’s looked like it’s maintained around 70 so the other one i already forgot what it was running around it’s running around 80 or so 80 or 90 so this one is i mean almost we’re getting a 10% gain or increase in performance just by removing an inner join and instead doing a function instead now it’s also important to note that establish the number of joins but also the type of joints and we’ll get into that with the practice problem coming up in a little bit last major concept to cover is optimizing your order buys sometimes order buys are not something you can just like negate but if you can they will save you some times specifically here well let’s just go ahead and print out this query pressing command enter i’m getting the customer key order date order key and net revenue and in our order by we can see we order by our net revenue first followed by customer key then the order date and then the order key rarely do i find ordering by all columns is really necessary anyway there’s a few different ways we can optimize our order by the first one the easiest is just limiting the number of columns in order by the second is avoid sorting on computer columns or function calls the third probably the most intuitive is place the most selective columns first in the order by basically if it’s doing something that’s going to filter out other rows you’d want to use this one first and then finally use index columns for sorting to leverage existing database indexes unfortunately we don’t have control over indexes indexing usually a database administrator does but if you did you’d want to use it in that case anyway let’s go with one of the recommendations of removing function calls so we’re going to go ahead we have explain analyze up at the top i’m going to run it and i’m seeing it around 90 milliseconds or so now i’m going to take this exact query put it over here and we’re going to remove that well the net revenue the aggregation up here on the sum let’s go ahead and run this and this one i’m seeing a lot less usually around the 70 to 80 millisecond range so we just cut off about 10 to 20% doing that alone now maybe we find out even more that we can remove the order by let’s say we want to just remove all the way to the customer key itself and then run it in this case i’m not finding that much of a difference even seeing it get as high as 90 so i’m not finding that this one is as great as the aggregation but overall we can see that it does have an appreciable impact compared to our notoptimized query so let’s get into optimizing our view that we’ve previously worked with and that was with cohort analysis we can go into it under databases right underneath our data set underneath schema public and then our views ourselves that cohort analysis now we can actually look at the query itself going under source and we have it all here i’m actually going to go ahead and just copy this bad boy and put it into this script here on not optimized i don’t actually create or replace any view so i’m going to actually remove this and instead put up at the top of explain analyze so i’m not liking how this is formatted so i’m going to highlight it all go to format and go to format sql and it’s going to break everything out more of like how i like it now let’s go ahead and run this explain analyze on here to see what we’re working with for our current execution time um and i have a typo because i didn’t get rid of this as in the front of here going to go ahead and run again okay boom we have this all and wow there’s a pretty hefty query plan and we can see this is some of our highest execution times that we’ve seen so far around 200 milliseconds to get this bad boy done it looks like it has a total of 1 2 3 4 five six different steps and that looks about right with the ctes and all the different group eyes we have in here now recalling back to what we just previously covered of how we can improve a query just looking at this we can see that the cte well it has a a bunch of group eyes also has a join so that may be able to be optimized and then we look down here to this bottom one this bottom or the main query itself and there’s not a lot of different techniques that i feel i can put into this as this is just doing a simple select and then from so primarily we’re going to be focusing on inside of the ct of customer revenue and the first one we’re going to focus on is the join now previously we discussed about minimizing joins but actually which is also just important is understanding when you should be using what type of join now a lot of our course and the previous course used either left joins or inner joins with left joins they’re specifically used in the case of for table a you want to keep all values in it and if there were maybe some null values that matched up with from the b table for the a table you would want those null values to fill in for a so we didn’t remove any of the a well if we knew what we were matching on had all contents from both the a table and the b table thus there are no nulls inner join is slightly more efficient to use because we no longer have to do this null check before actually joining so what i’m going to do is i’m going to copy this query and put it over into the optimize section and i’m going to change this here from left to inner the first thing i want to show though is the actual query itself the output pressing command enter what i can do down here is i can i want to see the total row count so i click this okay that’s around 83,099 if i go back to our one with a left joint i hope that whenever we run this query i’m going to select it all and then press command enter we can see for this one the row count is 83,999 so the same so they’re still doing the same thing where this one has a left join and this one has an inner join so now the question is is the explain analyze whenever we run this on the nonoptimize and on the optimize is it going to be quicker well for the not optimize or with that left join it’s around 200 milliseconds and that of optimize is well around the same thing around 200 milliseconds so although it didn’t work in this case to further optimize our query and just works out to basically break even there are cases where using an inner join instead of left join when appropriate can save you potential time in your query execution all right so we talked about joins the other last thing that we can do in order to optimize this query is has to do with this group by look at this we have a bunch of group eyes and when we actually look at it based on what we’re aggregating by we’re having a lot of repeating values and country full age given name and surname what do we mean by this well let’s actually look at the query itself for customer say 180 yes the order date is going to change yes the total net revenue number of orders but as far as things like their country full the age their clean name their first purchase date or even the cohort year that’s not going to change so why are we doing a group by on things that aren’t going to necessarily change we really care about just grouping it by the customer key and then also the order date so what we can do for this is like we said we want to minimize those group by but this query is not going to work if we go to run it right now it’s not going to work anymore what we can do is we can do an aggregation function with this we just need the max value from each of these or you could do min whatever not it’s very popular just to do max and i’m doing this for age the given name and then the surname with this it’s also important that you give it back its alias so i’ll be giving it for country full age given name and also surname so first let’s go ahead and just run this query and make sure that it’s working properly scrolling on over here we can see that everything’s remained the same for the country full the age and then also the given name or that that final clean name that we got to i think i called out first purchase year and cohort year when i first talked about this they didn’t have anything to do with the group by they’re done lower below anyway let’s go ahead now and run this query see how long it takes and with this one we can actually see that we’ve now got the execution time down to 160 milliseconds where previously it was around that 200 milliseconds so now that we have this optimized query that’s taking less time we can go ahead and update our view and we’ll be using that create or replace view cohort analysis as so we’re not changing any columns with this so technically this should work without doing a drop i’ll go ahead and run this it’s now telling me that it’s changing data type so in fact we do need to delete it or drop the view first of cohort analysis we’re going to now just go ahead and execute the entire sql script said it ran both the queries come over here press f5 to make sure that we have it refreshed open up cohort analysis and i can see that we have those max values and we’ve minimized that group by along with changing our join and it looks like it actually saved it to a simpler join now now that we were using that inner join to just join alone which that’s the default so makes sense now the last last thing to cover are these advanced optimization techniques we’re not going to be walking through any of these but they are ones that you should be aware of specifically they have these three major ones of using proper data types so basically not referencing data uh integers or numbers over something like a string using indexing in order to speed up your queries so basically relying on certain columns with indexes built in to sort them more quickly and then for large tables you can have partitioning built into them to per uh improve their performance now all three of these are controlled by database administrators specifically they control the data types they control whether columns have indexes and they control how data is partitioned so we’re not going to go into this because it’s going to be really specific on whether your database administrator has done this now if you ever run into a situation where you’re finding queries are running excessively long and you plug into chat gbt and you can’t find any results except for this around indexing or partitioning or data types this is when you’re going to have to go to your database administrator and ask them to make changes to your table that way you can get more efficient queries hopefully you have a good database administrator i have in the past and been able to go directly to them and get what i needed out of it and saved me a lot of time in the long run all right you have some practice problems to now go through and get more familiar with those intermediate techniques and optimizing your query along with using explain and analyze again all right with that i’ll see you in the next one where we’re getting into our third and final problem in this project see you there welcome to this last lesson in the chapter and for this we’re going to be tackling our third and final question looking into performing retention analysis specifically we’re going to be looking at who hasn’t purchased recently we’re going to use terms such as active and turned customers we’re going to look at it totally overall and then from there actually break it down into the different cohort years to see how it’s actually trending over the years as we have these different cohorts so we’re trying to identify which customers haven’t purchased recently and the technical business terms for this would be we’re trying to act identify active verse churned customers for us active will be those that have made purchases within the last 6 months whereas churned are those that haven’t made a purchase in over 6 months now 6 months isn’t necessarily something you’re always going to use as the hard and fast to delineate between active insurance it’s really going to depend on your industry and maybe even other factors as a general rule of thumb i have these four different areas and contazo falls into an e-commerce and typically we’d see them use a 6 to 12 month period since last purchase for this whereas something like a mobile app is going to be much more quicker with turnover so they’re going to have a 7 to 30 day since last session to identify active verse churned customers and now you may be wondering why the heck this even matters well we can send off this data that we end up calculating on finding out if a customer is active or churned and we can do specific targeting marketing campaigns in order to get them to re-engage also when we look at this holistically towards the end to get these like percentages per cohorts and stuff we can understand maybe the effectiveness of previous campaigns that we’ve used in maintaining activeness and preventing churn overall this deals with tracking our customer retention and also engagement which is necessary because we know we have customers that have bought from us before and they’re likely to do it again so we need to take use of that so what are we going to be working towards well we want to basically build this table here which is going to have information like our customer key and our clean name along with calculating things like when was their last purchase date and ultimately was this in the last 6 months and then classifying this as either churned or active to make this easier we’re going to be using the view that we’ve been using of cohort analysis because this has all the information that we need from it in order to extract out this information now like our last two problems i want to be working in a script that we’re going to be saving as our final script to upload into our project we put on to github right now we have our um one and also question two what i’m going to go ahead is go to vs code and then inside of here i want to create a third file and i’m going to name this retention analysis remember this is a sql file so i do dossql and then click enter we’re not going to edit it inside of here i just want to actually create it and then now going back inside of dbever and clicking inside of here i’m going to run f5 to refresh it and we now have our sql file right here that we’re gonna be working in now what are we gonna be quering well let’s go back to that cohort analysis and open it up things we definitely want are the customer key we have this clean name that we saw additionally we’re going to be using that order date and we can also use the first purchase date which will be used for some filtering that i’ll explain later so let’s start defining all this we’ll start with a select statement we’ll define that customer key the clean name the order date and that first purchase date and we want this all from cohort analysis okay let’s go ahead and run this looks like i don’t have any active connections so we’ll update it real quick to select the right data source and run all right so now we want to get well we’ll target specifically this customer 180 right here we have these two purchases we already have a column for the first purchase date but really we want to know when was their last purchase made in order to understand if they bought it within that sixmonth period so we need a way to go through and basically identify in a numerical way what is the most recent purchase and we can do this using row number and partitioning so right after order date i’ll enter inside of here and we’ll do row number we want to do a partition so we use the keyword over then we put inside parenthesis the partition by and specifically we want to partition it by that customer key and then we don’t want the we don’t want it assigning just numbers willy-nilly we want to actually specify it depending on the order date so we’ll do an order by specifying order date and we’ll name this as row number which you’ll typically see this written as rn okay let’s go ahead and run this and not bad now looking at customer 180 again we can see that we have the most recent purchase is actually number two so it goes one two we actually want it opposite of this so like their most recent purchase is numbered number one so i can change this order by to descending run this again pressing command enter and now we have it in that manner and it does order it we can also double check on some other ones here at 387 everything’s looking good so not looking bad we’re almost to what we need out of this mainly i don’t need any more duplicate duplicate entries i just want to get the most recent purchase out of here and that can be done by basically filtering for row number equal to one so what i’m going to do is put this all into a cte and then pull out what i actually need so i’m going to tab that over and we’ll give this the name of customer last purchase put it all within opening and closing parenthesis and then from here do a select statement we want that customer key clean name order date and we’re getting this from the customer last purchase remember we want to filter this right where that row number is equal to one go ahead and run this have a little typo in here put something i didn’t need to go ahead and rerun it all right looking good now order date technically now this order date is i mean it is an order date but it’s actually now the last purchase date so i’m actually going to rename this with an alias of last purchase date looking good we now need to get into classifying each one of these customers as whether they’re active or churned now i need to show you something real quick so i’m actually going to do underneath this another query we’re just going to look real quick at the order date column and that’s from the sales table i’m going to go ahead and just run just this query then i’m going to filter this in descending order and so what we can see is actually the most recent date this data ends on the 20th of april on 2024 now i can actually just query this by doing a max of the order date run controll enter and it’s still that 420 so why am i telling you this well as of filming this it is march of 2025 so we’re almost a year ahead anyway if we went back from my time now six months none of the customer there’s not any data in the system within that six-month period and so we’d have like a 0% act well we would have a 0% active rate so the point is we have to do this from our last data point of 6 months past this 420 or 6 months before 420 so what we’re going to do is this we want to now actually let’s go back and run up this query we want to now categorize these using a case statement looking back seeing if they’re within 6 months of april 20th 2024 and if that case classified as active otherwise classified as churned so in our main query down at the bottom i’m going to go ahead and put a case in and then we’ll do a when then we want to use this column we know it’s called order date when order date is less than 2024 of april 20th and specifically minus 6 months so within 6 months of that period so we’re going to do an interval specifying 6 months in this case we want to classify it then as churned so better said going back or doing this actual calculation right here if there are any purchases before october 20th 2023 we’re going to classify them as churned else we’re going to mark them as active and then we’re going to end this case statement also i want to give it an alias of customer status okay let’s go ahead and check this out i’m going to remove this extra line right here and now run command enter okay we got this error message right here invalid input syntax for type interval specifically right now for this we’re trying to do a comparison for order date basically 10 20 of 2023 this sees this as a string we need to actually cast this as a date using this operator go ahead and run command enter and now it is working now we have this extra column we can go through and actually double check it we can see here november 2023 is active december 2023 active and looks like it’s matching up pretty well now there’s one other thing or one minor detail that we need to actually filter correctly for to make sure we’re getting the right calculation i’m going to go ahead and filter this data to show what i mean all right this is it anyway these are the last purchase dates and actually this isn’t actually showing what i want to show we want to show first purchase date i’m going to show it right next to this so i’m going to call it first purchase date right here remember we have it up in the cte up above so i can just call it right here and whenever i run this it’s now here let me actually now filter by this okay this is what i’m trying to show their first purchase date was or these customers however shown was firstly on uh april 20th and there is active so if we keep scrolling back all of these for a number of period are active and so they haven’t been a customer really for six months yet so they’ve never even qualified to become churned i would argue that this would cause a bias to increase our numbers especially in 2024 for making it look like all of our customers are actually active actually and that’s what will happen in 2024 if i scroll all the way through here and we get to the beginning of the year all of these customers in 2024 will remain active when i run a percentage on this it’s going to say 100% active in 2024 which is completely useless we need to actually go back and remove everybody until 10:20 because that’s when it’s keeps on being active but then here this is when we actually start getting churn customers cuz we actually get customers that have been part of the system for greater than 6 months so all i’m going to do is we’re going to modify this query here at an a end and we want this for first purchase date basically all of this to categorize that a period of october 20th 2023 i’m going paste it right here now let’s go ahead and run this and i’m once again going to filter by that first purchase date and we don’t have a first purchase date now until after october or before october 20th when we actually start having churned and active customers so we’re going to have a lot better description or actually key statistics that actually match up with the data now we have this cleaned up we actually don’t need this first purchase date anymore that’s not something that marketing may necessarily need we now have that final table that i was getting at that we needed to get with customer key clean name when was their last purchase date and whether they are active or churned one minor note on this query i am not a fan of hard- coding values into a query because say we got a like a data dump and we get more recent data files this number may change in the system instead we could use something like a subquery so i’m going to put this all within to parentheses and then i’m going to just take this command exit and i’m going to place it right here and then also right here okay and then now whenever we run this we have exactly the same results that we had previously and this is much cleaner so way if those dates ever do change or we get new data into the system it will automatically update so we have the data or the table we need for marketing but now i want to take it a step further and actually perform an analysis on this and one we’re going to look at just holistically overall what is the active and churned rate for everybody and then we’ll finally break it down by cohort year to see how the cohorts are trending over time so let’s just get a percentage for the active and then the churned i’m going to make this now into another cte i love me some cte and we’ll call this one churned customers i’ll put that into open and closing parenthesis then for this we’re just going to start simple first i just want the customer status and i want to count of these on active verse churned for each so i’m just going to do a simple count and we’ll do this of the customer keys itself and we’ll name this as numbum customers we’re gain that from that churn customer cte and we did an aggregation so we also need to do a group by on customer status okay let’s go ahead and run this all right so not bad looking like we have around 4400 active and 4,200 churned i prefer percentages so we’re going to move forward to calculating that one thing real quick we don’t need to necessarily run distinct on this if i ran command enter still going to be the same values and that’s because in here we ended up filtering down to only where row number equals one so there should be technically only one customer key so i’m not going to i think that’s just a little unnecessary we’re not going to include it so now we need to get basically another column if you will of total customers i want to basically add these together should be around like 46,800 but if you see here we’re doing group by well we can actually use window functions to expand bigger because window functions are done after the aggregation so what we can do is we can use this once again this count here to get the counts of these keys but then we want to do a sum of this using a window function and we’re going to do this over but we’re not going to partition by any anything because we want to do all of this and we’re going to name this as total customers okay let’s go ahead and run this all right and we have i was little off on the math that’s actually 46,913 now we need to have both of these right if i just did sum and tried to run this we get an error along with if i just ran count we’d also get an error we have to do the count of them and then we want to do a sum of this to do all of this in order for it to work so now what we can do is we can divide these two values to get our percentage so i’ll take this first value here paste it down right here we’re going to divide by the total customers which is this command c command v and we’ll name this as status percentage okay let’s go ahead and run this and not too bad numbers there’s a lot of numbers here so i could just do a round function around all of this and i only really care about two decimal places we’ll go ahead and do this and now it’s down to 9% and 91% which comparing this to the industry i’m using some like perplex perplexity which is a chatbot that searched the internet to get some values anyway i asked it what’s a typical turn rate in the e-com in a e-commerce company and it says hey a turn rate of under 5% is considered good however the average turn rate for the e-commerce industry is around 22% so this one’s pretty or our company is a lot lower than industry standards all right let’s just take this one more step further and now we’re going to be forming or finding out what is this active versus churned rate for our cohort years and see how it progresses over the years now all we need for this is well we need to add another column on cohort year um but the problem is we actually need to import it higher up specifically it’s inside of our cohort analysis if i actually look inside of here you can see cohort year is there so after that first purchase date i’m going to add in cohort year and then in our second subquery i’m also going to add it in here now because we added these extra parameters up here we needed to add it into our group by to make sure that it’s working just fine specifically i’m going add in cohort year and i actually want cohort year before this okay let’s go ahead and just run this this isn’t going to be the correct calculations just yet and so we do have that cohort year inside of here we have that active verse churned as we can see we have our number of customers but our total customers are 46,000 the entire time basically this is all of our total customers and then this is driving our percentages down so for 2015 we have 1% and 6% together these two rows should equal 100% the problem is we’re dividing this 237 by 46,000 we don’t want the total customers per se we want to be the total customers of 2015 so conveniently all we have to do is inside of our window functions we just have to add in a partition by and we want to do it by cohort year so we add in cohort year go ahead and run command enter and i need to learn how to spell partition okay we got good syntax highlighting now all right and i’m seeing this this is it looks like it’s adds up to the correct amounts all right looking good i’m actually going to take this partition by and also throw it into our status percentage below so we have the correct status percentage calculated and now whenever i add up these two values it will equal 100% for all of these and as we we can see it goes from around 8% up to in more recent years up to 10% graphing it visually we can also see this trend that it’s slowly going up over the time from that 8% up to even 10% all right so only one thing left to do now is update our readme we already have our uh third sql file in there and actually i need to make sure that it’s saved so i’m going to command s it and now when i go inside of here i can see that okay we have our entire sql file next thing is our readme i’m going close out of this and make this more viewable so what did i add to the readme first i attached the readme which is linked apparently not correctly and it looks like i spelled analysis wrong so always double check your spelling anyway when updating it now whenever i click on this it actually directs right to it so it’s always good to go through and actually click any different hyperlinks or links that you attach with this next thing i went in to do is attach a visualization this one i had generated by chai gbt just copied and pasted it in and it puts that graph in that we previously had from there i moved into the key findings talking about how our churn rate stabilized around 90% for the last 2 to 3 years and then studying the fact of that retention rates are consistently low 8 to 10% way less than what the industry normal is and then finally cap it off with that newer cohorts are showing similar churn directories and basically we need to take action now to start improving these churn rates so what can we do with this data well we can work in the future to basically target those within the first year or two to improve that active rate from churned we can also combine this with other analysis and re-engage not only our churn customers but also our highv value churn customers so we can be really specific with our targeting taking this a step further we could use this analysis in predicting future churn rates and how a customer may act that goes more into data science and machine learning we’re not going to go into that but it is something that we could take away from this analysis now that we have our third and final question done we now need to get into finalizing our readme packaging it all up and putting it on github and then finally sharing on linkedin which conveniently we doing in the next chapter with that i’ll see you there and we don’t have any more practice problems for the remainder of this course so congratulations to everybody that’s been doing those practice problems with that see you in the next one welcome to this final chapter where we’re now going to go into sharing our project and first of all i want to congratulate you for making it this far and getting through this entire project it’s been quite an accomplishment thus far now this chapter only has two short lessons the first lesson which this one right here is going to be about how we can create our github repo and then our next lesson will be in actually sharing this github repo onto platform like linkedin so dialing into this lesson we’re going to be focusing on two core technologies that you may or may not be familiar with the first is git git is a version control system similar to like track changes in microsoft word anyway it tracks our changes and you can install on your computer and use it to track changes within files we’ll go more into depth of this as we go through this video but we’re going to be using git to create a repo or repository and we’re going to be pushing it into github github is an online platform that allows you to share remote repositories and remote being you can access it from anywhere and what’s great about this is it allows us to then share our project so what are the steps we’re going to be going through in this video well first thing we need to do is actually clean up that readme after that we’re going to do a deeper dive if you’re unfamiliar with repos git and github we’ll do an explanation of all of this thirdly we’ll move into installing git on your computer and getting this repo set up for those then to put onto github and then we’ll in the fourth and final one we’ll be synced between the two and i’ll show you how you can manage it so if you’ve been keeping up with your readme so far with all of the different analysis that we’ve done since the beginning there’s not a lot that we need to do to update this specifically we need to fill in an overview business questions and then finally any strategic recommendations we have from this the overview i just have this one sentence of hey it’s analysis of customer behavior retention and lifetime value for e-commerce company to improve customer retention and maximize revenue for three questions we bucket them into these three that we’ve gone into inant detail on each one of these not going to rehash it feel free to pause this video now copy whatever you want off of it after this you should have that analysis approach that we’ve gone through after each one of the questions and actually updated it to include everything we need and then finally our strategic recommendations i went through and bucket these based on our three different questions and i’ve outlined a lot of the key tactics that we can take away from it within those questions so i’m not going to rehash it here again but i highly encourage you to brainstorm and think through what are some strategic recommendations that you would take and then from there put it into this section final and last sections on technical details i just have information on what technologies were used so people are aware that yes i use postgress for this and i use chatgbt for the visualizations so this is looking good i’m going to go ahead and press command s or control s to save it and now we can get into our next steps of initializing a repo or publishing to github but i want to just cover some background knowledge first so the first concept to understand is what is a repository or as i’ll call it going forward a repo this is a personal library for your project and basically allows you to keep manage and record every change to all your different files within it like i hinted to before it’s like track changes in excel except we’re using a version control system like git in order to manage these changes and thus we can go and revisit previous editions of it if we need to now in order to create this repo we need to use a technology like git git is a free and open-source distributed version control system and it’s designed everything from small to large projects i use it all the time for my version control we’ll be installing it here in a second so what exactly is going on and how is this becoming a git repository well here is the files that kelly and i are working together for to build this course and it has all our different lesson plans in it we actually used git for the version control for building this course anyway on the surface we can see that it just has some folders and some files in there nothing special but whenever i go to unhide the hidden files on a mac i can do that by pressing command shift period it shows that there is other files in here specifically this git folder orgget folder dot being at the front mean that the file is hidden that’s why you can’t see it that’s why i unhide it anyway this tracks all the different changes inside of here of what’s going on inside of my project we don’t even need to attach that or touch it in order to adj make any adjustments it does it automatically as we go through and make changes and update the git but i just wanted to show it so you understand what is going on there i’m actually going to go back and hide it so now that we understand that git is the version control system and is what is used to create a repository we understand that there are actually two types of main repositories one is a local repository and the second is a remote repository local is as suggested it’s local it’s stored on your computer what i just showed you right here is in fact a local repository because it’s local you don’t need any internet connection it’s super fast and you can do this and it’s very common to do this for your initial development now remote repositories are stored on a server they obviously because they’re on a server and not local you need internet but because they’re now in a remote location they allow you to collaborate with others so once again i have that that local repository here but also that same repo is on github and this is a remote repository and github allows me to work with kelly as a contributor for us to work back and forth on different files so frankly it’s more than just a version control system it’s also great at collaborating with others anyway this is now bringing us into github which is one of the most popular tools for using git specifically it allows you to store those git repos here and then share them with the world so by the end of this video we’ll be publishing your project to github so you can make it publicly accessible so if it’s not clear git is the version control system it maintains that local repo and it also has uh some different command line tools we can actually type into it we’re not going to go into that in the video that’s out of scope and it’s open source and free so that’s why we’re using it github hosts these repositories it’s located via web browser interface and we can access it remotely so that way we can also collaborate with others let’s now get into actually setting up this repo and sharing it with the world we’re going to go through four different steps first we need to install git if you don’t have it second we need to create the repo within our project folder third we need to set up a github profile if you don’t have one already and then finally the fourth step we’re going to actually share it to github so let’s see if we have git before installing it i’m going to open a terminal that’s going to be what you use on a mac and on windows you should have the terminal available or you can open up a command prompt inside of here all i’m going to type is get and then d- version and click enter in my case i do have it installed so it’s going to say what the version is i don’t need to install it on the machine now if it’s not installed you’re likely to get an error message and next we can now go through actually installing it so navigate to get.sem.com and from there you’re going to download for your appro appropriate uh operating system for windows machines you’re just going to be going through the setup for this most modern computers are 64-bit so you should be fine with installing this if you have a newer computer anyway it’s going to walk you through a guey just leave all the default values the same and click okay all the way through for mac they have a couple of different options for you to install and all of them are through that command line or that terminal my recommended option is through homebrew and if you don’t have homebrew not a big deal you go to this link up here and all you have to do to install homebrew is just copy this entire code here and then paste it in and actually run it i’m not going to run it because i have homebrew installed then after it’s installed all you need to do is copy this command of brew install git and execute that in the terminal you’ll have git installed now once you have it installed you need to verify is it in fact installed all we have to do is run git attack version and it should output the version there now some of y’all may get an error when running this it’s going to say something like this please tell me who you are and it gives you the instructions run this get config message in order to provide your email and your name all you got to do is copy it and then paste it into your terminal you need to actually go through though now and actually update things like your name to what actually your name is along with that email address above and then all you got to do is press enter you’re done now we need to move on to the next steps of creating our repo creating our profile and sharing to github conveniently these steps specifically steps two and four can actually be done together if i navigate to vs code specifically you go to this source control tab right here they have two options inside of your project itself you can either initialize the repository or publish to github but publish to github actually initializes the repository and then publishes to github the important thing though is you need a github profile before you click this so if you navigate over to github.com on the homepage right there it has a sign up for you to enter your email in and then go through the sign up process to create a github account once you have that account all set up then we can proceed forward so now i can go back into vs code and in here remember i’m going to do publish to github because it’s also going to initialize our repository at the same time i’m going to click publish to github it’s going to prompt me that hey the extension github wants to sign in using github i want to allow this i select my account that i want to be associated with and then i’m navigated back to vs code it asks me this first do i want to create a private or public repository i wanted to do a public repository the next thing this is very important you get this right in the first try it is select which files should be included in the repo i don’t care about this ds store any of these hidden files per se which hidden files are anything with a dot in the front of it i do want my sql files in there i don’t need that bookmarks folder that diagrams folder that scripts folder i do need my images because they have the images for my analysis you could if you want include the scripts i don’t really care about that that’s just like throwaway scripts i’m not maintaining that in version control okay i have in my case five files selected i’m going to go ahead and select okay it’s be going through publishing and it says that hey this was successfully published to my github now what i’m going to do is navigate back to github and go to my repository i can just get to my repository or get it to my profile by clicking the name in the top upand corner one thing to note if you haven’t done this already i recommend filling out any of the different social information along with your name and adding a picture to make it look like you have a legit profile anyway if i want to look at the repos myself i can go up here to repositories tab and it has this project which i titled intermediate sql project i can go ahead and click on it and includes that images folder which i click into it has all three of my images next is my git ignore which basically ignores all those different files that we said hey don’t import into git so that’s why it’s there and you didn’t see it before then our three sql files and finally our readme which we talked about before the readme is actually going to appear down below in this section and this has all of our analysis on this homepage this is really great that it is all there this is actually the url that i would want to share to other people to showcase my work now there’s one last core concept that i want to go over before we conclude this on github and that’s on how to actually sync your profile with github or sync your project with github as you go along let’s say that we do have a change inside of our readme file itself specifically i’m going to go under analysis tools and not only do i use postgress but i also use things like dber and pg admin okay so i have these new changes in here i’m going to go ahead and do command s and save it i can now see based on these changes that we have an m next to this this means that this file is now modified and underneath the version control i can see i have this notification here for one and it’s telling me that the readme is in fact modified now just to show i’m going to refresh this page real quick just to show if i scroll on down these tools are not present here but we want to get them updated on the technical details up here so what we need to do is stage as you can see this is underneath changes we need to stage these changes in our local repository we need to give a message of what we did here and i’ll say you can just leave it super short i’m going to say we updated tools and i’m going to click commit and it’s going to say hey there are no stage changes to commit would you like to stage all of your changes and commit them directly basically previously we’d have to go through staging all the changes and then committing them we’re going to basically combine this step together and so i’m going to click yes now these are still not up on github this is only committed locally to our repo so what we’re going to do is now push it to our github repo by clicking sync changes and it’s going to say hey this action will pull and push commits from origin main which is the version that we want to get updated to in our repo we’re going to click okay and also i don’t want to show this again so i’m going click okay don’t show again so now we can see we went here from first commit to now our second commit updated tools and if i navigate over to the readme refresh this page we can now see that it is now added to it so that was an example of pushing our changes we can also pull changes basically if there are changes in our remote repo like when me and kelly work together she pushes those changes up i want to pull those changes but we’re going to just implement a change in here and then uh pull it from there so what i’m going to do is i inside of github here i can actually edit this file oh and let me actually show you what i’m going to edit so these images i have them around 50% i’m going to update this one this one’s just too big i’m going to update it to 50% i’m going to click edit and then i’m going to go to the code now this is slightly this is html code that i’m using for this i’m using an image tag you don’t need to necessarily do that all you need to understand is that i want to update the percentage and this is actually the image for question number three i want question number two oh which isn’t in an image tag so what i can do is copy this code from down here put it down and this says image what from our source specifically i want this image right here from this source so i’ll put this in we want the alt tag or the name of it to be cohort analysis and then for the width 50% height auto i’m going to go ahead and do this by the way you don’t need to necessarily use this uh html formatting for image this is just sort of fancy dancy i’m using to get this 50% anyway now that we’ve done these changes in the readme i’m going to go ahead and go hey i want to commit changes for the commit message i’m actually going to change it to more descriptive to update second image size if you want to do an extended description you can and i want to commit directly to the main branch i’m going to go ahead and commit changes now scrolling on down in that readme i can see that we have that image formatted correctly so our remote repository is updated but if i actually view our readme from our local repository we can see the number three image is pretty small but the second image is pretty big and it’s still using that other sorry it’s using our just markdown format for having our images so going over to version control we want to pull these changes down from github so i’m going to select more actions and specifically pull and we can see down below underneath it we not only have first commit update tools we now we have update second image size and closing this out and looking at this we can see from this that all the image sizes are now formatted correctly and i have that updated code here so remember there’s two main concepts that we got went over here one is pushing the changes and this is sending our local repository changes up into our remote repository in github and then secondly we can pull changes if there are any changes on the remote repository i can then pull them down into my local repository and then my local repository can be up todate now that was just a brief intro into git and github if you’re new to this and you want additional resources on it i have an entire youtube video on it a link up above and you’ll be able to go through and see even more detail to understand the ins and outs of git all right in the next lesson we’re gonna now that we have this public repository on github we’re going to go forward with sharing it on linkedin so with that see you in the next one all right welcome to this very last lesson once again congratulations for finishing that project it’s now time to get into sharing that github repo onto linkedin and we’re also going to be going through how those that purchase the course perks can also upload their course certificate which you’re going to get after completing your end of course survey so let’s navigate on over to linkedin you should have a profile if you don’t i highly recommend that you create one this is where employers are at and this is where they’re checking your work anyway i’m here on my profile in here they have sections on and about featured activity but what i care about is this section here on licenses and certifications this is where we’re going to be uploading your course certificate remember you complete the end of course survey i’ll be emailing it to you you’ll not only get a link but you can also download the physical certificate as well now if you’re not seeing licenses and certifications you can actually come all the way up to the top click add profile section and underneath recommended you can click add licenses and certifications anyway let’s add that certificate to it by clicking this plus icon from there you’ll go through and fill this all in here i filled in with intermediate sql for data analytics put me as the issuing organization i have the uh issue date of march 2025 the certificate never expires so you don’t put an expiration date in there’s a credential it id located on the certificate so put that in along with the url underneath skills you can list up to five skills i’d recommend these of postgress sql git github and dbaver finally i also like including the image of the certificate itself so i select add media and then add media and then attach the file itself in there give it an appropriate title from there click apply all right once you have everything in there all you got to do is click save and it’s there the next thing you’ll do is actually update this project because we have our certificate but we also part of this course a project so underneath this project section i’m going to click the add icon from there i give it a name of intermediate sql sales analysis short description that i stole from our readme fill in the five core skills that were saying from that certificate next is the media and i like to include a link specifically a link to the github repo so what i’m going to do is just grab this url right here and copy it and then paste it right into here and then click add i’m liking everything that it has for this i’m going to go ahead and click apply now that we have our media in we can do our start date i started this bad boy making this back in october of 2024 and i just finished it this month in march of 2025 if you worked on with somebody like kelly mcklly so i could add her as a contributor and i can associate other projects i don’t have that okay now i’d go through and click save and my project’s going to be updated to my linkedin the last thing i’m going to recommend to do is sharing a social media post on linkedin or making a post if you will of this project completion to let everybody know that you’ve done this in it i’d call out that you completed the course and also did the project don’t forget to tag me and kelly in this as it’s super awesome i love going through this and being able to see all the different work and i can comment on it as well once again congratulations on all the work that you’ve put into completing this course and also this project what are the next steps well i have coming up shortly in the next few months we’ll be releasing an advanced sql for data analytics course which i’ll link somewhere on here that you can go and check it out if you’re interested in with that don’t forget to follow me on linkedin and smash that like button see you in the next one

    By Amjad Izhar
    Contact: amjad.izhar@gmail.com
    https://amjadizhar.blog

  • Russian Movie: Murders, Mysteries, and Mishaps

    Russian Movie: Murders, Mysteries, and Mishaps

    The provided Russian text appears to be a screenplay or transcript for a historical detective television series titled “Anna-DetectiveЪ, Season 2.” It includes dialogue and scene descriptions, hinting at multiple mysteries and interpersonal dramas unfolding in a 19th-century Russian setting. The excerpts introduce various characters, such as Anna, a detective, and involve investigations into crimes like murder and theft, alongside subplots of romance, social intrigue, and familial secrets. The fragmented nature suggests we are witnessing snippets of different episodes, showcasing a range of cases and character interactions within the season.

    Аннa-Детективъ Study Guide: Initial Investigations

    Аннa-Детективъ Study Guide

    Quiz:

    1. Describe the circumstances surrounding the duel mentioned in the excerpts. Who were the participants, and what was the outcome?
    2. What were some of the concerns expressed about the lack of crime and incidents in the town? How did some characters react to this lull?
    3. Detail the initial report regarding Ester Safyanov. What was the reason for her disappearance, and how was the situation resolved?
    4. What was Anton Andreevich doing all day, according to his conversation? Did he find what he was looking for, and what did the clues suggest?
    5. Describe the first crime scene investigated in detail. What were some of the unusual aspects or pieces of evidence found?
    6. What was the initial explanation given for Baroness von Berg’s death? What detail seemed to contradict this explanation at the first crime scene?
    7. Why did Anna Viktorovna initially believe the maid and Russia would “come to the tone”? What observation at the scene challenged this?
    8. What were some of the details surrounding the murder of Tipanova, the maid? Where was she found, and who was being questioned?
    9. Explain the significance of the letters Masha received. What did they reveal about her situation and the advice she was given?
    10. What were some of the unusual occurrences or discoveries related to the death of Anfisa, the maid at the restaurant owner’s?

    Answer Key:

    1. The duel involved an elderly French Viscount and a Russian student from commoners who were Parisian fans and had a disagreement. They shot each other in what was described as utter stupidity, but thankfully, both survived.
    2. Some characters expressed a feeling of losing their former “lightness” and worried about the lack of incidents and crimes, questioning why they had disappeared. Others, like one gentleman writing articles, were frustrated by the lack of worthwhile scandals and villainy to write about.
    3. The duty officer reported that Ester Safyanov ran away from home with the intention of a secret wedding. However, the following morning, when the young couple returned, her parents reconciled with them and gave their blessing.
    4. Anton Andreevich mentioned spending the entire day looking for someone who was missing. He did find the person, and the curious owner of a mask pointed towards the neighbors as being responsible, highlighting the common tendency to blame others.
    5. The first crime scene involved a woman with a slit throat found at a hotel. The door was locked from the inside, and while blood was present, it was in drops too far from the body and not a handprint, suggesting something unusual about how the crime occurred.
    6. The initial report indicated a woman with a slit throat was found in a hotel room. The fact that the door was locked from the inside contradicted a straightforward scenario of someone entering and committing the murder before leaving.
    7. Anna Viktorovna initially thought the maid and Russia would align because she believed the maid was the intended victim and that Russia would be involved. However, finding the revolver lying openly at the scene was noted as an interesting detail that potentially complicated this assumption.
    8. Tipanova, a 37-year-old maid, was brought to the monastery on a pilgrimage with her mistress, General Eliseeva’s widow, and was found to have been killed. General Eliseeva’s widow was being questioned in relation to her death.
    9. Masha received letters indicating that there were no decent grooms in the city and advising her to get married quickly to avoid scandal, especially given her profession as a doctor. She was also told that her literary works were highly valued.
    10. Anfisa was found murdered, and a piece of jewelry not belonging to her was discovered on the body, which the restaurant owner’s son claimed to have bought for her. There were also questions about the owner’s son’s whereabouts and his relationship with Anfisa.

    Essay Format Questions:

    1. Analyze the initial characterizations of Anna Viktorovna. What impression does the source material give of her abilities, personality, and role in the unfolding events? Support your answer with specific examples from the text.
    2. Explore the recurring themes of societal expectations and gossip within the provided excerpts. How do these forces influence the actions and concerns of the characters?
    3. Discuss the early mysteries presented in the text, such as the lack of crime, the duel, and the disappearance of Ester Safyanov. How do these seemingly disparate events contribute to the overall atmosphere and potential plot of the series?
    4. Examine the introduction of forensic details and investigative questions in the initial crime scene descriptions. What do these details suggest about the nature of the detective work that will be central to the series?
    5. Consider the various relationships hinted at in the excerpts, such as those between Anna Viktorovna and other characters, family dynamics, and romantic interests. How do these relationships contribute to the intrigue and complexity of the narrative?

    Glossary of Key Terms:

    • Детективъ (Detektiv): The old Russian spelling of “detective,” indicating the genre of the series.
    • Дуэль (Duel): A formal combat between two people using lethal weapons, often to settle a point of honor.
    • Губернатор (Governor): The chief executive of a Russian province or region.
    • Благотворительный комитет (Blagotvoritel’nyy komitet): A charity committee, an organization dedicated to philanthropic work.
    • Императорское человеколюбивое общество (Imperatorskoye chelovekolyubivoye obshchestvo): The Imperial Philanthropic Society, a major charitable organization in Imperial Russia.
    • Мещанка (Meshchanka): A woman belonging to the class of townspeople or commoners in pre-revolutionary Russia.
    • Следователь (Sledovatel’): An investigator, particularly in a legal or criminal context.
    • Уездный город (Uyezdnyy gorod): A district town, an administrative center of a smaller territorial unit within a province.
    • Фельдшер (Fel’dsher): A medical assistant or paramedic, often providing primary healthcare in rural areas.
    • Морг (Morg): A mortuary or morgue, a place where dead bodies are kept for identification or before burial.

    Zaton Investigations: Season Two

    This briefing document summarizes the main themes, ideas, and facts presented in the provided excerpts from “01.pdf.” The text appears to be a transcript or script from the second season of a Russian historical detective series, “Anna-Detective.” The excerpts jump between various scenes and conversations, making it necessary to synthesize the information into overarching themes and plot threads.

    Main Themes:

    • Investigation of Multiple Crimes: The central theme revolves around the investigation of several seemingly disparate crimes occurring in the town of Zaton. These include the murder of a maid (Tipanova), Baroness von Berg, and a young woman named Anfisa.
    • Intrigue and Suspicion: The atmosphere is thick with suspicion, with multiple characters appearing to have secrets, motives, and potential involvement in the various crimes. Misunderstandings, rumors, and hidden agendas contribute to the complexity.
    • Social Dynamics and Class Distinctions: The conversations reveal the social hierarchy and interactions between different classes, including nobility, merchants, doctors, servants, and commoners. Social expectations and scandals play a role in the unfolding events.
    • Relationships and Romantic Entanglements: Various forms of relationships – romantic, familial, and professional – are explored. Jealousy, betrayal, and the complexities of love and marriage feature prominently as potential motives for criminal actions.
    • The Supernatural and the Rational: While the series has a detective element rooted in logic and investigation, there are also hints of the supernatural or at least superstitious beliefs influencing the characters’ actions and interpretations of events (e.g., dreams, fortune-telling, mentions of spirits and curses).
    • Justice and the Pursuit of Truth: The detectives, particularly Anna Viktorovna, are driven by a desire to uncover the truth behind the crimes and bring the perpetrators to justice, despite the obstacles and deceptions they encounter.

    Most Important Ideas and Facts (Organized by unfolding plot threads):

    1. The Murder of the Maid (Tipanova) and Baroness von Berg:

    • A maid, Tipanova (37 years old), was found murdered, having been brought to the monastery on a pilgrimage with General Eliseeva’s widow.
    • A witness mentions seeing a “woman with slit throat found hotels nightmares.”
    • Another description of a body: “woman with slit throat found hotels nightmares iso da.”
    • Baroness von Berg was also murdered. Mr. Apraksin is a suspect in her murder and that of Aglaya Stepanova.
    • Evidence includes a fresh bullet wound on Apraksin and his presence at the Baroness’s house.
    • The door to the Baroness’s room was locked from the inside.
    • A “MGTS” (likely referring to a telephone line) is mentioned in connection with how the criminal might have left.
    • A thread or “Don lard” with a special knot was found behind the door.
    • Blood drops were found that were not handprints and were far from the body.
    • Anna Viktorovna and Anton Andreevich are investigating these murders.
    • Anton notes, “for several years now nothing is happening in the city, everything is quiet,” indicating a recent disruption of peace.
    • Anna states, “In the evening maybe we can sit and play chess remember our was her adventures Anton Andreevich, all this is in the past already.”
    • The spirit of Baroness von Berg is seemingly invoked for information: “spirit of Baroness von Berg and the whole world spirit Baroness von Berg me hotel semi I ask you speak out when did it come who killed you.”

    2. The Murder of Anfisa:

    • A young woman named Anfisa was murdered. Her body is in the morgue.
    • She was supposed to get married.
    • A coin was found in her boot, a tradition for wealth in marriage.
    • She was wearing a light dress and new boots.
    • The murder weapon has not been found.
    • The door was locked from the inside.
    • Evidence suggests the blood drops were not a handprint.
    • Several individuals are suspected in Anfisa’s murder:
    • Golubtsov Fedor: Mentioned in connection with jealousy as a motive. His son might have been involved with Anfisa.
    • Golubtsov’s son was away in the village with provisions on the night of the murder.
    • Golubtsov admits to buying jewelry for Anfisa.
    • Adamov: His revolver might have been used in the murder. Dr. Mills examined it and found it was recently fired.
    • Adamov suggested a date with Anfisa before her death.
    • Faisal (Peter Soloukhin): Confesses to killing Anfisa, driven by the belief that she was a witch who caused the deaths of his wife and son after predicting them through fortune-telling with cards. He used a silver bullet based on a mystical book.
    • He waited for the “right opportunity” and used Adamov’s temporarily left revolver.
    • He knew Anfisa would be in the park that evening because Fedor Golubtsov let it slip, and Vladimir (possibly Golubtsov’s son) boasted about it.
    • Anfisa was fortune-telling with cards for money, which made her unpopular with some people.
    • The murder occurred between 9 and 11 o’clock in the evening, according to Dr. Mints.
    • Silver bullets are identified as the murder weapon, cast from a fork from the restaurant owned by someone (possibly Adamov, given the revolver connection).

    3. Other Notable Events and Characters:

    • A Duel: A duel occurred between an elderly French Viscount and a Russian student over Parisian fans.
    • Elopement: Ester Safyanov ran away from home with the aim of a secret wedding but returned in the morning.
    • A Dog Thief: There’s a mention of a dog thief, with the reasoning that “he who today stole a calf tomorrow will steal bk.”
    • Ryabushinsky: A writer whose articles are discussed, including one about a duel and another potentially libellous one about Anna Mironova.
    • Anna Mironova: A character who has returned to Zaton after a long absence. Her return seems to coincide with the increase in criminal activity and is viewed with suspicion by some. She is also a writer for a ladies’ magazine and is knowledgeable about ancient Egypt.
    • Dmitry Aristarkhov: Arrested for the murder of Iraida Suslova, a participant in a terrorist faction. He initially refuses to cooperate but later confesses. He had made a mummy out of her body.
    • Pavel Martynov from Petersburg is involved in this case and seemingly dictates Aristarkhov’s confession.
    • Iraida Suslova: A member of a terrorist organization who was in hiding for seven years after an assassination attempt.
    • An Auction: An auction featuring Egyptian antiquities takes place, where a mummy is a key lot. This event intersects with the investigation of Dmitry Aristarkhov and Iraida Suslova. Mr. Golenishchev, a famous Egyptologist, attends.
    • Praskovya (a housekeeper): Reveals information about a past murder involving Andrey Chern and Tatyana, whose body was moved to the basement. This seems like a separate, older crime being uncovered.
    • Doctor Glebov: Deceased. His widow, Antonina Glebova, is a character in the narrative, and there are suggestions of foul play in his death, initially thought to be accidental.
    • Anastasia Petrovna: Involved in a complex situation involving her husband, a child named Sasha, and potentially a murder. There are hints that she might have killed Doctor Propane.
    • Yakov Platonovich: A judicial investigator and a recurring figure involved in the various investigations.

    Quotes Highlighting Key Ideas:

    • On the nature of Zaton: “for several years now nothing is happening in the city, everything is quiet” – This sets the stage for the disruption caused by the recent crimes.
    • On suspicion: “always at the neighbor’s cow the udder seems bigger” – Reflects the general atmosphere of suspicion and tendency to suspect others.
    • On the detective work: “reveal no more incidents there are no crimes, so why did it disappear?” – Shows the detectives grappling with the lack of obvious cases before the surge of murders.
    • On the supernatural: “spirit of Baroness von Berg and the whole world spirit Baroness von Berg me hotel semi I ask you speak out when did it come who killed you” – Demonstrates the intersection of the rational investigation with possible beliefs in the supernatural.
    • On motive (Anfisa’s murder): “jealousy is quite logical why not” – Highlights a common motive explored in the investigations.
    • On confession (Anfisa’s murder): “the witch only knows silver that wait for the right opportunity” – Reveals the killer’s motive and method based on superstitious beliefs.
    • On the past returning (Anna Mironova): “for many years we read you are dead and then suddenly you appear alive and well so please explain why didn’t you send a message or a letter telegram anything any message after all, you couldn’t help but understand how she deeply suffers” – Indicates the significant and perhaps disruptive nature of Anna Mironova’s return.
    • On the nature of truth: “believe what do I believe when they tell me the truth” – Underscores the difficulty in discerning truth amidst the many lies and secrets.

    Overall Impression:

    The excerpts provide a glimpse into a complex and engaging detective series set in 19th-century Russia. Multiple interconnected and seemingly separate crimes are being investigated, with a large cast of characters, each with their own secrets and potential connections to the events. Themes of social dynamics, relationships, and the interplay between rational investigation and superstitious beliefs create a rich and intriguing narrative landscape. The return of Anna Mironova and the unfolding details of the mummified Iraida Suslova add layers of mystery and intrigue to the already convoluted web of crimes.

    Anna-Detective Season 2: Themes and Case Insights

    Frequently Asked Questions: Themes and Ideas in “Anna-Detective” Season 2 (Excerpts)

    1. What kind of cases does Anna Viktorovna investigate in this season?

    Anna Viktorovna continues to engage in a variety of intriguing cases, ranging from apparent disappearances and sudden illnesses to outright murders. The excerpts hint at investigations involving a runaway bride, a dog thief, a mysterious duel, the death of a maid, the murder of a woman with a slit throat in a hotel, the poisoning of a doctor, and the suspicious deaths of a maidservant named Anfisa and a widow named Glebova. These cases often involve complex circumstances, hidden motives, and a colorful cast of characters within the Zatonsky setting.

    2. What is the nature of Anna Viktorovna’s relationship with Anton Andreevich?

    Anna and Anton maintain a close and collaborative relationship as they work together on their investigations. There is a clear sense of mutual respect for each other’s abilities, with Anton often seeking Anna’s insights and relying on her deductive skills. Their interactions suggest a deep-seated friendship, and while romantic undertones may have been present in the past, their focus in these excerpts appears to be primarily on solving crimes. They share information, discuss clues, and support each other in their endeavors.

    3. What are some of the social dynamics and concerns reflected in the excerpts?

    The excerpts offer glimpses into the social fabric of the time, revealing concerns about reputation, social standing, and morality. There are mentions of scandals, gossip, and the importance of public perception, particularly regarding women. The discussions about marriage, appropriate behavior for ladies, and the presence of “indecent grooms” highlight societal expectations. Additionally, the involvement of charitable societies and the reference to building a school for peasant children suggest an awareness of social welfare and philanthropy.

    4. How is the supernatural or the unusual intertwined with the investigations?

    While the series is described as a Russian detective series, there are recurring hints of the supernatural or at least the perception of it. Characters discuss dreams and their potential significance. There are references to curses, witchcraft, and the belief in spirits influencing events. In one instance, Anna is asked to communicate with the deceased. This interplay between rational investigation and potential supernatural elements adds a unique dimension to the narratives.

    5. What recurring motifs or clues are present across the different case snippets?

    Several recurring motifs and potential clues appear across the excerpts. Locked rooms are mentioned in multiple murder investigations, suggesting a possible element of deception or a specific method employed by the killer. Specific objects like revolvers, knives, and a piece of jewelry become focal points in different cases. Blood evidence, including its placement and type, is also scrutinized. Furthermore, the repeated mention of individuals lying or concealing information hints at the underlying secrets that drive the plots.

    6. How are themes of love, jealousy, and betrayal explored in these excerpts?

    Emotions like love, jealousy, and betrayal seem to fuel many of the conflicts and crimes depicted. The runaway bride eloping for a secret wedding, the duel fought over Parisian fans, and the suspicion of a husband killing his wife’s maid due to jealousy all point to the destructive power of these emotions. Betrayal is suggested in instances where characters are suspected of lying, concealing their whereabouts, or acting against the interests of others. These personal relationships and the emotions tied to them are often central to uncovering the truth behind the crimes.

    7. What role do other characters, besides Anna and Anton, play in the unfolding events?

    A diverse range of supporting characters contribute to the narratives. There are law enforcement officials like duty officers and inspectors, medical professionals like doctors and surgeons, and various individuals connected to the victims or suspected perpetrators. These characters provide information, become suspects, offer assistance, or create obstacles for Anna and Anton’s investigations. Their testimonies, secrets, and interactions are crucial in piecing together the truth in each case.

    8. What is the overall tone and atmosphere conveyed in these excerpts?

    The excerpts create a tone that is both engaging and suspenseful, typical of a detective series. There is a sense of intrigue and mystery surrounding each case, prompting the reader to want to know more. The dialogue is often brisk and informative, revealing clues and character dynamics. Despite the serious nature of the crimes, there are moments of social commentary and interpersonal drama, adding layers to the overall atmosphere of the series. The setting of Zatonsky appears to be a place where secrets and unexpected events are commonplace.

    Anna-Detective: Russian Historical Mystery Series, Season 2

    The source provided are excerpts from a Russian historical detective series titled “АННА-ДЕТЕКТИВЪ. 2 сезон” (Anna-Detective, Season 2). This immediately indicates that it is indeed a series, with at least two seasons. The genre is described as “Русский детектив” (Russian detective).

    The historical setting is suggested through various elements in the dialogue and descriptions:

    • Social conventions and titles: Characters address each other with formal titles like “Nikolaevich”, “Andreevich”, “Anna Viktorovna”, “General Eliseeva”, “Baroness von Berg”, “Mr. Apraksin”, “Madam Mironova”, and “Mr. Klyuev”. There are mentions of nobility and social events like balls and noble assemblies.
    • Professions and roles: The presence of a “duty officer”, “doctor”, “judicial investigator”, “navigator”, “gatekeeper”, “maid”, “clerk”, “police”, and “detective department” are indicative of the time period. The mention of a “telegraph” and “electricity” provides technological context.
    • Crimes and investigations: The excerpts are filled with discussions of various crimes, including:
    • A missing person.
    • Theft (dog, calf).
    • A duel.
    • A murder of a maid, Tipanova.
    • The murder of Baroness von Berg.
    • The murder of Anfisa Luzhina.
    • The suspicious death of Mrs. Glebova.
    • The case involving Dmitry Aristarkhov and a mummy.
    • Detective work: The characters engage in various aspects of detective work:
    • Questioning witnesses and suspects: Numerous dialogues involve characters asking questions, seeking information, and trying to uncover the truth.
    • Examining evidence and crime scenes: There are references to finding a revolver, bloodstains, a knife wound, a piece of jewelry, monastic clothing, and the state of a locked room. The investigation of Aristarkhov’s basement and the discovery of caustic soda and a hidden room suggest detailed crime scene analysis.
    • Developing theories and hypotheses: Characters propose different explanations for the crimes, such as the involvement of an evil spirit, jealousy, a desire to prevent a marriage, and secret missions.
    • Seeking expert opinions: The involvement of a doctor to examine bodies and wounds and an Egyptologist to analyze a mummy demonstrates the use of expert knowledge in the investigations.
    • Following leads and gathering information: Characters discuss going to different locations like hotels, monasteries, estates, taverns, and shops to pursue their investigations.

    Recurring characters and plot lines:

    • Anna Viktorovna: The title itself suggests she is a central character, likely the primary detective. Her interactions with other characters, involvement in multiple cases, and references to her “extraordinary gift” support this.
    • Anton Andreevich: He appears frequently in conversations with Anna Viktorovna and is referred to as a “judicial investigator” and her “assistant”, indicating a significant role in the detective work. Their dialogues often reveal their investigative process and past experiences.
    • Recurring cases: While several distinct crimes are mentioned, the excerpts often jump between different investigations, which is typical for an episodic series. However, the reference to “АННА-ДЕТЕКТИВЪ. 2 сезон” suggests that there might be overarching plotlines or character development across the seasons. The reappearance of characters like Yakov Platonovich and discussions about past events hint at continuity.
    • Personal relationships: The interactions between characters also suggest ongoing personal relationships and potential subplots, such as the dynamic between Anna Viktorovna and Anton Andreevich, and the various romantic entanglements and family issues that become part of the crime investigations.

    In summary, the source excerpts clearly depict a historical detective series, “Анна-детективъ,” set in Russia, likely in the late 19th century based on the social context and technology mentioned. The series follows various crime investigations conducted by characters like Anna Viktorovna and Anton Andreevich, showcasing elements of mystery, deduction, and interpersonal drama within a historical backdrop. The presence of “Season 2” and recurring characters confirms its status as a series.

    Mrs. Mitrofanov’s Missing Italian Greyhound

    Based on the sources, there is a mention of a missing Italian Greyhound belonging to a Mrs. Mitrofanov. The text indicates that “special signs” of the dog were being noted. Unfortunately, the excerpts do not provide any further details about when the dog went missing, the specific special signs, or whether the dog was eventually found.

    Duel in Paris: Viscount and Russian Student

    Based on the sources, there is a mention of a duel that occurred between a French Viscount and a Russian student. Here are the details provided in the excerpts:

    • The duel involved two individuals: an elderly French Viscount and a Russian student from commoners.
    • The reason for the duel was that the “Parisian fans something not shared”. The specifics of what they disagreed about are not mentioned.
    • The duel involved shooting at each other.
    • The narrator of this part of the conversation considered the duel to be “utter stupidity”.
    • It is mentioned that “Thank God the words are still alive”, implying that neither of the participants died in the duel.
    • A character was in the country and knew nothing about the duel and the lack of advances from someone for a week.
    • A Mr. Ryabushinsky apparently wrote about the duel, and a Mr. Mushinsky also commented on it, with someone feeling that Mushinsky “always makes a mountain out of a molehill”. This suggests the duel was a topic of some discussion or possibly even public interest.
    • Someone was angered by an article related to this and demanded that a “she” immediately returned home. It is unclear who “she” is and what her connection to the duel was.

    In summary, the sources detail a duel in Paris between an elderly French Viscount and a Russian student, stemming from a disagreement among Parisian fans. The duel was considered foolish, and thankfully, both participants survived. The event was written about by Ryabushinsky and commented on by Mushinsky, causing some level of reaction and a demand for someone’s return home.

    A Woman Doctor: Scandal and Skepticism

    Based on the sources, the idea of a woman being a doctor appears to be associated with scandal and is met with surprise and skepticism. Here’s a breakdown of the relevant information:

    • One character, Masha, identifies herself, followed by the remark “but a woman is a doctor, that’s just it some kind of scandal they follow quickly get married“. This suggests that a woman pursuing a medical career was considered unconventional and could lead to social scrutiny or pressure to marry quickly, possibly to avoid further scandal.
    • Another character explicitly states their old-fashioned view: “I humbly ask you to truchen I am a human being old-fashioned I can hardly imagine woman as a doctor“. This highlights the societal prejudice and the difficulty some people had in accepting women in the medical profession.
    • The presence of a female doctor seems to draw attention. When “Anna Viktorovna came for knowledge on the screen and the doctor there are people gathered what a people ah that’s what to hide“, it implies an unusual gathering or perhaps a sense of something hidden or extraordinary related to her presence as a doctor.
    • It is noted that Anna Viktorovna “studied medicine in paris with seal I admit it’s very rare to meet young amazing woman in russian provinces he really wanted this to change“. This confirms that female doctors were a rarity in the Russian provinces, which could contribute to the perception of it as something scandalous or at least noteworthy.
    • A misunderstanding occurs when someone refers to a woman as a doctor, and another character corrects them, saying “erase mistake it must be maids“. This mix-up indicates an assumption that women would more likely be maids than doctors, further illustrating the societal norms and the unexpected nature of a female doctor.

    In summary, the sources suggest that in the historical context of the series, a woman being a doctor was viewed as something unusual, potentially scandalous, and hard for some people to accept. It went against the prevailing societal expectations, where women were more commonly seen in roles like maids rather than in professional fields like medicine. The rarity of female doctors in the Russian provinces likely contributed to this perception.

    Ongoing Murder Investigations

    The sources contain several ongoing murder investigations, showcasing the detective work of characters like Anna Viktorovna and Anton Andreevich. Here’s a breakdown of the different cases discussed:

    • The Murder of Aglaya Stepanova and Baroness von Berg:
    • Victims: Aglaya Stepanova (a maid, 37 years old) and Baroness von Berg.
    • Initial Circumstances: Aglaya was found dead in the monastery, brought there on a pilgrimage with her mistress General Eliseeva’s widow. The gatekeeper heard noise at dawn on the second floor but found everything quiet. The maid didn’t answer, and the doors were broken down, with the body found inside a locked room. Baroness von Berg was found murdered after Anna Viktorovna visited her.
    • Suspected Cause of Death: Aglaya was stabbed to death, and it looked like she tried to draw something (a rooster) with blood before she died. Baroness von Berg was killed with a sharp cone-shaped knife, possibly a large icicle that melted, explaining the missing murder weapon. She also had a cut on her stomach, and her internal organs were extracted and dried, leading to theories involving Egyptian embalming techniques.
    • Potential Suspects and Leads:Ivan Apraksin: He is arrested as a suspect in both murders, with a suspected motive related to Baroness von Berg rejecting him. He had a fresh bullet wound, and the hostess confirmed he was coming in the morning for the second night in a row.
    • General Eliseeva’s Widow (Irina Alekseevna): She was questioned about Aglaya.
    • A young man (17 years old) living with Irina Alekseevna: He was questioned.
    • The clerk Matveyev: There is speculation that Aglaya might have revealed secrets to him.
    • Alexey (the clerk Matveyev): Believed by some to have killed Aglaya, possibly planting evidence.
    • Dmitry Aristarkhov: A student arrested in connection with Baroness von Berg’s murder due to the discovery of caustic soda in his basement and his knowledge of Egyptian embalming. The victim in his case was identified as Iraida Suslova, a participant in a terrorist faction.
    • Evidence and Clues:A drawing of a rooster in blood found near Aglaya’s body.
    • A revolver found under the bed, possibly used recently.
    • Monastic clothing found on a suspect.
    • Missing jewelry from Baroness von Berg’s residence.
    • A secret letter.
    • A piece of thread with a special knot found near Aglaya’s body.
    • Blood drops too far from Aglaya’s body to be from splattering.
    • The victim drawing a rooster head on the wall with her blood, possibly pointing to the killer or drawn by the killer.
    • The locked room and window latch at Aglaya’s murder scene.
    • The manner of Baroness von Berg’s death suggesting a non-metallic, cone-shaped weapon, later theorized to be an icicle.
    • The discovery of caustic soda and a hidden room in Dmitry Aristarkhov’s basement, along with a dried, mummified body.
    • A scar on Iraida Suslova’s body, mentioned in Ryabushinsky’s article.
    • The Murder of Anfisa Luzhina:
    • Victim: Anfisa Luzhina, a maid serving Mr. Klyuev.
    • Initial Circumstances: Found murdered.
    • Suspected Cause of Death: Shot with a revolver.
    • Potential Suspects and Leads:Mr. Golubtsov’s son (Fedka): A piece of jewelry belonging to Anfisa was found at his place, and he admitted to buying it from a jeweler and giving her some gold. He was supposed to have been at a tavern but his alibi was questioned.
    • Vladimir Gamov: Detained at the cemetery. He had a revolver, which he initially lied about having on the night of the murder. He had a motive as Anfisa was going to marry someone else (Raffia).
    • Fedor Golubtsov: Let slip that Anfisa would be in the park that evening.
    • Soloukhin (Peter): Confessed to killing Anfisa with a silver bullet because she had predicted his wife’s and son’s deaths and he believed she was a witch. The silver bullets were cast from forks from Golubtsov’s restaurant.
    • Evidence and Clues:A revolver.
    • Love letters signed by “Mazi” found in Anfisa’s room.
    • A coin found in Anfisa’s boot, a sign she was preparing to get married.
    • A piece of jewelry bought by Golubtsov’s son.
    • The murder weapon being silver bullets.
    • The Suspicious Death of Mrs. Glebova (Antonina Gleb):
    • Victim: Antonina Glebova, the widow of a doctor.
    • Initial Circumstances: Found dead, initially suspected as suicide.
    • Suspected Cause of Death: Killed violently by being hit on the head and thrown into a ravine.
    • Potential Suspects and Leads:Baranov (the coachman): Suspected of murder, possibly in connection with the death of his wife and the doctor. He was seen the day before her death.
    • Agafya (a maid): Tried to burn papers belonging to Doctor Glebov. She was pregnant and lost her child, blaming Antonina Glebova.
    • Evidence and Clues:An elongated hematoma found on the doctor’s body earlier in the spring.
    • Missing medical tools from the doctor’s office.
    • The discovery of Antonina Glebova’s body with a head injury.
    • Agafya’s attempt to burn papers.

    These cases illustrate the diverse nature of the murder investigations within the series, involving different motives, methods, and a range of suspects and clues that Anna Viktorovna and Anton Andreevich (among others) work to unravel. The recurring theme of societal issues, personal relationships, and the pursuit of justice is evident in these investigations.

    https://www.youtube.com/watch?v=V39uT-9K8A0
    ДОЛГОЖДАННОЕ ПРОДОЛЖЕНИЕ! ИСТОРИЧЕСКИЙ СЕРИАЛ. АННА-ДЕТЕКТИВЪ. 2 сезон. 1-8 Серии. Русский детектив.

    The Original Text

    A yes come in how did you sleep young lady, did you dream? what otherwise why did you ask, it’s Friday after all and a dream on Friday things I wish you good health, Nikolaevich, and not to you either. get sick from Andreevich something doesn’t add up at all seas today rest let me see and here they will dump something like this to ruin for sure Jack of diamonds goes to houses before thoughts lost their speed and did not say nikolai vasilich do you know I have the same feeling that we we just lose our former lightness reveal no more incidents there are no crimes, so why did it disappear? Italian Greyhound Mrs. Mitrofanov’s special signs here are like this all Unfortunately, the duty officer reported tonight came almost ester safyanov yes yes what ran away from home with the aim of a secret wedding Shumel direct figure out can I but In the morning when the young people returned it melted and blessed them in that case what will i do and rare get busy or else you’ll rub I’m sure you will if you can handle this matter, I will find it dog thief because he who today stole a calf tomorrow will steal bk I wonder who the artist is at all some famous matiz didn’t dare to talk about I don’t know, but for me his trait is much better tell me about the duel ok sasha so what tell here 2 and Parisian fans something not shared one elderly French Viscount another Russian student from commoners they shot each other, it was utter stupidity Thank God the words are still alive and what about her night I was in the country she knew nothing about the duel and none of them advances for a week but Ryabushinsky wrote You never know what this Mushinsky wrote the gentleman always makes a mountain out of a molehill I would have already turned white with rage when I counted his article and demanded that she immediately returned home arrested only six months left until the end of the courses I’m Masha, but a woman is a doctor, that’s just it some kind of scandal they follow quickly get married while i’m not a beauty public a message there are no decent grooms in the city order moreover she won’t hear anything doesn’t want to get married year so that Paris did not pass for lasdorf Anna Viktorovna I give you an excellent rating thank you, then it can be sewn Anna Viktorovna, they are waiting for you outside. ok natalia decks Well, I’m so glad to see you. I’m going to Moscow in po affairs imperial philanthropic society so I decided to make a stop in Zaton well how do you miss paris oh i do terrible besides mode for like me too Of course I missed it, now I’m used to it and then you know people seeing that help is needed at least paris zatonsky this is right this That’s right, but I see you’re healthy. the deceased are busy with a blanket and the rest the Lord has already managed for you office to you letter thank you kindly that I am stepping kindly towards you you will allow of course i love let announcement one lady sail to take care of her at in the yard tomorrow she will be zadonsk No, well, I must say what a story will have to stay a few more days on tar are full how kind you are we are ready to help in everything if it is indicated I’m not an angel at all, it’s just that good though somewhat delicate well how woman as mother i cant become a branch and I don’t want to listen to anything this person doesn’t guilty must be acquitted but baroness water the matter of clapping will require funds for keel problems don’t worry please I I’ll invite the best one what a stupid thing to save up for your eyes and what is good about you in me now Darling, this is smelling salts helmets type ac tell me what you have happened maybe I can help you help with something I have given moose part a thousand times asking for the word came to Petersburg answers according to laws it’s not surprising who you are talking about is busy storms yakov platonovich who are you have to Mauro is wider but you know it seems to me to you now 1 you can’t give up matilda torso and u I have very good connections at court. I’ll try to help you but what do you agree with? then we are great and you don’t need to cry Well my dear I won’t see you again such mike album not ideas i tomorrow I will organize a meeting of the local charity new committee and I will be happy if you you’ll come, but it’s a pleasure well then see you tomorrow A he should say that the dress is his sister’s I have great mercy for you, I shout at yours request when you will gain from the flesh or hats all bills for them be kind it came you don’t know uncle I’m not okay here you have many reasons to change hats and outfits you are taking advantage of the generosity of peter ivanych Annushka while I was playing his song did anyone give me no no in any way In this case, I will remain faithful to the memory of the divisions although in connection they say that I married for calculation however kazan so I was to her I didn’t write here that I’m really attached couple page love want read no ulm, of course I’m very glad that yours and literary works are highly valued in ladies magazine but sorry i have to work my opuses thank you very much, I don’t dare stop you listen and so what if not passionate desire and not such love in quiet moments and dream It seems like a woman’s heart and what do you want, he was met with little understanding maybe they have become hardened and mired in business or just club who are so late 60 lungs on the way to the forest broke down had to end up at the inn the main thing is that they came to collect the money and not to help we ate liberties didn’t save let’s go tomorrow morning you’ll wake us up and hurt us how beautiful thank you nature is awakening Spring is just around the corner, how are you, Anton? Andreevich I don’t count hours except for happy ones by the way you know you get bored more and more and the devil knows what I spend my detective money on abilities yesterday for example all day I was looking for the missing one and did you find the damage? you know, I must say, it turned out to be the curious owner of this mask is all pointed to the neighbors, they say, they sent except or well always at the neighbor’s cow the udder seems bigger and I personally think that If my neighbor’s wall is on fire, then that’s it. my business and what do you think stole the dog lovers and daughters then he then return and earn favor little one to his beloved later ask for her hand and heart as well obvious stories and you are not injured by the ear came to stitch up doctor news tried to you to us Anna Viktorovna, what are you doing today? In the evening maybe we can sit and play chess remember our was her adventures Anton Andreevich, all this is in the past already. the famous estimate and the work of the prince of darkness are one feels however however you are all right it’s in the past and thank God to look how good it seems for several years now nothing is happening in the city, everything is quiet and it’s just anton andreevich I barely found you, what happened Anton? Andreevich murder anna viktorovna i i am forced leave you for us crime party we are all good Chapter XII Why so early, well, they don’t say the bastard follows as if from a nail the guest was on the fence sticking out again I climbed into the monastery garden but not there on the map with wet apples old stand you have such a thing here, Reggie, and not go to someone else’s garden more often and pick apples have you heard, sister? and now but clearly woman with slit throat found hotels nightmares iso da where are you everything you have to do the most they victor mironov letter separately to hand over into one’s own hands to the cross from hotels on the front of the war he was not ordered say name I don’t know myself tall thin important we look today in the city I arrived, okay, go Hello Anna Victor Strange Nikolaev’s power sex and where is their doctor? Well, you yourself did it. new crime scene is completely correct I forgot, well, I’ll come back another time. I just can’t breathe in my chest in hospitals it is given to the shoulder blade I humbly ask you to truchen I am a human being old-fashioned I can hardly imagine woman as a doctor so you sleep as soon as he does appeared immediately after that in the chest and extreme embarrassment learned well that’s all it’s clear that it’s clear your nerves are like hell, Nikolaevich, you’re tender here you go, drink this now I still have a drop for you but still you Please go to the doctor in a few days we’ll see you alexander francevich thank you killed eye tipanova maid 37 years old brought to the monastery on a pilgrimage together with his mistress General Eliseeva’s widow was questioned in the light the gatekeeper heard at dawn noise on the second floor rose to check but everything was quiet in the morning she will come pilgrims the maid didn’t answer, the doors were broken down there they broke the corpse until the door was closed from the inside on the window latch too they opened in the city, rumors have already spread that there was an evil spirit involved here, well, he is evil spirit or good then we will figure out why the area is not cordoned off date wells of the project all left and and you I’ve been waiting here for half an hour already, what is this? you know that the killer is very often returns to the scene of the crime true-true what did he say alexander francevich wait we’ll be caught red-handed here He what are you doing, Victor? it’s not much easier anymore It’s amazing, this is modern science medicine all these new discoveries are simply amazing imagination genetics heredity hypnotism hygiene about 8 from whom glass of leash this morning axis to me came to the department with a new appointment sir navigator I almost got off my chair and services do you they didn’t say anything sir what are you doing here slowly raise your hands police immediately throw him up like that slowly or immediately you decide throw her cage I can’t important evidence what is he I welcome you from the speech leave the text again. why are you frozen like a ghost saw you alive and in the crisis la perla drowning or is it agreed to get fat tail no allowance and volume red to discharge alikhan phrase and you are not at all changed just as young and beautiful what kind of evidence did you find revolver one under the bed they shot from it perhaps quite recently with a pony navigator let me ask what yours are powers to investigate this case new appointment antonovich submitter all sir that on them fleet night is designated for the position of a judicial investigator in the city of Zadonsk satisfied gentlemen, you are already wonderful, then we are again together this event will definitely need to be mark but now let me get to it we will accept our responsibility of course extra where have you been all this time why haven’t you informed about themselves I think we will have more it’s time to talk about this, let’s talk now let’s take care of the girls, gentlemen what can i say judging by the character wounds and the depth of the wound, although of course none not suicide and definitely stabbed to death it looks like she was trying to draw I wonder why the rooster if it’s like this in this way she wanted to point to the killer was it easier to write the first or last name or the picture was drawn by the killer so that Now you asked me a question about leaving hotel through the front door it’s risky there the gatekeeper is sitting, I think the killers have escaped a thread through a hundred windows usually black ones are usually eaten from Monastic robes are sewn so cleverly No one ever pays attention to the blueberries attention for the average person they are all the same the face is also a hook and monastic in the vestments I confess I excluded I am glad that we we will work together again and I am not happy not at all happy for many years we read you are dead and then suddenly you appear alive and well so please explain why didn’t you send a message or a letter telegram anything any message after all, you couldn’t help but understand how she deeply suffers if they gave themselves know about each other Libyan reasons and let me not dedicate us to them as for my relationship with anri crani it doesn’t concern you, everything concerns you she’s thunder my friend she’s dear and a person close to me and you I’m glad to hear it I’m somehow more subtle, but at least a couple of words for my readers your mystery and not less than 5 years ago back to business so much amount now you simply have to give an explanation differently subject I’ll go gossip I’m not afraid to eat but if you insist on an explanation served in different cities of Russia was performed choose well have mercy here such an explanation is the same as nothing why do you see nothing else I’ll say it’s better if you tell me how it goes things are like platon of all flat he is worse nowhere for all five years not a single one worthwhile scandal and villainy to write there is absolutely no creation of the world start the investigation you try me I’m sure with your talents you can do it there too find the scoop This because of me letter you today there is no tower no from confident she and kind ones too I didn’t get any letters, no sir there is nothing school for you welcome soda how can i help i will rip this letter Masha Masha Masha it’s pointless listen to Talmyn in the city he received here is the appointment for a long time sooner or later they will meet anyway and we will be late he knows give it to me I’ll decide what to do by doing this you make yourself look like a boss families and in fact I will give you I don’t care about me or my daughter since I am not here, I will now enter it would you be constantly busy perhaps there is some sense in this Three months have passed already, there will be passion from the ladies whether following no one remembers yes you are right better to be in paris than with this mister what a hard time this has brought half first question as a criminal penetrated into Seville I think it’s quite obvious that he’s a killer I knew that the maid and Russia would come to the tone was already waiting for the victim here he could hide anywhere, even in in this closet and where did you find the revolver it was lying here open well that’s interesting interesting another as the criminal left the cell Locked from the inside, probably MGTS, please I was being tested it could be that any ways mass thread with with a special knot or Don lard here she is I found her right here behind door you didn’t even notice, something else is bothering me this blood is not a handprint and the drops and they are too far from the body well that is, the blood could not have splattered 5 far perhaps the maid shot in self-defense she came up in that case we had to find a field but she is nowhere to be found and there are no traces so there are bullets in the killer’s body here is the beginning of my mistress after death General this proxy to welcome the widow on young men scarves are for what kind of man what man young man beardless milk on lips not dried up 17 years old he cerato foundling decanter you say so I know how to cut it cockfighting big hunter irina Alekseevna gave him money and already I was scrolling through it there and a week ago she You refused him the house What do you think about the maid? writes how I’m also looking for Aglaida right away I wanted to figure out the owner first to form from since she lost her head a still in the head before death I drew a chicken head on the wall with blood from just a witch body to a killer from my pointer to Irina Lexina how long have you been serving? Stepanova was killed above, almost managed to do so you know how to get attached now it’s hard to find a good crooked no i don’t I know, tell me, have you already reported it? relatives of arus tonics they are not she was left very lonely all the time life in service rule and maybe some girlfriends or maybe heartfelt interest may God be with you my Aglaya was decent valley of all she already summer girlfriends you already there was no our house stands alone After my husband’s death, I rarely accept anyone yes, I myself very rarely you are not with anyone else was to bring down on friend not flu forest not you’ll find it, because I’m kind I’m ready for an official conversation allow me of course and who is this gentleman judicial navigator? investigator I am also handling this case where your to the maid revolver and revolver a Well, I kept this one just in case at home, well when we were already getting ready to leave she advised him to take the monastery with with her and put it in her bag what’s so strange here? Nothing your maid was a brave woman managed to shoot their attacker at her the criminal and did not put down the shot there is no I didn’t hear the shot, you see every night she took him down very much I’m fast asleep, come in madam and lucy his letter to you from Baroness von Berg as I will for memory pass on you are equal to self-change today In the evening I definitely visit my friends tell me can I bury the eye here in Zatonsky Personally, I don’t see any obstacles to this but you must understand that the body will be be kept in our morgue The local hospital has a long history of completion investigations and you Irina Alekseevna and I I would ask you to stay for a while in the city of course I moved to a hotel you will always find me there again a question on the wall in the cell was found drawing head you don’t know from what the head could draw her in front of she is not even really literate in death I couldn’t write my name why a rooster’s head Well, I see that you have achieved something. a lot, although there is no limit to perfection I am truly proud of Zatonsky branch of the imperial humane society of life gramercy duv indeco I dare not anymore detain Maxim Finns stay late my dear it was she who didn’t come I don’t even know, maybe I was late again hospitals but now she’s probably already Natalie’s at home, maybe mom, come to do us the honor I would be happy to be amal got soaked, couldn’t carry it away, not very good important meeting before dear monk please they will pass you on kiss my love with this chauffeur peterson come pick me up A yes driver you still don’t sleep souls with this something you look pale from more put became it’s always uneasy when you’re in this hospital coward only contagious you want talk to me about something, but anyway you don’t care where you are and where she is us father I you wonderful news filter after all, you have already announced your decision who’s here you will let them get stuck I’m in let’s go General and his elise I wrote that you need to go through yours madam Actually, I’ve been waiting for you for a long time please forgive me our meeting must was held in the morning but a tragic event will eat your miners poor woman, but I understand all the versions new your letter touched me so deeply me that I decided to stay in the city just for the sake of meeting you I humbly thank you then let’s not waste time of this kind as you may know can only be resolved in person participation of the sovereign I will help you compose correctly please believe me with atrazin tahtu when are you going to arrive Saint Petersburg Thank you Natalia floor but the thing is that soon I’m going abroad every year food my plans and intentions have changed Same they are standing here and we discussed it and she I decided to leave once or everyone has already forgotten them passions have subsided then you could go back to paris and finish your education what do you say Aren’t you happy? I’m glad yes I am I am about cities according to them it’s the same the best dog can be up to poland then It’s always good, thank God for that case I’ll arrange for the money and through you can have them in a few days, thank you, otherwise without somehow became legs nearby waited for this meeting I’ll crush it so now you won’t find anything that’s hot until no one judges us hand replacements avant-garde Goodbye what’s the reason it’s cold I’m so cold chat restored death is inevitable you are early hamster noble lady friend empresses find the killer do eat and I will make every effort not to they are shouting Kira is characterized by a policeman who heard one interesting in size A Natalia is full, how do you know? city ​​chatter hello one game on It’s a pity that we meet at such a time sad circumstances hello Mr. School You Electrum the matter is here Well, what about the doctor in Belarus personally? there is nothing special to please you with, a big wound on extensive blood loss in the neck I’m glad I took it on, I suffered for a long time I haven’t found the murder weapon yet will of careful examination I’ll probably say something else, I supposedly let me remove it take it What is this rooster head again They are already trying to convince us that the hole is ours drew her before she died do you think that it was the criminal who did it, of course you you don’t consider honor dying baroness I was drawing, but what happens? that one killer impersonates someone else strange things very strange never search crime weapon in room not found the door is locked from the inside again new in this In this case it was much more difficult to do this I can’t imagine how in the body at the head of the mind the criminal does it Well tell us how you are I met General Eliseeva I received a letter from him and she reported the same that she knew my relatives or something like that and I heard that you I’m an orphan and they don’t ask why it matters to me For the first time in my life someone took part in me example you were in a love affair with I’ll get a massage from him and all this is gossip carbolic gauze blood how do you do it explain anton andreevich what is this what is this what is abroad I don’t know take off your shirt why don’t you have the right to develop it Mr. Apraksin, you are under arrest. suspected of murdering Aglaya Stepanova and Baroness von Berg plot of his but tell me my dear what did you see mean how the meeting ended the baroness stayed at her place and then went to her some lady arrived what kind of house can you describe how no they are under the veil was there for about 20 minutes and then they went away what time was it so tulle net or so I am in the morning as usual the floor went up I look and the door is locked from the inside, the driver I think that’s why I called the police out of harm’s way further away Why didn’t you worry at night, you fool? the baroness does not come out fell asleep your the nobility of life so firmly dessole as if someone cast a spell on me look out for Yakubovich Anna Viktorovna didn’t see there went the beast probably drank himself dry, not a drop went into his mouth took inside the Moscow Ring Road or mouth is not idle we I overslept you Well, why did you ask for a loan, are you going to? waste my time experience my patience to remain silent I demand a lawyer yes that you are going to do something bad you’re naked as a falcon, you’re up to your ears in debts Irina Alekseevna pay her why? pay for you with what as far as i know she rejected you in the house a week ago and now when will I find out that you killed I certainly didn’t kill the maid and Aglaya and in what did they find monastic in you? clothing why the hostess confirms that You for the second night in a row you come in the morning devil fresh bullet wound Better confess yourself, Apraksin I ask you to admit at least who helped you remove the bullet you admit who didn’t kill who didn’t kill who are you talking about what’s wrong with you? No I knew gave that you are alive this was calculated by me and did not receive letters from I never reached out to him in that way my powers were credited you will never go I know what happened for some reason she didn’t let me know and could do it and red 25 years old so the opportunity arose and I did everything at once I found out that at that time we were in Paris and I thought that you were happy and maybe favorite and less often I studied medicine I needed to find new meaning when I I lost you and my gift but now I am me guessed about Chersky went after you again to see them means something, it’s important believe me, they don’t believe, that’s not important who brought you into the house of the spirit of women with with a slit throat she said peddler and now Ivan Apraksin is interrogating, but not his friend not earlier and a lover of stewed a.f. think oklo you were talking about him who is yours establishment we feed cattle how often can here and there would be a party on Sundays so yesterday ivan apraksin was there too came how long rights on the 2nd went jumped I sympathize and who will you be with him police confirm 4 I tried to stick my finger in here and that’s all that’s exactly your gift said quite von berg from and forest and you and What is this so that means you caught him well thank god now we will have time to bury online i mind I don’t understand why recover wished for death your maid has never eaten it I liked her and tried to get me warn I was blind to know he is sitting in the cell he just begs to meet you No, I don’t want to see him, I don’t want him never to see again he was wasting everything money that was given a week ago it was created that the blog should I refused pay when he got angry threaten me and only after Aglaya came and pointed at him the revolver went out of business and I don’t understand you in something to suspect family no no what are you no way I thank you for I have time for it, it’s time for me oh yeah yesterday late evening you accidentally have not been to Baroness von Berg yes I have been I have some relation where after we believe that she was killed after your departure it’s the same apraxin no notifications the jewelry was missing from its place but here it is the letter that you wrote she disappeared bradisa returned to me at my own request I hope I burned it in front of you and what was in it tell me it’s not yours anymore case Mr. Korobeynikov, I beg your pardon parts of me I have no idea It turns out that Apraksina has an alibi last night but no one can confirm comes out that morning I’m for you now we know for sure that he is not Aramis killed although he was guilty of the first murder what if the general’s wife herself is involved eliseeva how did she leave at 11 also confirms she could come back go through the back door it seems to me that would develop and would not return both letters and that’s why the general came that evening take it in this letter secret me earlier still in the city tomorrow Aglaya is being buried and if we have a suspicion we should to get evidence before she leaves you need to go they looked at the estate secret secret secret such she realized maybe we can find some documents but if we are lucky a person in this case, you need to leave the letters immediately the path is not short yak Platonovich gentlemen, I’m coming with us, she’s Victor You can’t imagine how happy I am about this all ends good old times duty Prepare the carriage, you are the doctor Nilson won’t give us a dressing down for that so that two of you would be stolen from him terminus give me half an hour with him I’ll agree One day Natalia Polna saved me I can’t let her killer I’m still on the weak side, hurry up, my dear. yax fruity strangest early which I had to or throughout your entire practice you understand and it is clear that the blow was delivered very large force but the warriors did not gain but it’s something very similar to a stake Doctor, go on, you said wooden. the stake is definitely not wooden non-metallic it is not difficult to say yet what material was it made of tomorrow the body will be taken to Petersburg I suppose you want to say goodbye I won’t bother you doctor if you ask you could say that yes night I was on duty at the hospital Let’s yes, a private house search is good I allow it without attracting attention but solely due to the importance of the matter I expect in essence you know I all the time I’m thinking about this matter, well, let’s go let’s think about some monster killed the ram with his legs, what is this whole circus about closed door from the inside with this picture rooster blood well, in order to blame apraksin I admit it doesn’t give me peace either especially the guard who fell asleep as if by accident your team has no hypothesis Well, go ahead and leave the city. unnoticed that no one saw you spirit of Baroness von Berg and the whole world spirit Baroness von Berg me hotel semi I ask you speak out when did it come who killed you where was a real angel for everyone Mrs. von Berg, the poor, became an angel for all choose sinners Russia for God’s sake maha what sinners what a tax collector and you will buy this already the first option a seems much better to me more sublime you’re leaving again, I’ll go to the bank I will arrange for monthly payments for ours we are leaving for Paris see you in the evening my friend the navigator is waiting for us at the exit from the city you came to the station together did you talk to him? did you really talk to him? forgiven search why do you think Anton Andreevich, I’ll go there myself I’ll talk to the devil while I’m killing Natalia Polunina or another here here dear to me before the clerk of Zatonsky so only at home cook the military personnel returned the tower to their old ones expected you are mistaken, I am not your lady, forgive me Ladies, I have weak eyes, forgive me We have orders from the police look there with the muscle police irina Alekseevna what am I no don’t worry Your Irina Alekseevna is alive and well will be back soon let me in please show me what such and such police in the evening and I’m all alone in the house, nothing to do worry simple check we something happened, maybe something did happen such happiness in the steppes of Matveyev our clerk hasn’t said anything about this yet I can say please make some tea I listen to the courts which speech find the maid’s room she herself Viktorovny let’s see Bekov’s fault Plato let me remind you that I’m now simply in charge of the investigation forgot myself what will be the orders, very simple look for the maid’s rooms and we’ll do it ourselves amber we are exploring the office please maids’ rooms are usually located in on the first floor and try not to make noise nothing suspicious mortgages are no personal letters passports in the name of Eliseeva Irina Alekseevna and Stepan Petrovich Matveeva I’ll show the clerk leaves that she assembled with quality for abroad brought wonderful and how cute are you you manage all this and cook when you can hardly see anything, is it difficult for you? ball and from all life and the stove stood I don’t recognize all the products, thanks to Irina Alekseevna that you didn’t kick me out when my eyes grew weak then they started preparing a shower good like this doctor three ports I will never go to those doctors he could have had such horrors with Stepa these doctors said there is no urine tell me Aglaya and Stepan got along well, ink and go you are young, well, go ahead this is the story of victor on maid he’s messing around with the clerk and the hostess is going abroad with him and when it no longer appears earlier new object of passion young apraksin then the maid instead for some reason the hostess is in a happy mood countries are really against him Women are very difficult to understand Anna Viktorovna she is vikram V Baby Ivan Apraksin and it’s about a Finn found avoided judging by these documents and his fox sent money monthly with apraksin will everything came back to her I am returning everything that is mine his movable and immovable property narco chopra xenu born january 3 1800 composition about the conclusion I studied biographies not before and the general was at war for a year or more in Turkish it turns out that and curses they lovers whether gray and her son not a marriageable son Now it’s clear why she didn’t immediately pointed at him didn’t want to believe 4 son murderer You know what I think, General’s wife had to sheep feinberg to find out about the possibility of recognizing a child officially natalie full often provided help in such matters of course she I told you as a woman and as a mother I don’t I dare to refuse, but why does she need this? recognition if if she already bequeathed all to her son after death so that she the son belonged to the nobility the baroness clearly kept this secret and Apraksin didn’t know anything about this Aglaya I knew why you think that she brought me here led him to knew the hiding place but who was it killed and the baroness who was afraid that the secret it will open, let’s assume that it is the clerk Aglaya could have blabbed him the secrets earlier on 3 could kill her baroness and then put all the blame on professional and after that calmly console irina alekseevna somewhere on french riviera we need to find out urgently when in for thin this Matveyev was driving and their fleet started looking for him our maid to the book is correct food is your thing anna Viktorovna self-study french all books with notes in the margins it’s strange isn’t it I said earlier that I was globalizing illiterately It’s not clear why she hid it so what else is strange about this gentlemen There is not a single portrait in the house Certainly when will your boss come I can’t know and who knows you would after lunch if they came in then they will definitely be there no I I’ll wait for this gentleman, I didn’t demand it has the right to keep an innocent person in the company man and who are you I arrested innocent madam ivanov roxy i’m afraid you’re wrong madam Apraksin committed a serious crime could he do something for you why because on the night of the murder he was shooting with water or with my husband and was injured shoulders and that the husband can confirm this husband no I brought seconds with me and they are ready to testify under oath well Well, let’s go to my office instead of all the storm to the lord go through expand the dust whether I to the fleet they gave you a note, thank you break out without knocking me here see what patient sorry doctor this is an extremely important matter Doctor, you said that Baroness von Berg was killed with a sharp cone-shaped knife subject but you couldn’t understand from what material was it made of meters I am convinced she was killed and the house it was a huge icicle that’s why they didn’t find the murder weapon simply melted beat possibly but the man who made such a blow to the norn possess do not hold strength strong men I can do this in principle RF later I very much believe so, probably then he did the same thing, he put the animals under a piece got dirty when I installed the Tatra what does Anna’s country say? look who we have today Saveliy you find out she’s a liter well how come your hand doesn’t hurt mouse mullet on so clean well here more you will not invest in the monastery garden somehow you also make a living in the monastery garden then I was there last time on Saturday dawn I’ll be there today and what happened to her running out out of the window and after me I ran step by step fence and I’ll hurt myself with a nail what’s being built you didn’t say minister will you be able to find out this person antenna speech and at what where Felicia left in I say keep on his funeral service and we’ll take well what else he immediately draws on the night of the murder he fought a duel and has a wound on his shoulder followed me and not before see my dear soon follow them and listen quickly to the wal and Here you can close the front page anyway they let me go, I’m innocent, Aglaya What it’s him who’s gone crazy Aglaya the maid did not recognize the lady with you We’ll talk about who’s in the coffin later Irina Alekseevna weight on take these two lived everyone stands please raise even if he gets caught anyway it will be worse come on, get in where are we going as far as our eyes can see or you Do you think I’ll go to hard labor because of this? This baroness also knew that the general’s wife and send a letter and set up a meeting asked once for calculation early or late beyond the borders you could meet someone who long small earlier god won’t give out the pig won’t eat what is this why store sits there tied up plug stand still and don’t move listen to my voice they will come soon we have a couple minutes who are you do you still recognize me tell me how they killed your friend as soon as they closed the door outside That’s right, she told you yes then your gift has returned you killed her no one will know the clerk is dead he will hang on him I will know you will forget everything sleep and we have been for a long time she played she flew she is not a Koran where he lived and your honor found she is vicarious what is wrong with you screen ogre wake up what happened here she said that he doesn’t want to go to hard labor what a joy what a joy that you are whole forever equal matter clear your honor first he shot the lover and then myself oh yes yes on That’s why . the criminal was convinced that it is illiterate and she herself read books and cooked villainy who doesn’t go there these days the service is all mixed up swarm you look and Don’t you understand, there is a noble lady in front of you or a maid to the river spinning in times have changed it was aglaya who killed her ren we believe that alexey did it the clerk Matveyev identified him as a boy witness also wounds from a bullet in the hand in exactly like yours and the monk’s robe It was probably him who planted it Aglaya will make a drawing on the wall, I replaced it clothes in the closet with the help of women’s hairpin and lowered the latch on doors but she didn’t know that Matveyev was wounded that’s why I don’t open the revolver I noticed, but how could she not have heard? shots During the Easter service the bells rang Yes Baroness why was it necessary and why did you weave Aglaya went to kill the baroness to pick up the letter generations of russia you but i think natalie I immediately realized that she was an impostor that’s why aglai ordered matveyev to be killed or why did he do it in such a sadistic way with the help of ice and other criminals like shake the imagination of the police excitement you Mr. Apraksin as a lover fights you should know this, stop with it sir, although your mother gave you to education but before death provided your future my mother andreyk upstairs I wanted to tell you I want to play The role of the lost baroness cannot be returned criminals and paid for everything I thank you for helping them found and started to thank creatures as always, nothing would have happened without you and I’m tired I’ll go we haven’t really talked to each other many of them brought me their apologies I accepted I see that everything that we have with you connected remained in the past and is not necessary I know you are rushing this gave birth to other words from me again I you went against honor and conscience if said aslan yes indeed it took too long to arrive time I don’t care about the hood I need to be seen off A I’m good ok i’m ok on one side A the master still has coffee, although although before good morning young lady no fight in the woods Do you care, uncle, that one is in such a early I’m going to St. Petersburg and the deferred money is going to I don’t know for a long time if you would visit me capital don’t you think from the guest rooms all empty almost them and changed his mind fracture is it because of something you know, every night I dream about the same thing same dream here he is in prison and calls me for a while rumors that he was under investigation Do you know anything about this, I don’t? In general, all this is just rumors nothing confirmed if something you you will definitely find out on the same day you will tell me swear I swear give you a ride to the hospital but I don’t dare to accept such a proposal refuse who is this here someone we just need to notify Korobeynikov marry dear and obviously close distances but he definitely doesn’t have a parade, I suppose came instantly judging by the traces The victim was killed in the alley and then dragged away. the enemy is by the way a camp and after all there in I can stay in the lowland body for a long time unnoticed oh my god high where are the good ones my respects and then I wish you health Anna Viktorovna said to discover yes that’s true and I already asked her gentlemen I am with With your permission I will go for the orderlies The identity of the murdered woman has been established, but there is no location yet found a body Not far from Myron’s house there are new and to another Razumovsky exactly as . This already nobody beak bought a house a couple of months ago back who is a landowner without any special occupation quite rich recently returned from I haven’t met him yet on the city’s borders probably doing some landscaping curiously expensive thing would not become robbery we found something else this photo night she had I had this in my pocket I’m waiting at ten yours until the grave looks like it was going to dates path where it was murder committed goes to the house from they have a brownie son there, a rascal and a gambler And weak to the female sex but only if she didn’t serve Miron no no didn’t serve so most likely he served the master klyueva or about brownies I’ll go beak you take care of the brownies and don’t please don’t worry, I’ll find something to do to do but after all someone is with you I should do it if you don’t mind see you at the police station Sorry to interrupt your breakfast Lord of Blood but the matter is urgent police Yes, they reported to me where she left for and why . poor investigator tell me who else Besides you, there are also crushers living in this house maid lucky I can do this as her maid in general and Elisha, first of all, please explain to me there was a murder here please invite your maid here immediately otherwise I will call I’ll send a police squad and order a search of the house everyday not at home she should have serve me breakfast somewhere disappeared tell me is this familiar to you thing for this and her pendant the keys of our anfisu you shot last night in the park not far from here you said her name was Anfisa Anfisa dinner body is in the morgue You still need to be in the hospital to come there for knowledge yes of course where they remember her and I need to search, please I wonder where the maid got this from expensive jewelry and I also asked her question She replied that Clooney and the suitor gave it to her merchant’s son I didn’t specify which merchant, no, I didn’t go into it in detail You yourself didn’t come from these places from abroad decided to settle here why zadonsk glorious town anfisa I hired her right away for hair care I arrived two months ago she came from village father died mother is alive well what letter and pendant to her winter and about you I’ll ask you to wipe the room and not anyone Don’t let anyone in here without my permission you still have a question, the girls say there was very pretty yes handsome I can foresee the next question I didn’t have an affair with him, why? what a strange question sir what a very reasonable question, do you live alone? as i see the maid is not beautiful When I’m married I don’t have the habit of having sex dalliances with maids known to you the fate of the previous the owner of the house raivis but he was killed a this is relevant I guess not, I investigated what I do about it murder, that’s how it is, well, there are more questions no all good what hurts so much it shoots we are still only night I didn’t sleep, maybe the car is burying me you have a nice inflammation and you caught a cold probably, and so I’ll treat you with myself too I’ll give you some medicine and you’ll wash it at home Understood husband 11 sister and husband would poison herself holy water go deaf you want all the disease of sins from corruption and evil eye of a written contract A what’s wrong with you killed innocently who should I judge innocent help me it’s not long let’s go to the couch drunk since last night talk to him now firm that samson but there is more sense in a writer Your son wrote this note, let me I’ll take a look yes it is his hand as you can see here invitation to a date how let’s see who it can be addressed to for what? Volodya is not married and has hobbies excuse me, can I have some water and of course some cars scriptwriter revolver no optimus firmware there was a path to your house body of young woman found murdered shot from a revolver where your son was last night like where in the tavern when did you leave when did you return left at 10 returned by morning clear I hope by evening he will sleep it off, thank you, I’m not saying goodbye Anfisa Luzhina was killed and served as a maid in in the house of Mr. Klyuev he recognized her things and house keys Today he will come to the hospital for examination inflate, there can be no mistakes klyuev klyuev is what I bought at home where xii Razumovsky on it I told him that this house is cursed and that father is nothing didn’t say where the maid got it from expensive pendant says that some merchant gave in the room van fiz found letters of love signed by a certain mazi to us this is a baker and bodily younger or older and so that houses hammer to drunkenness yesterday Mom can’t pronounce it but sand note in his hand parents confirmed, well, here’s the real deal she opened up and began to walk towards him and he her motive is drunk and bad, that’s the motive I wouldn’t rush to conclusions Nikolai connection needs to be checked mazina Anton Andreevich, you take it upon yourself it’s hard to go to him otherwise after when we will be performed by Yakov Platonovich However, I ask you not to forget that now the head of the detective department I am well, I always remember and hope for comprehensive assistance from Andrey in parts gentlemen and have mercy Anton Andreevich, no one has a place with you takes away thank you humbly Anna Viktorovna came for knowledge on the screen and the doctor there are people gathered what a people ah that’s what to hide and necessary to find additional evidence that will help you find the criminal well plus the vector to see it order the doctor introduce me your assistant Andrey Petrovich cool please love and favor Anna Viktorovna Mironova Mironova so I must be your neighbor I’ve been with you for a long time I had to pay you a visit so that we still have things to do before we clap We are glad to see you at any time thank you so you are a sister of mercy well what is Anna Viktorovna my irreplaceable assistant will be rolled up right hand by the way medicine studied in paris with seal I admit it’s very rare to meet young amazing woman in russian provinces he really wanted this to change I would like to continue our conversation Do you mind if I walk you there? I have unfinished business at the hospital sorry this will take time i will let’s go good afternoon served what would you like day Kind forensic investigator navigators to you This decoration looks familiar let’s put what does it mean let’s put is familiar or no put a sign listen to her Fedor acquired the fool do you know where you can find a restaurant like this on the corner dogs on the main street and the son to the father helps in the restaurant and thanks so you study paris i also study a lot time spent abroad don’t be bored Zatonsky it’s not that important if people have children they need help they want protection and then you know our life is Zatonsky Only from the outside do I seem calm I think your maids are scary steel drunk girl yesterday i was Full of life today lies already lifeless on the prosector sculptor but not there was a brand new pair of shoes from one a coin fell out of a boot, so it’s mine Anfisa was getting ready to get married why this mother well because puts a coin under his heel so that his family’s life was rich and the new one is better the bride buys so usually well of course of course you are right and Her dress was light, but it was still the body itself has not arrived Andrey Petrovich I’m sorry I have to leave you now. Well. I wrote to Anfisa so what if I write what it means to many I love this business, what business, well, letters write about feelings where were you yesterday between 9 and 11 at the bakery I put the morning dart in 2 of ours the bakers were with me you can go to them ask so it’s clear that you write to different girls, right? He who follows his passions will perish that the bones will break that’s what the electron is and stick in bun kindly be so kind that it happened that night he wrote about the wife was collecting competencies from someone there was a light dress, a new pair of boots and She put the coin under her heel and the wealth of cubatan that thank ana victor no no no how did you manage to do it all here you know, Antonovich was just sorting things out their morgue or did she appear to you was afraid that he would judge an innocent person I ate enough for a liter, please, if you can You will definitely find out something else from me let me know reported but he told them for three parts of life delicious colors certainly good afternoon wish this have lunch wish I had a talk with Mr. Golubtsov Very and now you are not with the elder please wait Mr. Golubtsov we give them storms judicial investigator Well, I don’t remember you recently. assumed duties OK, so what brought you to the restaurant? sit down the murdered Anfisa was already on your son I would like to talk to her about the relationship Luzhina never heard served and maids in espada sticking my son not runs around the maids minute on the body killed I found a piece of jewelry and bought it from a jeweler told her he won’t ask her, he’s not worth it and he gave her a little gold so that it’s not hard to say what the order says Not a single man could calmly treat me she passed by as if she was struck and where was your son last night? I know, but now he is not here, he has left for the village with provisions yes, don’t think that he killed him and soft Fedka is not like that, why does he need it tell your son what he needs show up at the police station and give indications as soon as mts near the city anfisa and dinner and consisted of an appeal in relations to any All my life I’ve needed more than just money this says to sing candy fools and loved ouzo sniffed services I’ll start what for I would love you, here’s the note you wrote note yes I thought agreed it gets worse at ten o’clock in the evening I’m now waited and then went to the grief tavern he was scared to wash down his food, she secretly wanted to get married, bite, I don’t know everything the question was said, I swore to remain silent the dump will be eaten and you will oppress but it is not yours don’t meddle in the matter, there was a revolver lowered back lost in the tavern fools how everything is so neat and you have a revolver lost to a rival from the city and went nowhere We will check everything carefully before leaving country I couldn’t eat it the streams I couldn’t understand this procedural violation nikolai vasin was give body without opening it up here is such a thing their Platon well a whole crowd gathered, almost a riot the priest came and asked the mother, this was crying but you understand that now we are not we will be able to determine what kind of weapons did they shoot from? have mercy I am Plato what should I do here simple no lover so another Nikolay sat down Yakov Platonovich as the local police chief the management gave the order to avoid popular unrest you this share drift why didn’t you resist you are the head of the detective department Yakov Platonovich Platonov why are you taking on this trouble? some inspector auditor Yes, you dictate your will to us and I will allow it remind yourself that the police are obliged take into account the local realities that you probably forgotten during our time mysterious absence of the Lord pure Yes, you’re a weakling, I knew you could do that. I ask for forgiveness colossi not me you tell what He who knows how to control his anger will certainly he will live to old age but you see for yourself the situation is out of the ordinary I don’t understand where he is there were all these loops and why did you come back and fix everything in the same way abilities connections you know in his character yes but he thinks that there is someone here he’s hiding something here secret secret and what secret let me know I believe that he was sent to Zadonsk from some kind of secret mission and what kind of secret missions may be in our town what images do you remember which were woven intrigue five years ago that’s exactly it, i’m sure that yakov platon already It is not by chance that 2 is given here that style is it really didn’t work out very well fleet of rights my dear I ask you how as quickly as possible investigate this case who rus efforts i I rely on you these why did they come to the work of their hands look and shut up my mouth no shut up look at him look here he is the killers came to have fun, what envied he ambushed and killed our happiness you killed changed his mind, the little one got scared and that’s it police arrested a man for fighting with you brought it to me even though my little fingers and I don’t I know, oh yeah, fear God, Euphrosyne, why? your daughter was better than others for not the same and there were some sins, yes, if I I did something so wrong with my pisco I really didn’t give them the right answer before they lived says to accept the cliffs of heartless 1 manage no, then listen, he will sign this one ryabushinsky did not have time ordinary people recover from the murder of their general elisha you baroness von berg so new scary death shocked everyone anfisa was shot puddle to share dubious reputation and mysterious to occupy sinister ones again fell on the launch of the ominous shadow here about you are there Are these streams of misfortune connected with the fact that our launch returned mountain sorceress anna mironova and from what no I will definitely answer him there is a gentleman in our column he is still they will dance all this came from a letter from a neighbor Klyuev and I of course responded to his invitation for dinner tomorrow what a nice young man we have today met him I’m very glad that something new is starting acquaintance you need to be in society more have fun she where are you looking I’m tired and beaming I’ll go don’t go away, I need you, I said leave and afanasia klochkova’s shops wanted bases afanasia’s shops galochka in something someone asked and me no and how are you feeling mom ok why are you asking yet good night good night okay up to her old tricks again ran through the forest with the police your maya was against it but I don’t think it’s possible to interfere in cherri bat ours this is for you she and Anna Viktorovna will be found possible hate gram or you have long I was forgotten in that case I am with I will humbly accept the poison and never again I won’t disturb you I acted dishonestly, one thing was put into that night and at least there were reasons for that from me beyond my control I know that I cannot be forgiven hang up with all these five years there was no day not a second when trends thought in asv I didn’t dream of it, she’s the same meeting A A It was you who was detained at the cemetery last night Vladimir Gamov good trental speech to I and don’t you think that this is somehow on what basis is the basis greater than Mr. de Armas caught enough possibilities motive for murder all folded according to him and he has a revolver I had this I read in your report he lost the revolver about the figure of people not destroy for what he was not guilty he is now we let’s deal with the revolver, it’s hot your son also had the opportunity to motivate murders what was his motive jealousy raffia was going to marry someone else, that’s also from your report well what do you think of the government in your power to ease the fate of your sons let’s figure out how to break away from revolver is it true that vladimir at home left a revolver in your lord fools of institutions really that’s how it was so the revolver could use oh no I couldn’t I returned his windshield wipers are springs just right murder, that is, the revolver was with you your son night of murder No, I had a revolver, why did you? lied Sorry, I didn’t mean to scold you helped me with this murder so you had a revolver then I’m asking you, did you kill Anfisa for that? to prevent her marriage to yours son, God be with you, I am not a murderer I was at home with my wife all evening and all night the servants will confirm very well gentlemen but this is not enough tell me what time you handed it over revolver proof at ten o’clock Vladimir was at home and I saw him briefly so he could see how the master Golubtsov passed you on to rival no no we saw it little by little we talked in the hallway and then I revolver cleared the table parents always they think that children don’t hear them then heat your son had the opportunity to take revolver and try to return it to place well mine it’s not your fault put it down here his but unfortunately I can’t tell you where you kept the revolver at home in the restaurant too according to doctor mints it is murder happened between 9 and 11 o’clock, then your son also had the opportunity to take a revolver and I’m very sorry to put it back in place gentlemen, your sons will remain under guards about other suspects don’t want to check you mean yourself yes you also had the opportunity matiz you killed anfisa and later handed her over revolver for the gentleman and at home for what to divert suspicion from myself I did not kill I swear it’s some kind of weakness photo he could shreds athanasius law school what kind of meadowsweet your ignition we from some seeds through They gave me money a month ago, that’s what I needed Well, in order to name his daughter, he married her off and our blockhead seems to have a fever there were magicians who could express their paws and if Borges was straight up theirs then I but also calm teeth that’s why our sons they were shouting yesterday at the cemetery that mother Anfisa and him yes that’s how it is I tried to reason with my mother but she wouldn’t what kind of meadowsweet this he she was resisting bewitched him and he already I started drinking and abandoned my body and realized I went he directly found the Slobodian base I have to ask you to leave us, gentlemen. it’s in your best interest the sooner we do it we’ll find the killer the sooner your sons there will be freedom and a master will be given bring and revolver accomplice rehau with them for the sake of the police chief not left me no choice you make my soul burn here 9 anyone who’s here that’s what I wanted to do here before vectors I would like to ask the same thing hair not here brought two offices to my wife, we don’t know yet why does afanasy klochkov live here and the failed groom and his mother told me someone was shaking it was overpriced in this I don’t really know, I came questioningly if you want to eat something there, that’s definitely not it Afanasy It looks like this meadowsweet really has it a black streak in life him Elena Viktorovna It seems he won’t harm anyone anymore Kvachkov has been dead for several days so he couldn’t kill anfisa, you’ll go, I’ll go at the call of the police they will take the body I confess when you were scared of me it seemed that in front of me was the same forget it was a moment of weakness you became strong, I had no choice you asked for my letters, I read them and wrote them I don’t give a damn about anyone We told him that you can’t say those words that in your opinion I am waiting for you didn’t let me finish I wanted to add that I can’t yet tell you these words there are circumstances yakov platonovich I’ve already heard these words from you this is the last century you are right i was absent for a long time please answer I only have 1 question to answer and more on the farm Yes Why what did you accuse us of? You said one. question one victor na and believe me i don’t I would not have answered it to the body except you from this folder which they left me about saved not in the end of course I will return it to you I beg you not avoid I must see you watch your bottomless eyes g-lorry. what let’s talk about business if you want the landowner’s beaks went and talked with I met them yesterday but you are right we need to talk to them again, let’s let’s go together well about the Russians the first time we came together sold here not for Razumovsky and you also stole cedar from his table and we managed to find out who killed him let’s talk about this later How long has Mr. Krai been having problems? shower with a month of faces he gave birth much earlier as soon as we arrived I was very pleased with her services pleased often praised her They gave me gifts as an example present new clothes all sorts of hats dress with bleaching these new outfits she has the city is glad to see you gentlemen on victor na yakov platonovich today your reception is strikingly different from yesterday’s please forgive me, you caught me I couldn’t even imagine it being taken by surprise importance of your visits please unban that I made inquiries and heard a lot wonderful stories so what I was looking forward to our new articles Well, let’s forget the old ones analysis irna happy to see you in my At home your mother invited me to dinner new ones beat me to the answers to this does not cancel when tire maritima farms without 13 years old we come to you on business I’m listening, how can I serve you know, I’m leading investigating the murder of your maid I can inquire such outfits trust milk and stirred it up when he had time protection from the wire but I already have it hides it just didn’t seem important I bought her some new ones before what are you in do you find something reprehensible in this? I am of the opinion that nothing makes a girl as happy as a new dress what hat anfis was very I was resourceful and decided to thank but I didn’t see any new outfits do you see what the problem is with her sometimes her mother came if she saw these things in her wardrobe that in relation to me her daughter would have turned out wrong and that’s why anfisa kept his things in another place closet She complained to you about her mother maybe to be something forced her to do something or I didn’t give free rein to it, it seems to me that they had complicated relationship but to something forced forgive me for my next question but where were you on the night of the murder from 9 to 11 manat hours a natural question with 6 From 10:00 p.m. until midnight I played cards in the noble assembly A dozen or so people can confirm this I can name some of the saints no need I thank you for the water and let me I would be very embarrassed to ask you a question I want to know your secrets, is it true? You and Anna Viktorovna revealed a lot of crimes and what’s not in it the last role was played by yours extraordinary gift it’s true but only partly rumors about my abilities are extremely exaggerated and now i’m consulting whom platon draw for medical matters only tell me anfisa didn’t tell you about their gentlemen on not command mom not I never have cabbage rolls, I think that he, like everyone else, had his own and you have one too please carefully I have the first guests to whom I open the door its a steam engine it produces electricity I’m going officers not not only your house but also utility rooms then the English apparatus also came to the peasants’ houses the system does not have this, this is yesterday’s Parsons turbine day I’m going to implement my estate the most advanced technologies to build a school for peasant children are here specifically productive for sowing and there is chemical laboratory if you want you can see the dps nice to meet you although this is not such an unpleasant reason I am sure you will find the decree Hello, good health Vasilisa Kapiton on you will be yes and you who will you be, you are a doctor, right, yes, to me you said for the new merchant of beaks erase mistake it must be maids and they knew Anfisa oh I knew forgive me Lord all her sins what sins what voice did he have stupid what does it mean looked there and where you can’t look, what’s hidden is hidden I don’t quite understand the basilisk tons what are you getting at, killed her dude or something tell I lived in Europe for quite a long time I studied chemistry and mechanics and I can say maybe a seditious thought for an educated person man of europe is boring boring Agnes according to your weight it was not fun drive janeiro cape town and how not it’s strange to rub in now that that 2 villages who has access as far as I know foreigners are banned from going there under threat death how did you get there but it I’ll tell you a separate story some other time put it and saw a lot of interesting things but what I heard you Anna Viktorovna it’s all cancelled there are miracles exotic countries andrey petrovich I told you it was very exaggerated yes, it’s all in the past, well, as a gentleman Ryabushinskikh wrote this in his article libel committed she assures you tomorrow in our magazine for ladies my answer to this scribbler will come out write to you too, I will definitely read it 6 a woman’s view of the world and this is what we need everyone still misses it, tell me more about your travels let them a funny thing happened to me in Congo this is very interesting how angry petrovich is educated smart very pleasant in communication with wealthy people Mom, it’s been a long time since I heard these there was no one to treat you, so I said, here I am I ask you I smoked nothing it’s boring Miss, who has come to see you, Anton Andreevich? oh my god, tell him as much as possible that she went to bed i no no no no he would didn’t just come like that, is it important, well how do you know anton andreevich she is victor you forgive me generously change what happened come in no no I’d like to say a few words the thing is that i was talking to today Anfisa’s fellow villagers and many hinted for some strange activities Nobody says anything directly but I I feel like people are afraid of something like this yes and that’s why I decided to ask you maybe be with her herself which I understood I I’ll try, thank you I gave the money on your own let the pampering force it stolen 2 and I wanted to throw it away but my mother wouldn’t let me because of money everyone has like henri on mother told fortunes on cards for money forced how come you got it so soon from the general tip erase just what I did to you thank you from the bottom of my heart good night to you Anton Andreevich helped me a lot and that unfortunate woman in the store got drunk death and the former goll poured as It’s strange who then that nothing good stretched on a third by you night I need to talk to you it certainly concerns you now I’ll show up but I know too little about HIV to form my own opinion about him and for me he seemed very nice and besides I she noticed that he was carried away by Anna Masha is located They are both grown-up modern people. They’ll figure it out themselves, of course, I just won’t I want them not to interfere either, and that’s what you think can interfere you surprise me victor that he is worthy of man she refused to go to paris and it’s not for you have to see him and talk like a man and like a father about something find out about his intentions regarding a if he has no intentions then will demand that peace comes or it becomes clear Hello you are a kickback good afternoon welcome how can i help you don’t worry i just want to take a look of course to rule and you just opened up recently a week ago kipling the jungle book but this is something I would gladly read the new product was brought in quite recently and gold I’ll take them Dr. Mills examined Adam’s revolver really came out of it Recently they shot at least I am inclined I think it’s Golubtsov Fedor who killed jealousy is quite logical why not agama why was he going to answer? if I changed my mind I would have killed this why if the girl was pregnant from It’s interesting to imagine him in what scandal suffering parents blackmail with her I didn’t understand from her mother’s side what are you getting at? Adamov suggested unit invited to date and killed this version Of course, we can’t rule out the fact that century fleet he know what i managed to do yesterday find out that no anfisa was fortune telling on cards for money predicted fate and for this many of her many people didn’t like it, they wonder I don’t see it there is nothing special about this, although you are right I need to ask my mother about this again or ask about it and think about i am doctor eva was allow by its height what are you planning I want to convince him change your wrong decision but you are not from around here, from St. Petersburg Polina is not Kyiv, actually Pelageya, but Pauline more suitable for the housewife fashionable book and I, Anna Mironova, hope that yours the bookstore is really coming soon will become fashionable thank you and you sister mercy to serve here hospital nearby and what medical do you have from you no but I can order from this it will be very useful I will please the doctor fought thank you for going again i think you you will see me here often thank you have a nice day you want to be is making I delivered it didn’t seem like it at all necessary impossible to put forward accusations unless we are sure that Mrs. needed him shot from Mr. Adamov’s revolver We can only establish this by opening it up bodies and delivery do you put me to be their platon is in an awkward position I went to light a candle for my mother and fellow villagers killed well now can you imagine what could be their reaction when all I have light, I will try to explain it to them that it is necessary but maybe we them at night loss on them group and we will return early in the morning his doctor knew how to be needed at the cemetery much more time for all of his necessary research so that We still can’t hide the factoring you cut me without a knife but in this case you should be registered find the criminal otherwise there is no excitement avoid you understand this of course Well, why did you start a stable here, it’s dying came to life from here this area what are you doing glad she’s back the investigation goes on to what extent the investigation and damned cross on you do not miss I’ll talk to her, stop and think kitchen how sorry i am disturb your daughter’s ashes but this it is absolutely necessary, you want it to be we will click on the site demonic deeds yours they wanted to cut first and now you take out the land, you need to push dumpling of that come with me let’s go I understand let’s go with me I’ll participate let’s talk a thousand why Mrs. Mironova Mr. Bread so I’m a presumptuous scribbler and collector low gossip Judas, you who do not remember your kinship, you deserve it each of these prose Hi you, yes, those who don’t remember their kinship, yes, how are you the editor missed this, especially here there is a missing comma here but this is better disgrace more timofeevna you should work for me what yes we will transfer your column zatonsky telegraph you are talented well how can you vegetate in Tomsk saints forgive me lord but i will be I will contradict you I will refute you and throw mud at me just like that this is what you need, you understand how they will take off circulations promise to think about small effects my proposal Fine I will think I hope the documents are not damp I’d rather have mold eat them You saved many and Anna Viktorovna Sorry, I can’t say more I’m so tired of your secrets what was what is what will happen and how will the heart calm down tell me about russia how do you live cow feeds his garden, his daughter helped the service was good, the master was kind paid slyly but the service lasted only two months I kept silent until then, you encourage me crimes your neighbors said that you never been poor so where does the money come from We hardly had any special money we made ends meet, but it was all in vain You are stubborn, Euphrosyne, there is one person so he says that it’s wrong Anfisa predicted his fate demands money back for fortune telling whoever is like that, let them not lie and come true and fortune telling She told Petrov that her son would be a toxin. they had a baby, well, it’s true, after that, and the girls the wall predicted great love and in she was forced into marriage and then I fell in love with him passionately and also because she predicted a long journey for the groom, so he did Well, here you go, a long road ahead ah so that’s what it means sooner or later one way or another cleverly conceived cleverly bright daughter sat down at the table and good doctor Hello, ours is here arrive Anfisa killed the servers here, he thought that rids the world of all evil but there are vampires werewolves witch you You’ve probably heard about these escapes before for murder out of jealousy or place there is no need for a silver bullet and it is possible to get around in the windows of the venerable to say such you can go to the blacksmiths or in a jewelry workshop by the way remember him asked me if there was Anfisa is pregnant for so here she is pregnant she was not thank you alexander francaise at least one motive can be attributed this is the house of the blacksmith Kukushkin what can I do for you good health sir and the same to you Kukushkin Stepan etc. Well, I’m selling the blacksmith, I didn’t smoke they dared to work the figures they say there and cousin and we washed the high frequency and I see, well, somewhere in there we show the forge necessary they uncovered the confusion, no Danis, it seems like everything is on the tool is just lying there in weight there I put him and raised the mountains of Uncas if anything I would read I haven’t been here for two weeks silver on top figure piece spoon fork and knives simple tableware I think siri guru joy of snow andrey petrovich new things why do you need it, what’s better for me give it to me I will give it to someone things of the deceased give a bidet someone sir. open up i need to talk to you this Mironov glad to see you filter you are mister navigator I can’t answer you the same way I would I would rather not meet you if don’t push Well then, should I ask you? directly what are your intentions regarding my daughters restaurant all know from deep respect floor these are all words gracious sir, do you intend to ask her? hang your hands I would consider it an honor but everything is pretty clear to me you don’t have to continue any further sir storm in that case I order you not to come near me daughter with all due respect to 3 frets you can’t order me around listen Don’t you understand that your presence poisons her life interferes with her happiness I suppose Anna Viktorovna she herself will deny me the pleasure, I see and if he deems it necessary, I will say everything and I suppose if there is even a drop left in you honor you will do as you must, I dare expect our conversation to be saved in that evening in parts this is the last one and thanks put it here baby somehow I’ll drown overlooked it’s because of you that she gave me such a gift She said all the worries are carried by modal was already made by the blacksmiths kukushkina this hid the castle I found traces silver work and a piece of cutlery device wow and the jeweler told me that the field is made like this once from silverware only necessary It’s scary to imagine searching houses the killer must have had access to 3 of you so it’s either golubtsova or adamova but why did you need to shoot? It was the silver bullet that pierced the gentlemen crayfish I thank you don address I ask for yes well what same gentlemen, some amazing somersault We owe it to fate that we have what we have In our city we see you Yakov Platonovich and you know what I feel what I feel that we are standing on the threshold of some significant and I’m not afraid of this word fateful events yes something something will definitely happen I don’t know what I hope something good like fleet night your health your health we beat him. thanks anton drake can explain and what kind of event do you foresee? yeah how should I know get away from justice yeah God willing, justice will prevail It will be good after all, I’m the boiler. Tell me, what are the prospects? you see yourself here in our city before the prospect of me is always one to serve this I understand that service is service, but maybe you will want to start a family and settle down so to speak, settle down I doubt I’ll be able to combine it service time he got married and in any case until now it didn’t work out well, I also understand patricia let me put the heating pad here, really then fools It only remains to find out whether it is the father or not and let me ask where they removed it these devices they are so good, such Zatonsky no more, personally ordered in St. Petersburg you won’t say right away They believed that Anfisa bewitched men perhaps they thought she had cast a spell your son literally has nothing they already took me, they mentioned me at first our meeting you will find out anfisa was killed by silver bullets cast from your restaurant’s fork Well, what can I order by the grace of the Lord? and anyone could steal from us 1 lit always doesn’t disappear after the banquet It’s good that you can still order new hives athletic time needs time you have you yourself showed that sir Adamov made a revolver for you restaurant a week ago and they returned the hive only 3 days are not enough maybe some of the nude’s other children as far as I can tell no, only Soloukhin from the mouths of geese misfortune is exactly where is anton andreevich so the power of cabbage rolls in the restaurant dinner from I didn’t know such people that he was lying on now the waiter found the boat and then I forgot where the waiter is now to bring here the glory of attention and for where for which he asked to go home he just got sick and feels bad talk show words gentlemen what’s going on, we’ve been extinguished I urgently needed to go to this how are the potatoes and shook be but Is it really impossible to figure out where tomorrow where is the takeoff already, let’s have a drink police open police Anna Viktorovna how do you post from me asking what’s wrong with him maybe send for a doctor to the persons peter soloukhin it is you who will convince faisal dinner confess six months ago my wife the confession went, we lived in poverty there was never enough money but I went to find out what’s ahead office and promised that everything would work out she said all your worries will be washed away by water A month later Alyosha drowned and then the wife died I couldn’t bear the grief in your opinion it is ansys’ fault and it was she who predicted it so you decided rid the city of witches i read mystical book that the witch only knows silver that wait for the right opportunity and when Adam’s son put his revolver in restaurants left who did not come my time passed abandoned bitten and how did you know that it was that evening Anfisa will be in the park Fedor Golubtsov let it slip and he Vladimir boasted at home, they say you are crowned with English opposite parental will fistula and crowley when she sees and then they shoot her and the revolver was returned to Golubtsov cast suspicion on him why else to take one sin on one’s soul I wanted to show him today where my conscience tormented me in thought and in the end you will not find many in the city has a death wish in vain red Venus Anfisa death of your son and and fortune telling was a game 3 times more no one will be harmed by Alyosha blog i’m coming how stupid this all is Anfisa told you a ridiculous story no son the drowned boy is with you everything is fine now it will pass for a long time that’s how they coughed when they went to their doctor you worry about me that’s not all lost anna viktorovna I see you are still here, allow me to Of course I hope we’ll go to those cab driver goodbye the estate of the world made themselves wait for the blow to come I hope no one will raise you in the back streets saw A mo You yourself knew him, you saw him as a child I barely remember the shower a couple of times, he has a mustache were there such outstanding ones and what helped You’re joking with them, you haven’t earned a penny in 20 years gave it to him even though my mother is his own sister Grandfather was stingy, Andrich was tall, but now all this is yours and only because he died overnight and didn’t have time to do his part movable and immovable as they are almshouses to bequeath and by law I am the only one heir Well, let’s go to that Aladdin’s cave yes, of course they are not your late Aladdin more likely Miklouho-Maclay and touch the expensive thing you will break it hello grandma who are you I am Praskovya’s fox Rastan served the deceased with speeches may the kingdom of heaven be his and by any chance you won’t be the nephew nephew two or three opanas arrived and that’s it I think when the young master comes, then perhaps but come on, take off your clothes, give me your clothes I will accept listened to the abyss I am a man of new views you are not a servant to anything you can go free how is that possible I have 6 I don’t even have my own corner, I’m your uncle’s 40 years or truth and then we got into debt I feel like I owe a lot almost 20 rubles I don’t have that kind of money ok daddy stay then decide with you how I will make it eat the riddles perhaps in fact I’m hungry as hell, yes, I won’t refuse I’ll tell you straight out what the lady is talking about right now I expected more from your inheritance, you I say stop, you will leave, it was a whole the condition was guessed by his was know what you spent it on however, half-shin yes, you can sell it what the hell like iblis Now I understand where the deceased spent it do you think about money there are many sites that can help out this is enough the most daring project of you I understand what this means we now have money not a gun and there will be pressure A what would you like, madam, this media list hva du it is the nicest house and far from the city so why have you been serving here for 40 years already? served and will another place suffice for itself we don’t need it for what Dmitry Fomich heard you really don’t have and these are not against me let’s go, we think alike, we look at things alike how much does he owe you 20 rubles here take track 1 Mitya fire boys i’m here Andrey Petrovich plus what about this in such and such call early good morning anri petrovich starve him wife Anna Viktorovna hello spend francs everyone obliges I was driving by and I thought, yes, I’ll stop by the neighbor’s I’ll visit and they did the right thing, he doesn’t have it tomorrow to thank ceed but then maybe coffee but we’ll give up the kitchen thanks perhaps we’ll turn it off and have you heard about auction what auction we don’t know anything about today In the evening a certain Dmitry Aristarkhov is selling off his late father’s collection uncles burial masks sarcophagus canopic jars channel pie is such vessels for storing entrails died in ancient Egypt sorry good it’s nothing to worry about you and they said Dmitry Aristarkhov who am I I believe this is Andreich’s nephew and Rostov the local landowner never spoke about him I haven’t heard of it in recent years, no wonder for twenty years he never left my side the old man and you were strange in general Nobody had really seen him here before more and more with you Egypt disappeared through some kind of wisdom almost immortality but you clearly don’t have immortality I found it but I collected enough collection impressive famous personalities will be at the auction Golenishchev is the most famous in Russia scientists Egyptologist owner of his own collections of Egyptian antiquities He says he wants to buy the most The most valuable lot is a mummy which is about 3000 years and what to put on public display review I don’t know, would you like to take a look? I admit, no, I don’t see anything attractive everything to stare at the buried deceased is not fat just I stopped by to invite you to this auction I apologize for Petrovich I do not I’ll go anushka but why don’t you go You’re hardly ever on the ground like that dear business somewhere really rare chance to see precious heritage of millennia agree to victor there will be very many familiar Mr. Shipbuilders will monitor the safety of all slots if you still insist then I guess I’ll agree, it won’t interfere, well come on in anushka how are you with me ok here is an example this is naked and such is your grandmother’s and doomed him this and the wedding well all this is nonsense wear you were very healthy, thank you very much Mr. Clio IV will shake mom our relationship with andrey petrovich friendly people I think he will agree but please don’t tell me this statement I told you a thousand times I didn’t I’ll get married May be . when live your life of pleasure what kind of fire is specified and also everyone marriage even if concluded for passionate love in the end licking eggs is unbearable in this descent Antonovich she wiped it here and I with It was a pleasure to chat with you execution your friend is busy this evening was born you got along with my humble company nothing against them maybe some champagne and so ladies and gentlemen alabaster fluffs from an Egyptian tomb 4th century BC eras starting price 500 rubles for large ones dessert grid 550 rubles 550 rubles 1,600 rubles 600 rubles 1 650 650 rubles 1 650 rubles 2 700 rubles 700 rubles a great investment for conjugating your capital 700 rubles 1 750 Victor she is not I expected to see you here, why not? I know I thought it wasn’t for you two glasses of Golikov listen we 700 to 800 rubles 800 rubles once I here on duty do you think it could be dangerous yes no just a precautionary measure agreed should go very valuable only you someone you are looking for and the risks of tetis someone not we don’t touch him, but you do something worried how good enough for you for 950 rubles I want a round figure of 950 rubles 3 sold uncle uncle and when returned only so one of the screams was almost late the will be amoxil I came in so that’s all the benefits of cutting it and the sands of antiquity quite a good investment while away so since when are you interested We only have 2 Egyptian values appeared this gentleman whom my Mironov already uncle very nice cliff even mutually you forgive me but without an invitation You won’t be able to get inside, I beg you Anton 3 Well, at least for five minutes 1 I can’t see it with my eye, that’s the most important thing event of the year and my readers don’t tell me forgive me if they write to me I would be glad help you but alas invitation however let me console you that scream measure three before that who is looking for that will find Come on gentlemen, our next lot wooden figurine depicting Egyptian god of death he murdered the ancient Egyptians believed that he meets the souls of the dead and leads them to the judgment of Osiris 2 centuries AD starting price three strings 350 350 rubles 350 rubles 1 350 rubles 2 fat 400 rubles 400 rubles is great avenue 450 he is here Andrey Antonovich what if you tell me everything what is happening there will be recorded of your words well Don’t you understand, well for now we’re here on our own push I myself will not see anything in the hall if something happens then I give in go there and roll your heads quickly into the hall wait a minute I’ll wait for you here, I won’t tell you anything I promise to join go precious in our and I bought it, congratulations, excellent acquisition forgive forgive for god’s sake will you allow me to look at please amazing work congratulations hide from the sun so that the colors don’t fade phenomenon sorry i didn’t introduce myself take switch ganichev Egyptologist very nice Andrey Petrovich only very nice in one roof and this must be your wife no i am not your daughter lawyers neronova 1 viktor my approach neronova isn’t it you the most medium woman who was written about newspapers a few years ago very I wouldn’t like to oversimplify it It’s a pity, you know, I’ve been doing this all my life I study ancient Egypt Egyptians in communication with spirits was nothing I didn’t think anything unusual about everyone there is a person to part of the soul or which remain after death earth and you can talk and schiz me our main one here is the mass priest of Anubis more precisely, the mummy into which he was turned the body is skillfully polished and it is bilt as it is supposed to be Kent and children of years they are typical for your fight studied banks it is necessary to note she will come out she what are you scared of today my head was spinning from the champagne that I I can do nothing for you, I’ll stay one okay I won’t leave you alone two Petrovich please I beg you everything is fine with you as you command and so ladies and gentlemen 2500 rubles 1 2500 rubles 23 thousand three thousand rubles 1 3 thousand rubles 23 503 thousand 500 rubles 1 3500 rubles 4000 5000 5000 times five thousand 25 thousand sold gentleman stripped him for 5000 rubles she is victor anna viktorovna darling please help me out but at least a couple words you were there tell him you didn’t see him in time make out chasing sensations again gentlemen ryabushinsky what are you master of the storm I I just wanted to know if I needed anything Viktorovna no no need both not victor they are there for whom take care that’s great Jacob Platon not in the same 2 Don’t tell me who bought the legs scientists collector from saint petersburg Mr. Bootleg and that’s where I’ll end our conversation for today Thank you Are you okay Anna Viktorovna No, I kept thinking about this top mass It’s terrible that his body is on display their tent falls to already expressed believed that in 1000 years he would be behind because of the board you don’t understand me in real life a person is the same as you and me his thoughts and feelings dust and bury humanly they exhibit in the museum honestly beautiful what I know you said that the past is not returned no but still what anyway a cry in the plasma and you are not a child at all if you want to say something, speak stubbornly I would like to give you everything I can suggest only Yakov Platonovich You so quickly I passed by I thought something had happened, you understand, I I am personally responsible for this the event certainly didn’t seem like it to you strange conduct of one gentleman me A let’s sum it up like this surprise yes we are here you just met at the auction look at what thing I came I didn’t I was waiting for you and if you don’t have me, then I’ll settle down hotels what nonsense what the hell you know they are always waiting for you here holes today I want to know everything We beg you for the details for God’s sake not today and I’m so tired of performing I bought this from you at an auction and it seems to me that Annette has a new one fan quieter your neighbor klyuev I speak quietly and not likes such conversations well yes we will really measure the well-groomed and I am so immeasurably pleased with how he seemed to you we didn’t have time to really talk about it my glorious what do you say did you recognize anyone it was too noisy it was impossible to listen to the voices You forbade me to enter into conversation should not take unnecessary risks if he in the city it will soon appear in the x store be careful birch weapons that’s what it is A Sorry sir, excuse me, they are easier to create yours I but yesterday we saw each other at the auction bootlegs Egyptologist what but judicial investigator listen so coincidence i like once the area was going and the thing is that sir assault that I would not like to rush I still hope that this is the case with the accusations the mistake is not an evil mind, can you explain it clearly? what’s the matter the mummy turned out to be fake good afternoon, no more words, court let’s go yesterday after the auction see quite which agitation and I couldn’t wait to touch it woven treasure New Kingdom era as a rule has amazing instability some of them even have an eye joint very curious but I ask closer where wow yes yes of course and so well I’m not in stockings I was able to resist the temptation properly consider my live i collected all you have to do is turn bing slightly to check its safety because this fabric for more than two thousand years it has survived to our days thanks to the special composition of which her about medals and noticed that bento shared too easily it was immediately aroused my suspicions without much the work was divided into the upper body and I realized what was in front of me fake and how did you do it Got it, you’ll go. I have seen dozens of Egyptian mummies and I can to believe that they don’t have teeth like that whiteness as well as nails obviously lost by the saw I hope that Mr. Aristarkhov himself did not know about one and I agree I will return without money scandal, wow I admit I also think that Aristarkhov car and he inherited the collection a little over a month ago It’s obvious that it’s his uncle’s mind that is being fooled everything needs to be implemented just intro I’m recruiting, I wouldn’t rule out forgery sides heir but she also had an ocean he was in charge of everything at the auction attorney I hope he is still in town that’s if I can do it to him with which I recently perhaps this is murder gentlemen you are not believe me, I’ll talk about this myself right away She flew very opportunely with us today a very unusual patient cats and yes judging by the condition of the teeth and I have this woman who is no more than them 25 years old she has a cut on her stomach and all the internal organs the bodies were extracted and dried in this way what can we assume is that she has been around for a long time lay under the rivers I know us the sun blown by the dry wind that it is absolutely impossible to teach our weather places or she was under the influence some chemicals really bother me a convincing fake exactly like that what did the Egyptians do with their dead the organs were removed and then the bodies were kept in sodium hydroxide for 40 days what do you mean to say that he is a criminal owns Egyptian technology and embalming somehow it is this is not a closely guarded secret process Herodotus described in detail in the 5th century BC era 40 days means she could have been killed not at all until 40 but maybe 40 years This question is impossible to answer I swear to you I didn’t know anything about the organizer auction said something provenance mom not leaves no doubt It was bought in Luxor from the department Rasul he receives his goods directly return this from the plundered tombs the amount paid is of course only you see I don’t have any money now, so what? Well, you’re telling me, Dmitry Afanasyevich. a fortune at auction yesterday helped out I understand how it looks from the outside but Believe me, I owe a lot one person well what we search the leader this is necessary I’m afraid that we are not talking about not only about forgery but also about the possible murder and so you understand 1 the suspect is you starting Frantsevich, you could at least say was there a death of this woman violent answer to this question impossible too much time has passed you she vector I’m afraid that we from you I can’t open this case, I’ll try in a few minutes to be left alone I understand gentlemen, I ask you come with me I need to clarify some details A spirit movies Why do you owe so much money? mister aristarkha skis student studies by the way, what are you studying in year 34 chemistry chemistry interesting yakov platonovich I found this bedroom whose things are these in the house they still want iron threads one who are they belong to the bright possess there in the basement that I will have the benefit of seeing it myself once died on who killed you I order you to show me show me bo I order you to show me for 3 8 liters why do you need it and you still have to go become quantity hold hands she is victor what will you please girl young and quite beautiful I killed man masks anubis blows live all I didn’t understand anything else, thank you in that case, allow me to take my leave I’ll go to the site to conduct an investigation in the usual manner and Mr. Glinishchevo no longer cares about the fate of the mummy and therefore that he urgently went to the hotel renew your number i think that worries all the best all the best there is nothing to talk about here yakov platon it’s clear collistar how some woman arrived it’s a fact you found a caustic one in his basement sodium this is also a fact and what follows from this it follows from this that I k plato that our the student killed his guest and made her mumiyo I think it’s wonderful, I would even said some political way get rid of the corpse anton andreevich the most difficult method is very senseless boots sooner or later You would have discovered the substitution yourself they said that Aristarkhov is going to escape from the city, here’s what about golenishchev he would crucify movie in his Petersburg so alice go where were you at the ends of the earth lands so i suggest we put pressure on him it’s time to ask people in the city surely one of them saw me coming lady if we establish her identity and we will understand that she has gone missing be it is in our mind It’s just too easy for you to always make everything simple it turns out that this is all you have then there are no other versions in that case I went through working on my faith for Mr. Golenishchev, I apologize for anxiety alexey ryabushinsky newspaper zatonsky We saw each other by telegraph cooling at the police station before I found out about Mr. Ryabushinsky, what can I do, yes, I am here see or dine you alone and I saw you exactly the same, so to speak his disposition will either be for you move to my table together it’s somehow more fun, you know I always dreamed of talking to someone you know about the upper ancient Egypt you are right it is incredibly fascinating subject learn on case arrested Dmitry Orhei I’m afraid I won’t disclose anything has high at night are we without at all concepts flashed thanks slushies listen, please bring us the model the best glasses grams 300 us qualitatively understood if after death a person falls into a lethargic sleep since she is on the ground, she walks in lethargic sleep falls into and this is already another part of the soul and in total how many are you 7 in body and also from part of the soul and name if name your concern you never enter 20 and not gain much connect this unfortunate converted in them hell will not get into heaven in quantity there won’t be an ace tone why is his personality her personality her health top from details Well, what did I tell you, see how much people buy the newspaper and ladies and all this your merit is priceless maltesers need I must admit I was pleasantly surprised Alexey the city never failed to investigate it’s normal that even my best is possible author attack I’m very curious where from you learned all the details of this ritual murders I do not disclose my source and how did my father come to him barney only one famous one and I don’t know maybe be age or somehow external you can describe it, you can see that you are so beautiful only the eyes are cold as if made of steel age in our time and at 25 for an old woman and now even at 40 I don’t know any beauties I’ll tell you OK, but you will recognize these things if they you hat is precise and dipper is quiet as in your opinion, she had to do it to him he loved him still loved him so much how did he love you I love you my life my destiny everything that I have I have all yours you have nothing of your own the rally is developed this was and keep busy waiting for you with everyone on and for all of us common A and then what, well what happened next maybe they we had a fight once how should I know she was me that day I figured out why you’re busy I’m you a certain Pavel Martynov will ennoble there came from Petersburg, speaks on business Aristarchus Mr. Martynov, what do you owe him for growing up to Dmitry Aristarkha sat before and what about him friend no need to see him i’m afraid he is in no way impossible aristarchs is accused of a serious crime and refuses to cooperate with the investigation in similar circumstances the date is not delivered to her then I arrived as I read in the newspapers about I want to talk to him about his arrest the truth about their guilt is obvious only repentance capable of easing his fate ah so that’s it mister aristarchus you are like that and you will continue to remain silent about even three days you test my patience with me the slower you go, the further you will be the master peddlers may explode If you want to go to the dungeons in St. Petersburg, it’s not easy I will have to, I tell you for sure, well then that you will answer questions and therefore I don’t think you can do anything, you just autumn young inexperienced simple-minded man daddy noble company sorry Yakov Platonovich Anton Andreevich They ask the arrested person to come to them hello me which the door kilo Pavel Martynov I came from Petersburg and somehow I’m holding on mission you have to confess everything i I know she was a bad woman in the end much of it you it did not control itself when attacked her with a knife and still murdered her an innocent person for a terrible sin when there is no other way out mouse this is the best way out the meeting will take place attention that the murder occurred because passions you will be shown leniency and soul iraida will finally find peace iraida until Her name was Iraida Suslova I killed her A I loved her more than life, I begged her to be mine wife but she didn’t want it played with me like a cat with a mouse then he caressed, then he pushed away that evening she confessed between fell in love with another I felt some kind of clouding over me grabbed a knife from the table and stabbed her stomach yes, I think I read something a third of the time similar to Prospera Merimee and then you made a mummy out of her I didn’t want to part with her and her body no way the chemist was interested in conducting similar experiment I stole caustic soda from the lab faculties and they took some in reserve for the future, well, for some reason they quickly cooled off towards the corpse to his beloved and therefore decided sell it at auction Iraida Suslova 26 years old participant terrorist faction of the organization appeared after the defeat the people’s will is the only one who succeeded went into hiding seven years ago after an assassination attempt on the sovereign emperor all this time the police are looking for her and we found her is it incredible luck or great the play was played out I don’t understand what you doubt Aristarkhovich himself admitted to everyone yes from the words of my friend from St. Petersburg which as you noticed literally dictated it to him, they recognized it I think you are exaggerating However, it is strange that Martynov did not come. earlier arrived exactly after I read the investigation by Ryabushinsky and essay lady world us which in detail it is written about the scar on her in full eat and find found caustic soda in his basement is irrefutable evidence, because you can yourself introduce Dmitry Aristarkhov hiding a series of corpses extracted from his organs need a strong hand before that well and at least some general knowledge in medicine but also the most important question why it would have been easier to do this, it would have been easier to bury the body forest, by God oh well what is she victor there are secrets in my head who don’t even know my mustache so then we can congratulate you Anton Andreevich you are in for a promotion or some other reward touched 2 you know for me the best the reward is your attention look at I’m more likely to be half but I’m not I deserve yours attention nesting deserves anton Andreevich Wasn’t it the gentleman who detained Aristarkhov? navigator why are you talking about this again I sent he was taken to Aristarkhov’s house just so he wouldn’t waste time having done the deed took on a very serious tone turnover look at this woman, she is a terrible woman You can tell right away that this is not it he won’t stop at anything but what is this not her. another girl was killed in aristarkhov’s house so you continue to insist that no did you know who Iraida Suslova was in fact? there is no point in when and how you are with them We met maybe three months ago four back in the tavern st petersburg the first time but I don’t care anymore believe what do I believe when they tell me the truth Hello, good afternoon, madam mironova I am very glad to see you again please, let’s just do it without ceremony she just came in find out how things are going in your shop much better than I would have dared to assume I have a lot of you, a very well-read public orders and what do they order you want to know so 12 orders for 2 sphinxes is new Mrs. Kryzhanovka’s novel interest in Egyptian theme is unusual I can imagine imagine what else Mrs. Selezneva wants to know the future the complete guide to tarot cards patch mister kuzyakin suffers from gout conspiracies for aching joints conspiracies as a doctor he seems afraid to come a cultured person Mr. Beak wrote out a reference book on cereals Central Russia from the Sabashnikov brothers Mr. School Cycle Piebald Heresy dangerous cults strange are you surprised this navigator he is your friend we them In Zadonsk everyone is familiar with each other in one way or another Tell me, can I order the same one for myself? book yes of course you are interested in this topic it’s so interesting that it’s so simple curiosity please tell me and madam Is she by any chance your relative? this is my mother i can’t tear myself away from her article I still have this in front of my eyes Horrible picture of a masked man killing with a knife in the stomach of his unfortunate victim all this is described in the article you haven’t read it seems I need more pay attention to mom’s bite, sorry Me Polina all the best 2 good henri kira Hello, this is a lampshade have you been to a bookstore is this surprising or this is an interrogation it would have been more like starting a conversation, that’s the same are you heading there no just passing through past Tell me, did you see something at the auction? I can’t say for sure it only lasted a few seconds but you felt bad you lose consciousness I think I I saw So far Nadezhda kill someone with a knife in the stomach anubis not dmitry aristarchus think over and Aristarkhov is innocent I confess to me there is a comparison but you will tell in brides if i see something else, of course i’ll be here I’ll tell you Anton Andreevich, are you trading in this case? good diameter to the righteous plato type and how cute is that Just listen to your growth syllable yogi like breathing and the writer’s talent and doubts and who I’ll write it down for you one reader I now get double more letter should depend on your The essay “Dead” is written quite briskly however, you picked up a lot from it she didn’t lie, she didn’t embellish it for anyone It’s interesting to read about real life, tell me please, you found out about it from me that the victims were stabbed to death and live to see in general I don’t understand the point, but the fact is that now the killer will not be found because the criminal learned during the investigation of the article Mom, don’t talk nonsense, the case is solved the killer drawing yes and we are not in this are we sure that we are who or what do I eat only you know i will never see you again nothing to talk about places you’re just jealous of my success and she doesn’t can you hide it in this family me never understood It is true what is said, a man’s enemies are his own his I need to work I guess I have some things to do too, Lisa please likeness of cats office this minute bar my angel tell me do you really think that’s an idea risks contains innocently confessed to in general there are a lot of discrepancies and the most the main thing will be conveyed by the word not at all looks like the spirit I talked to that you will convince the spirit that such help is not needed so i can take the bandages and amulets former on the mummy they are genuine some value Of course, take it in good health say something and what have you heard about it Aristarkhov’s house will go under the hammer and you will already get money for it your five thousand but I’m afraid that it will be not soon unfortunately we still don’t have it managed to find out where he put all the money from the sale of the collection and he said that he made with real movie ska worth it yes but there was a real mummy priest status what did the tube do to her Now we’ll ask him about it, let’s go me and now suddenly I felt myself like five years ago when you and I were engaged in spiritualism, unraveled all sorts of cunning body glorious was the time I admit we will hide accepted myself with completely return yourself look here this house just gives off something sinister it but to put in the forest far from the city the perfect place to commit crimes but you never said nothing we are here in this house in the basement a murder was committed, they didn’t do it to him right here and so I thought that if on try to call at the crime scene spirit of the girl you can she will give a new the sign is just how to get into the house yes no it’s illegal you promised to help me just hold her asked but I’m a pro hold on, uncle when you asked me for help you did this she did it in such a mysterious tone that I I guessed right away easily and what my talent things can be very even will come in handy thank you how much longer can I just have two hours talked with the navigator and completely exhausted alone what Dmitry lantern after tomorrow you will be taken away Petersburg on the trellis there you can rest and in the meantime answer us where did you put the real mummy, the real one I don’t know mummy money Well spirit Iraida Suslova, appear to me in spirit Iraida Suslova you know I’m almost sure that it is not suslova maybe her spirit port fer is not in the mood today inhale moon and 9 me spirit she is there here payment of which minutes and I’ll come now I’ll come now to let them in at 10 I’m going nowhere Dmitry Afanasyevich Silence will not make your life easier where did you put the real mummy we will find her and I am sure Mr. Golenishchev I won’t insist on forgery I won’t I burned it in the stove broke the burn elephant shape burned god my what kind of husband is my Here Luke Hannes said to be here he is and you were right there are no aristarchs pigeons this means he didn’t kill the raid Suslova needs to be dealt with immediately telegraph to Petersburg how stupidly I was mistaken I was hasty with conclusions and you knew everything from the beginning I had my suspicions right away, so I He kept silent and wanted the conspirators to think. that their plan succeeded, that is, it was not one later my reputation as a researcher supportive does not save itself ahead of time Where Sorry I had to raise the salt on you later private business does not tolerate we just got some delays telegram about heroin and suslova detained at the Lithuanian border cannot be this is some kind of mistake with her your friend is arrested Pavel Martynov I’m not going to do it in pairs leave Russia withdraw a huge amount of money money rules until we what a scoundrel I should have guessed pretty well invented me to hard labor and he himself was given money for Wednesday border great plan and you really are good for the first time gave away all the evil inheritance a friend with his mistress and then they confessed in whose murder they did not commit the inheritance is laid Dmitry swim was going to sacrifice for a good cause the maintenance of tyranny liberation of the working people 9 just talk about if for musicians and you look tired she you should rest and get some sleep, you’re beautiful there are no methods here but I enough enough what do you want what are you watching boffin something meteorological obviously something atmospheric in spring close often it happens why can’t you sleep I’m writing a new one the article is called return although there is no better name, I have one better than another smori mukhin and why did you need akinator explosive device before the body played burying Moscow I took on the task of making a governor general Iraida had to prepare the bomb in Moscow we had surveillance of the police they think wearing it from the dead is all a lie there was no conspiracy, she just was going to run after us legally everything exactly as you gave it or didn’t give it order of the solicitors of many of their Moscow and there I handed it over to the man myself I was going to go after her the day of her arrest and where were you going to meet her? abroad the house of the merchant Zatulin nad Molokans Zenkah ask Akulina show Aristova wait you didn’t catch them right I was deceived, they played on my feelings made a traitor I saved you from hard labor if you are sensible you will get rid of it link you have a chance to start a new life don’t miss him take him away took bravo-bravo Yakov Platonovich you did it smartly, you had to do it smartly telegraph to Moscow immediately if They’ll be lucky, they’ll arrest Suslova today. At night your superiors will appreciate you even more no oil their fleet night it’s you you it’s I do disclosed anya I just believed in Tarkh Internet speech I I kindly ask you not to tell anyone about this speak no more than convenient if laurels of the main detective Zatonskaya you will get the same case of the mummy chase finished that’s right we don’t have no victim I’m not a criminal, maybe it’s a secret such will remain unsolved in no way I won’t give up in this case, especially now when we almost certainly know what and the murder and embalming took place in in the basement of Aristarkhov’s house you need Be sure to interview everyone again were closely acquainted with the calm and could something to see for u besides the old woman the housekeeper didn’t communicate with anyone, she was tired of being let’s start with her at 11 in a good way the attacker on I admit I was surprised by the letter that delivered you were put in jail need yours help yesterday in the basement of the house of aristarchus in power spirit here mass seriously I didn’t want insult you the thing is that he leads I don’t know myself like other spirits anymore what it can’t give ok let’s take it easy no need whether the conversation is sorry well I understand articles 100 and never here but right behind yours back don’t turn around we won’t get it anyway see oh my god said now through you as well as her bin rashid rahma tom somehow it’s so incredible that you understood something from this they 2-mind not only to write and read hieroglyphs oh my god she she oh my god me first you modern scientists managed to hear ancient Egyptian language in my brain free retelling even though I can’t convey it anymore There is no need to convey all your delight delight and to sleep and in the boots I do not have it Understand so you said that you can read and write hieroglyphs vlad boom quickly give paper paint and he and the guests came to the deceased 1 tone of speech No, he didn’t like guests and didn’t invite them into his house. what has he had for all these years served no one ever stopped being this can’t happen my father cannot be my growth at once Andrei part of the year almost 10 months I traveled abroad and when I returned I was taking a break from everyone, but women, really? have you visited or not have you visited abroad? maybe there were, I don’t know, I won’t say and here others had no others except whom Well, what’s there to hide now? we got along how long has he been I did it back then young oh well I’m a fool it seems that’s all Well, here is this hieroglyph definitely denotes tombs well of course we naturally he just wants so that we could bury him and give up the body we doubt the earth but accept the seven parts of the soul unite and enter into afterlife 2 only at compliance with a number of conditions preservation of mummies presence of tombs I’m sure of this I’m sure of this there’s a lot of that that you will destroy him if you bury him in earth what well what does he want from me then apparently so that you could build him new ones there are no degrees necid this is some kind of nightmare story equals steve ask again talk through the menu you need to his plaster teams Mr. bootleg and over the excitement of what open and the debris is still here well then I said everything I wanted for you to translate it wrong, looks like it’s right after all wait I think and it seems I have onesie what are you doing this according to words judges this means the document is approved that you we wrote in the document what we want build him a new tomb but for this it will take some time mother may several years maybe. but it’s quite true, look at this congresses of Russian artists German professors called on to create a well Museum of Fine Arts success here look at this sketch won the competition project for the future I really wanted to buy the buildings mummy for his collection but now with joyfully donated to the museum as soon as he will open again the same thing, brilliantly that’s hopefully your problem transition to only 1 of 2 what is the second who was the girl they made mummy just admire from Moscow you returned the telegrams of moscow union Iraida Suslova arrested revealed human conspirators our too congratulations, it would be great now can they go home you can go I I’ll stay and rummage through the archives of those photos tonight you are an amazing person you are one of those people which if they don’t find the way that some you will pave I need to find out if anyone has reported it missing girl woman in recent years how many years do we keep archives for how much well here for so much I’m afraid that I sq Plato, you can’t handle it alone why are you sitting like a queen on the dishes yesterday’s dishes were not washed, but what do I need? here you are on the farm and I am for beauty I’d better not get my hands dirty he’s just I will save this transfer Here Here I will give you death, you will live I will fall good afternoon good morning doctor me reported that you asked me urgently lamb say goodbye disturbed the doctor but here list of missing women with our province could you please look at the parameters according to the description, they match the parameters our mysterious mummies back to the list not small she victor on Today in the hospital you know, I’ve been working on this lately wear and tear so I ordered her to go home and have a good night’s sleep then all the best let’s go I I’ll arrange for this cool one to be left back Phil, would you please, young lady, another Praskovya fox I was told she lives here but I’m a simpleton come on in Don’t be afraid, we are charitable poor relief societies he will come to you bring out the medicine if necessary, well, thank you very much sit down good morning girl but let’s see what can we have for example ryazanov glafira petrovna long ago calmly stopped sleeping, maybe she’s translating something There is although I can’t sleep in the important place and my old sins gives me no peace find out is looking for the owner your belonged to anubis god of death your veins stand when you look at something like this in a dream you will dream about it and probably from I don’t understand if you can die from a heart attack what are you getting at? You all understand Praskovya, you all understand all of this you see i know that it was you who killed that one I killed the girl the master then went to the surgeon’s office during the week and how do you live here among Aunt Pasha horrors of these the dacha and gave them to these nasty ones who the masters are standing in the basement, what are you talking about you understand, all this is ancient history money is worth perast andrey took me I was just bragging there, I was just a little bit godlike gave her soul fear mortal special demon from the stove he scares me with his head at night nightmares are breast I’ll have a sofa like this immortal one fear you will run away from home yourself A call A Tatiana news when once Andrey Chern told Ulyam that In the morning Tatyana was found dead in bed he moved her body to the basement and what did he not do there I don’t know I grieved for six months and then they came to me again called for himself enter into the finger ease your soul, the court will take into account that it is murder it was unintentional no, let God judge me, I’m growing Andrey loved him all her life and gave him he brought this young man into the house and he made me serve her when she was dying and not a penny left all of you us for people then don’t count only Dmitry Afanasyevich was good You can’t understand a person’s life children finger and that’s why I Why did you go to Praskov yourself if something happened to you I wouldn’t tell you this forgave I wanted to test my hypothesis today they approached me especially since we you have already reached Tatyana Stolbov former service of the elder aristarchus and you know because it disappeared 30 years ago you compare but the perfume is mine ours how much longer do we have to wait and yet next time when you want to test your hypothesis what other time will there not be a next one I’m not tired of it once, I won’t be yours anymore she saw it as a hindrance to catching criminals Jacob Ladovic how i missed our company and here we are together again I thought why not play music for us today she ryterna I will support yours party graceful 3 small unfortunately today I can’t do it Come on, you’re Jacob Plato revealed now finally left there are always more important things to do than cry for example, delving into the study of dangerous I don’t believe what you mean by remote controls Annabelle wanted to decide both sides are upset today there is no more terrible person than that who has forgotten how to rejoice finally I’ve been waiting for you for a long time Morrigan Help youtube what mask I had a nightmare again, it’s all from nerves I’m not a drinker or a motherwort The doctor died more than a year ago maybe you can calm down and not torture yourself Prepare a dress for me, maybe I’ll go to the city will she accept me someone who will take my place with the ceiling elon it is Anna Viktorovna please steal for inhaling that say anything someday and your voice and hear yours great-grandchildren today is june 6 1894 weather wonderful and me and Andrey Petrovich voices, dry, so unpleasant that in so to persuade you have a beautiful voice and it seems so for the first time Good day gentlemen, I can and will do it everywhere Mironov it’s me it’s good that you are here I came to you on special business, they say your gift has returned, you won’t refuse, help I need to talk to you, I apologize, it’s been a long time I do not provide this type of service I beg you, I implore you he has no one but me and they have no one I’m trying to communicate something very important. I know for sure she is Victor, help me it’s good to wander and you record the process she is forced to leave you for a while as you wish as you wish, and the son of Van Gleb served as a zemstvo official he went to the doctor last fall sick the neighboring village and I will never return the carriage with horses was found two days later in the fields by the beacon only in spring when the snow has melted, I sympathize with you terribly I started to lose my child, thank you, but I I’ve already suffered my share, only root has been here for a month now Vanechka began to come to me every day night comes in a dream as if he wants tell me something very important is calling me manning Mommy and you, didn’t you die a natural death? the boy killed him and until we find the culprit, his soul won’t calm down ok I’ll try to help you she’s quite the spirit Just monolith you here let’s do it here who is burning for us your strength is this outfit Anechka’s wife died, they have no children it was so and I couldn’t get over her death I was escaping from the grief of work by rocking my child there is no Kuzya horse started the thread is long i am so thin kolkata and thread but of course where am I what kind of hen am I I’ve been sitting here too long, it’s time for me to go home forgive me for telling you nothing said that you were an angel, I would really like you helped God bless you Andrey Petrovich says nothing, I do everything I understand it’s her job to keep the secret, it seems closer to men secret well how did it come mother told you to express something No, the doctor didn’t say anything about it Let’s eat, mother, otherwise we won’t have any strength incoherent stupid niche on the oak the last one came half an hour ago Mrs. Samsonova, they sent for you, what happened? you didn’t say it right away I still have things to do where are you in such a hurry to get things done? maybe you can at least tell me what kind of Victor you are constantly going somewhere you have become secretive and don’t pay any attention to me no attention Well, why is that? You always come back I just have urgent business in the city 3 now the most modern women you work for ryabushinsky you owe me understand and the problem of the modern woman She must have fallen and thrown herself there or helped after the doctor died in the rain is completely wrong I’m going crazy, I’m getting more baths, version look A wipe the lens was heard in a special chest and I’ll take another 100 photos of the bag don’t forget very well that same one yes the reaction still works or take it, they bring it from St. Petersburg, I’m glad to see you It’s just a pity to see Antonovich the circumstances of the meeting are not very pleasant so we don’t meet any other way let’s get to it now who is this person installed Antonina Gleb married no widow her son ivan glebov zemstvo doctor needed ask It would be good if it crashed about a year ago back the horses carried away there to commit suicide similar not similar the body is needed urgently the doctor killed himself manage shower where to hurry now Yes, only on a clear day this Mironov and sent to the next world to Agafya maids Gleba you seemed that the lady went today this they expression and now not even three hours have passed I advise the police to sort everything out in this case, I’m sure he won’t let it go Electron has absolutely nothing to do with you here good side hello what happened unfortunately yes tell me met with Antonina Gribov today how do you know that? Boil it a couple of hours ago his body was found behind the settlement and the enemies are an accident they pushed her with a share, why did she come to you? came to help asked for a scene talk to him and help him Anna Viktorovna could you have to be careful who knows may come to you with something similar You shouldn’t help everyone by asking you know how to connect it’s up to me who to help and who not to help why did I let her go she was so excited, don’t blame her myself You are not guilty of anything, I ask you at least today don’t be sick to the city 1 will someone walk you home chair Andrey Petrovich blood means change worry that is Zaraysky’s dear serve here served as the widow of Gleb war the kingdom of heaven has long been in the economy and on I must have been here for almost two years when the son and the krapov were your honor how Mrs. Glebova suffered at first I hoped he would come back, but when should I explain? the body was found almost every night was a now the doctor’s office is like a museum everything is as it was with him, mistress strictly forbade entry here the schedule once disobeyed and they almost kicked me out who is this maid two of us clear I won’t disturb you, Alexandrovich, I’ll come to you again burst into tears see managed to find out time of death I suppose judging by coagulated blood three to four hours back this is the most important question I’m worried about whether it is itself or not and I ask you to help, closer, closer, here look, see this wound this hematoma suggests that rather all was on the right will strike some blow with a blunt oblong object because if it was just a fall of the blow flat stone that character it would be these murders are a completely different calp undoubtedly . on the way and soul and only one is done my heart felt it was not good, that’s true it turned out to be a number of numerologists it is to this It has nothing to do with the matter, so please don’t spread rumors about you when did the owner last see it like that that’s why she went to the Samsonovs for lunch do you know why young barney economics the people served and where was she at that time here I was obsessed with not being and the household Mother usually got busy by seven in the evening I was returning and I had already prepared the samovar I put it there and then it was gone and gone in the yard you came running and said that I can have flies see doctor’s office our doctor the best would be his departure was very much loved by They even went to him from the province everything here remains as it was when he was alive His mother took great care of his memory I suppose everyone had a mother and son attached to each other however the doctor is a lone wolf young man maybe some love interests were Ivan Ivanovich was decent the man saved human lives for me when he was up to some charade, how do you know that? I asked him to help me, that’s it I didn’t see the tool to save it I arrived sick or here at home as if his life all here thank you for the idea to watch more and his Shura gloomy with the doctor kept silent don’t stick your nose into their business you’ll blab, okay, goodbye to them keep your mouth shut or else You’ll be the one begging on my street understood kitchenette not on gleba reveal spirit antonina gleba reveal stuffiness Yes gold milf confirmed that the widow died she was killed violently by being hit with something on the head and threw into a ravine so that we It seems you wrote it off as suicide to the truth on enter Well finally, how long can you fix one? lamp let there be light thank you let there be light I asked the neighbors Gleb didn’t know him did not cause any trouble and was not in debt and in general she didn’t have many enemies I can’t even imagine that someone had motive to kill her and you didn’t succeed find out and the maid the police boy claims that Gleb la after lunch went to samsonova and also I looked at the doctor’s office drawers for there are not enough tools, a scalpel but the doctor could have simply lost it himself but not It looks like the room is in perfect order the servant says that Gleba is in I didn’t let anyone into my son’s room damn electricity if you think I don’t rule out that she took the drops She came to see Victor today and asked to help her talk to the deceased I heard about my son, everyone is already gossiping she told victor an and we are waiting for her son killed perhaps the widow realized who the killers were and went to take revenge on him but it seems like no one has been killed yet, thank God I hope so too, and take a look The doctor found the body earlier in the spring in a terrible state, but on the head found an elongated hematoma like widows exactly when they thought that he hit his head when the laurel fell but if we assume that he was killed and the widow found out about this and went to take revenge he could be a killer with her 1 likes tomorrow you need to go to samson maybe they will shed some light on this dark case she’s so glad to see you hello Polina, I was just passing by and thought find out how you are doing thank you all Okay, yours was delivered just this morning book to some kind of him that’s it yes I already and forgot how much should the set choose absolutely free but if I I’d like to chat with my deceased Grandpa, you will help me with this I’m sorry, I didn’t mean to in any way you are simply offended by the whole city only about that’s what he says and I believe in such things I understand, I just have a headache every time when it comes to your wonderful gift yes I understand I promise more I will never ask such questions questions only if you don’t want to it’s just awful to talk about this topic I wonder how everything works in the afterlife world I’m afraid I can’t tell you anything can you really ask everything? simple you feel that is questions which you shouldn’t ask how much of it in the hall there should be 2 rubles 45 kopecks forgive me again, I feel terribly embarrassed I wouldn’t like to lose yours location and you forgive me and in the company gets angry and 3 to you in a few days yes yes and at the same time tell me how you like the book I scrolled through it and it seems to me there is a lot here curious I’m in a hurry what is this in the heat of the moment yes, you should have had the tome long ago known for riddles you say Unfortunately I don’t have yours an extraordinary gift so there is no answer I can’t do 1 book at a time I’m in a hurry like the next time, I’m very sorry now I’m going to the heights of the book Samson widow Gleba worked as a housekeeper and not for nothing but a smile his death was given and who is this samson phoenix went on him before gold industrialist recently moved from Yenisei province malt his wife Anastasia Petrova born especially for this through the tailor made a good portion tailor where the needle goes, the thread follows and someone started can you wait for me i treat u the doctor changed and of course I will go with you I will wait for you and dear math is true but it’s beautiful wonderful sincerely scandalously new you wrote beautifully boredom of family life cooling of spouses in marriage there is no opportunity for a woman do something useful because of social prejudices but marie timofeevna be prepared for you all the Domostroy fans will pounce and after that the fight will start better than the origins I I think so too and believe me we will fight I will lead you I won’t let anyone offend me, so I agree with you by me what a modern woman needs some business maxima fiona I confess to you if I were with you for days It’s been a long time since children have been cooking vinegar-ba so you weren’t married alexey Yegorovich, I’m not inclined to family life. life does not need a wide field of activity space poland inspiration i think you would be funny husband that i had because it’s not boring well who knows precious and Stima Fiona, who knows? when did you propose, madam? Glebova I work with the death of the doctor and I felt sorry for her she was left with just one book and even you were without means of subsistence I know the doctor, of course, when I was still lived with my father he often depends on your father I didn’t really make friends if anyone Of course I always got sick because they didn’t send me he was a wonderful doctor will there be an illness he could have cured us and we had guests he was driving that the judicial investigator is mine assistant anna viktorovna mironova we are here on the case of Mrs. Gleba Lai yesterday her body was found in a ravine not far from your house you already what a grief poor woman first son now yourself you sit down I know she helped you you were satisfied with the farm conditionally the woman from the housekeeper is slow and this one seemed to be Nastenka kept Nastenka at I am so compassionate It’s strange but Samsonov’s article is not at all loves her husband bi-2 transfers he seems like such a gentle person Anna Viktorovna’s appearance sometimes it can be deceptive why was I there I need this marriage no more money many would consider this reason sufficient anastasia petrovna says that the doctor often visited her father’s house he lives here not far from the village let’s visit his father anastasia do you think he might know something else? patients know about their being korra much more than the doctor and the attack consecutive tell me dear peter said shamin lives here that’s right, your honor, that’s what it is neighbors you will be a coachman he served somehow his guests cleared it out somehow and Antonina came to his expense Glebova I don’t know anything but my eyes speak you know, you just don’t want to talk she came to see him when they had a row about fastening in the stable it was audible although we had a fight I don’t know, there is no habit listen to that therefore She jumped out angry and left for both of us. definitely left definitely-definitely in my own eyes because how did you know about this? chris repaired injured how can my doctors not remember different was small do you know what he taught in st petersburg capital stas but preferred to return to hometown was not of local caliber man I offered him my clinic if the whole province were to open it, it would go aus refused to be modest the main problem of a kind-hearted person the suspension joints are climbing forward noble people are left behind need to attack so you can lines grandma do not forgive this is your child his knees to be born my boyfriend you can’t do that to me, it’s the same as modernism tell Mrs. Gleb the mother of the deceased the doctor came to see you yesterday and how came and went nothing it lasted famous quarreled to find out something how much did the apprentice axle tell I’ll kick out the scoundrel so that the parties what am I nick she asked and I refused she in tears here began to moan doctor how much he helped us but what did I do to enrich ourselves or something I myself can barely make ends meet so I kicked her out By the way, I saw how many times she came out here to reveal seems to be a tailor’s craft passed these Well, now I actually take fewer orders Thank God I took an x-ray and it helps it was said that you will take away the region of your son there have they simply forgotten about Kim and his the child’s mother didn’t believe him how much I fell many allow him to leave I will only work twice as hard let me just say I agreed that I didn’t man what does it mean how much from the master yours exactly your chest you yourself ask him and we will definitely ask, thank you Mr. Fomina at least the apprentice confirmed that it was his child on have a last name I couldn’t name right away covers for the owner but why would Fomin lie? he is a widower and I could well admit it no one would say anything bad about the child I thought Anna Viktorovna said that the child lives with a nanny, he lives with his mother and the mother must have died of mushrooms in family doctor fominykh maybe he they accepted the freak and something went wrong in that case Fomin could do everything blame the doctor and decide on the spot here They tell you that the doctor had a motive a meticulous person wrote down everything names patients carefully kept medical cards let’s go to the house caliber now immediately I am faster than the wind in an instant uncle are you reading? I found my medical journal. Andrey Petrovich to himself after lunch it happened how sweet nick ration is carried away to forget it seems to me you you got seriously carried away a long time ago in Baden-Baden in one young woman and the heart and the doctor who arrived in time were famous did it to her mouth to mouth breathing already then I understood that for the most noble profession now I think maybe I should schedule some visits medical courses Petr Ivanovich and beyond This will happen to you in a week, but why? where is it very interesting to get advice life is to do something useful why aren’t we going I promise myself something other for example until a daughter gentlemen, maybe tea, no thanks, but I’m with We were very pleased with on April need to look at the case all good for the last year and a half if the child It should have been more than a year now to be just on the eve of the doctor’s death original conclusions, gentlemen let me help you who do you know better than me what is here and where lies what records do you need nastya pro hands-hooks I’m going to die now you are in us Wait in the living room I can’t believe my eyes how the fleet night maps found Akulina Baranova isn’t that his wife the very groom Baranov who lives next to Fomin so she is he died from 14 months ago extensive bleeding i’m going to let’s go what gentlemen found what they were looking for more than 100 found Doctor’s office, don’t go in don’t touch anything as you command and the little ones need to go to help, it’s an urgent matter. We’ll clean up the doctor’s office mister investigator villain nothing touch you listen to the pulse of others Baranova died two weeks before how the doctor disappeared laziness everything fits together a bunch of sheep a healthy man would be good for him one blow was enough to see a doctor he knows the local roads firsthand and catching a carriage in a snowstorm is a once-in-a-lifetime task for him spit think and balloon you maybe me I saw a scar on his arm, well, it seemed like scalpel cut besides, we know that Gleb is his came to the fireplace that evening rams lives nearby so he could see and know where did she go next A llama you are here What’s happened and I don’t understand wiki hurry up where is my house I’ll listen to what they write, listen to one the young lady still hasn’t worn a tailcoat in three years managed to give the man an heir and protests turned into the house of the dead Gleba I am the only one with you weighed pancake yes already night almost your hydrogen what have I done to deserve your visit late knee your wife is sure she didn’t die kingdoms and heaven you will have to pass with us why is that better not to resist otherwise we will have to use the force of the yakups and aquaton I grab please explain and what’s going on here your coachman suspected of murdering his doctor mothers detained pending investigation circumstances as otherwise why would you tell him saw Mr. Baranov the day before yesterday in the evening when the widow Gleba vocals I came to him, but he wasn’t home I just wanted to visit my daughter, I thought ask him to bring me and I knock knock to him and there was no point in it in the world with empty talkers I think you are so so are you sick of slandering me like that now? how much how much I want here and the swastika the first half tell me who is right me or that one shaggy the day before yesterday evening I went to him I knocked but he didn’t open, he’s such a god not remembering means you confirm mine words confirming became his plot they call from where you don’t need don’t need 1 we need to call the fire brigade do it capture as here it is there no need for feeding even records doctor I want you do it because of her we want to find him at the private police I’ll tell you the storm on your feet so that it’s not a courtroom fast It’s not my fault, I’m your nobleman, here you go cross here is the cross for you first never on the widow’s hand will be raised she is a doctor and especially a holy man is a holy woman yours didn’t help we all understand the doctor didn’t could help your bullets did not save her and you decided to take revenge on him, admit it you get some relief but I’m to blame for it Death to me, the midwife said, I feel sorry for the doctor, but I don’t I listened and thought everything would be okay when Akulenko arrived with my blood and went in the doctor said that she couldn’t be saved the child is alive, then I have a son thanks doctor how to do now as i do He gave the neighboring one to his sister village well where is he I’m not a woman I have we saw no breast to feed him mother with a share of Fomin will not give all this the child so nobody knows there are rumors that it was said about the foot somewhere his mother died, so he conscience took him to itself a long time ago I can’t say for sure last fall and Kolka innocent my dear tell me where have you been that evening when the widow went to the ball visited Fomin Tom was at the evening myself dorykh o or and what then Fomin says that there was no you and him apprentice Kolka confirms yes the devil I know them, maybe the sound is like you on me, but or they want to get rid of it come in later mister navigator me sent to tell you to go urgently to house of widow Glebova in that ambassador lady young beautiful I’ll go with you who shave stay here the interrogation will end treason flour couple ribbon ram solis abscissa sounds beautiful especially earlier arrived I wish there was something to thank for here she is left good night Andrey what happened me I’ll save myself Agafya tried to burn papers Doctor Glebov we have children succeeded we almost don’t have the master to save something Schulz good night tear off where now she ran away I tried to chase but she seemed to have a swan parting look what i found agafya lost I really didn’t want a 4 month old baby so that it becomes known, but why? it was to burn everything well most likely she was illiterate couldn’t so we want to explain your map for similar grass how did you end up in this house at such a time late hour as you can guess we asked to come here tell me why have you been serving here for a long time? coins of the ussr 2 entries and the murano was twisted by the doctor and strongly I was afraid that you would find out about this, go ahead think like an offer for a child from a doctor it became possible for example look conceived looking if agafia show up and let me know I obey your honor she restaurant you know how I immensely I am glad for your help and appreciate your participation in investigations new then we arrived in Gleb’s house you are in the middle of the night it is dangerous well what to expect with you if I didn’t have time do you like 5th heaven no no what are you not you should thank me good night good daughter what were you looking for here I’m like Plato here we will excite, we will catch and put in the yard in cabinet for which I am not guilty of anything so what is the main thing and what are you for says a year ago you were pregnant lost a child and it’s true ours You’re not smoking any of ours here written to live your life his this is a view and tell about it not to you judging everything is so easy for two people broke down how he even wanted to marry me He just found out about the baby wallet it’s nothing something simple You’ll see how things will heal on their own with you and me the wounded man demanded he knew about it he didn’t have it he didn’t tell me anything, he gave me this case It only seems appropriate to me that this is the old hag figured it all out herself Once I was cleaning and climbed onto a chair or wipe he pushed me, as if by accident and fell and lost the baby buy this there was no peace in the world and I wiped two I was sick for weeks at that time Ivan went to that cursed village disappeared if you say that antonina glebovo why is your child’s death to blame that she didn’t leave because of knowledge when the doctor all the spirit of that disappeared from her mice I couldn’t take a couple of steps, I gave up cried couldn’t sleep at night who was she I’ll leave it like this, it seems to me that she was scolding yourself for your sin then The baby stayed to rest, to her joy now the whole world is alone you’ve finished your studies, you’ve caught a cold, maybe he’s not there she didn’t ask for forgiveness I wouldn’t kill red bottles let’s talk about what the hell you are Baranov is accused of murdering Gleb immediately section but I know what I’m thinking about, I can say what are we lying about? but he was home that evening conscience me husband of which was said that I collected at your instigation and here it is goes to calm her down, can’t do this, that’s from will calm us down a little bit if I add it, it seems to have calmed down now you’ll become very quiet, your lips don’t roll it out or else with me you will go for perjury I wanted to understand, so here you go, sassoon, you’ll take it away Give it to Nastya personally if anyone else except and will see your path understood went tell me uncle this is definitely what you want If you changed your mind, it’s not too late refuse no no I want to know everything the secrets of the human body penetrate the riddle of life from the map so I hope the doctor won’t help me with this I will refuse Pedro glad to see you bypass not enough product good morning on face on you by the way I’m already running no darling I’ll be waiting for you in a week also a common cause you see, that’s what I would like to do some donations for your needs the position here is not very close to me you are small . She said that today according to your anatomical theater will be to be carried out to hide her unfortunate body which Gleba could be present at this peter vegetable pie is too loud umbrellas chesky theater we only have a morgue parade happens but then for mercury spectacle no not really no yes this account is not please don’t worry my first sweet well what am I asking in that case right now powder and if of course I could turn around quickly and manage to kill the bread his but ram to do it was where easier Of course I had no reason to kill the coachman that she is not guilty of the death of his child what if she suspected that it was he who killed her son and came expose and then everything comes together and this cut on his hand exposes him she rushed at him with a scalpel and managed to hurt but we only assume that Gleba you could have taken a scalpel from them voyage son but it cannot be ruled out that Agafia killed the widow but the doctor is here definitely didn’t kill, it’s quite possible that she did the doctor didn’t kill the sheep, maybe we we will never know who is guilty his death but the difficulty of the rise as if it didn’t sound like we were lucky today and were the deceased had no relatives and there were no about taking permissions to hide body let’s work for science interrupted look I’m making a cut carefully, give it free rein pins immediately boot tell me nerve good no here dollar don’t like wallet took 1c Guy, let me come in, a note from yours Father doors cash proceeds transfer So who’s on the berry bridge? the guy is feeling bad why are you standing there like a table with water what are these parts of boiling water some of me managed to extract from under the nails knocked out I wonder if it is possible to find out what it is I have a friend of mine for the material by the way, they reign, they could see something there in the hallway I didn’t consult the owner of Taliyah he said that most likely it is so called fish you are a burrowing velvet yes this is an extremely rare kind of junk glory Thank God we now have at least some the clue was that the killer was in red fish there in arhat I wonder why he would so dress up where he was going that evening is she red velvet more often Ladies’ dresses are sewn at Agafya’s like this there certainly couldn’t have been a dress from somewhere no money ohana victor sing this damn did not satisfy there is uncertainty in our area two suspects and prove the guilt of none of them thoughts splatoon what you don’t I’ve been meaning to tell you about my father’s condition for a long time tell one night i was returning from however I was walking home and there was a bookstore near this one who did you think I saw the color of our mysterious forensic investigator yakov Platonovich and he knocked on the door and the door the door opened and some woman said I I’ve been waiting for you to come in for a long time I came in, I beg you, well, Anna Viktorovna forget about him he’s not worth you i don’t I know what he said over there about him disappearance absence but I absolutely I’m convinced he wasn’t honest with you before the end of this bookstore is working on lines young educated very beautiful woman I won’t be surprised if he ticket not for a secret meeting of all on the lan 3 you well let’s not me not the navigator’s inner torments are interesting You can’t even imagine how happy I am I would give everything in the world to hear this your peace of mind suddenly remembered that you were a little before back he made proposals viktorovna Anton Andreevich and then really I was very sick at heart knowing that you did it out of the most sincere spiritual motives and I never I’ll forget, I need buns for the pastry shop where are you going my soul he sent a note to visit daddy that he is not well, so why should we? breakfast him together it is not to go Alexey I would really like to give you now sew my dove let’s talk for six months now men from Everything seems to me like you’re hiding it You don’t trust your husband for some reason get busy I try, I do everything for you your daddy his debts his flesh bills are written out but you won’t lose much money that’s right it just seems to me daddy your sons don’t know about this money he abandoned his business in taverns he’s wandering around, getting drunk, it’s not my fault I don’t blame you I just think maybe I should stop give money to your daddy for a while don’t do it until it forms then if he goes even lower, he will disappear completely If you don’t want me to go anywhere, I won’t go anywhere. I didn’t take another step without yours just don’t leave him without permission your help you are right I am a weak man it is said that whoever is without sin, let him be first throw a stone took on helping so help and don’t judge and not only that you my wife took for yourself then everyone who is near and dear to you just do me a favor if you do me a favor hiding something bring it and we know and I will not forgive betrayal she you have no idea how i am I made a fool of myself here was it worth it francevich bring in searched do I slapped a small cut on the as jar but thanks to your confusion the doctor found a new snail about i immensely I am grateful for this at least some debt tell me uncle why does a man always lie woman zone it depends on different reasons for example, you love one and confess her in his feelings and at the same time has an effect signs of attention from another how is this possible, it’s just meanness and above all it is extremely simple it means that I like this and the other than you you ask if it hits I am such a soul and twitch in life there are situations that are very difficult and sometimes not allowed and you love one, you are forced to live another life or vegetables 6 in front of the whole world for by someone just so that no one else guessed who yours really are your heart belongs So we filmed it as if to get a breath she herself is straight are you okay good night see you off No Anastasia Petrovna, come to see you, madam Mironova Anna what a nice surprise please me forgive me gentlemen, I came to you without an invitation It’s okay and I’m so glad to see you We rarely have guests, so what are you standing there for? please sit down thank you let’s drink tea what do we owe part again see here madam is served section to your wife probably pieces seriousness investigation no of course not this is purely a ladies’ question I think you will find it interesting at night very interesting way last time Anastasia Petrovna was like that on you beautiful dress i would like to know who I would have come out to you now on the row above all praise you have incredible taste you know completely I recently returned from Paris and I can say that even there that you are a fashionista give die for with ease add you are exaggerating not at all no, Zatonsky is all that’s talked about your toilets still how lucky he was with husband wifey points souls and do me a favor show me ladies world new others their on I with joy about such happiness red velvet is rare and expensive fabric We need to interview all the tailors in the city if they ordered a dress from it, then for sure remembered or have already asked yaks Platonovich Zatonsky with this fabric none of the tailors it doesn’t work and the Fomins were interested in is it worth it and previously worked only with shirt my date with loops and now and completely I have abandoned my business and nevertheless I would like to talk to him again about something Velvet hides a good reason pay him a visit for one of the under master let’s talk anton address you Today Sana Quiz saw Yakov Platonovich, would you leave her alone? take care of old wounds I understand what it is It’s none of my business but you don’t love her anyway it seems like you love Shouldn’t you know that I don’t have any I don’t have a chance, I’m not a noble commoner she is absolutely not a match for Viktorovna Andreevich will feel it and believe me I am grateful that you have been there for all these years longer to play with a faithful friend and heart and sq platon anna viktorovna the best of all the women I have ever met her life and she is worthy devoted love of the greatest happiness even if not with me look at the luxury that was woven your husband is really very Fedor happy nastasya petrovna Unfortunately, the festival needs more than just drags toilet 8 is the most luxurious amazing fabric do you want me to give it to you I will give why Alexey Eduardovich gave it to me as a gift our button with the eye but I’m not a resident you again often I got married the father’s wealth is his business, even so not bad, there was no money at all and then this party I did not dare to refuse handwriting not you shawl Although their in a hundred pro and the heart driver does not sound I need to go to my father otherwise something will happen that I am not a part of I’ll survive the spin, one thing won’t let me in, it’s watching he might be jealous of my every step if you go with me agree let’s say we’ll go to the milliners for a short while tell you dress what do you say it’s time as soon as not 1 part no one in zadonsk such platinum from all into matter and lead and they decided to take the dress to St. Petersburg Nastenka and a vest for Petr Gavrilych there is from deposed to Anna Viktorovna please come back soon I we run from roses I begin to yearn I absolutely cannot exist without her impossible as the priest said so don’t do it until you’re out of your mind it will be as the owner said I promised you money so you are a mother of rainbows top she will somehow be an innocent person That’s right, everyone, it’s time to go Sashenka Sashenka 1 my Sasha where are you going, even though it’s your shelter give the boy back to me Anastas Petrovna kill Now I won’t give Sasha to anyone else so pass on to your father the memory of what you are like why is everything here ul yes boy give The husband didn’t come for the above reason what did you swear wasps don’t care a now with IMT they decided to hand it over without a so if alexey yes i don’t care i I won’t let go of Sinku again husband’s name is your work in the field then install the program like this it’s your guys Stasik this is an idea and why is it your father I just mentioned the field what’s wrong with you anastasia petrovna it turns out it happened that night when Doctor Propane you killed to hide your secrets and you knew everything and covered for your daughter in time I somehow killed the man who saved me me and Sasha, the doctor got caught in a thunderstorm, maybe they didn’t carry him he fell on the enemy and the widow Gleb and you are in this style because she somehow found out that you were her killer I didn’t kill anyone, son, I’m not guilty I would be crying right now if I were you they broke her skull and threw her into a ravine your father and his assistant slandered the groom of the baranova he will go instead of you hard labor cool that’s true why did you do that go and negotiate with us and even more more more more that’s wonderful that’s all I let it slip I’m adding you legs were born healthy strong boy a real hero visit as soon as possible home I don’t understand at all how you feel about her situation and we were let out of the house, the doctor didn’t notice let’s tell you quickly what you can do there your cart we even smile smile smile You a second of birth but now doctors thank I am not a doctor in the East Thank you but about what such are just don’t tell us about what you have something happened to us Of course I understand everything I suppose it was you who killed him, yes gentlemen I think the figure should be goji yo red velvet of the same one from which your dress is sewn I will give you a present you won’t prove anything what is the truth to say how many prisons he doesn’t want me to tell you I’ll tell you everything-everything how I understand that heap has nothing to do with this matter true, very true, it has nothing to do with you advised me to point it out to him for you the highest and you don’t be afraid tell everything as it was proven so like tomatoes I would from it came out here is the key cheater now and itself followed her red pitted velvet arrived here are the Etruscans that very reception was what the respondents were on there is no more room for denial I advise you to tell the whole truth will ease your punishment what I won’t tell him in the suburbs Okay shoemaker, we didn’t fall in love with you. my friend was very unhappy, he was not rich and we Now and because I went to Moscow, there is one there they stabbed me and then I realized that in position to take then the fourth argument in the room sapir to the street I signed up to go, but when the time came midwives from the village of asane the primal when we exited we said that nasa tenge Well done, he’ll strangle me then I’ll run away from focus will have to be how good that we met so dearly left is good he is happy that he helped Sasha come in come into the world a feeling of horror you said he got A man’s duty is to grant him the kingdom of heaven how i stuffing was born i didn’t put that when taking a photo, take a place to collect and let go then for six months I’m like in the city came and my father started to tell him praises to take a photo of the widow brought you they were afraid, even though they themselves were not tired of getting married that the father wants to take care of your son agreed my soul what is going on here why did the police tell me petra they said they arrested me and this one is exactly what I am with you the patron of situations please let’s go out of the house you look after Sashenka but Connors Well, Antonovich, congratulations the case was solved for them, there is no one. I just can’t understand why Fominov had to be killed Gleb even if she came with accusations in the death of her son but what are her proof who would believe her is needed there was a housekeeper at anastasia samson you I’m sure you understood that there is something extramarital son started blackmailing him that everything she will tell her husband that he will allow this already minutes besides who killed once I will definitely want to kill again I know exactly how Anna ended up here Viktorovna let’s ask her, she’s still here So what does this mean? 4 isn’t even a scandal it’s a disgrace never I will never forgive you for what you dared to deceive me, I am blind your father turned out to be a lost man it turns out he’s kind torturer and murderer and diberis and on we are going home guilty . poster Let’s the country is victor and why did you suddenly decide go to the house of samsung and went to the place crimes comrade there was a scalpel on which there were for a long time particles of that very red sobbed beard adams as if you are very close to it place so I decided to go to them and see if any of them have an outfit from the same material as you found the scene of the murder and even without hurrying It’s good that they agreed on everything, yes I’m also wounded for them Now the child will grow up with his mother maybe anastasia will love her husband and do you think that it is possible to fall in love a person just because he is kind and noble, why isn’t the speech ready? crazy passion rarely leads to fortunately she is a calm attachment and trust opposite I don’t recognize you Anna Viktorovna about and you speak as if you were the headmistress of a girls’ school

    By Amjad Izhar
    Contact: amjad.izhar@gmail.com
    https://amjadizhar.blog

  • Exploring SQL for Database Management and Data Analysis

    Exploring SQL for Database Management and Data Analysis

    The provided texts offer a comprehensive introduction to databases and SQL, covering fundamental concepts like tables, columns, and records, alongside essential SQL commands for data manipulation and querying. They further explore the role of SQL in data analysis, outlining necessary skills, qualifications, project work, portfolios, and internships for aspiring data analysts. Advanced SQL topics such as joins, subqueries, stored procedures, triggers, views, and window functions are examined in detail through explanations and practical examples using MySQL. Finally, the material transitions to PostgreSQL, demonstrating similar SQL functionalities and introducing more advanced features like case statements, aggregate functions, and user-defined functions, while also discussing the importance and top certifications in the field of data analytics.

    SQL Fundamentals Study Guide

    Quiz

    1. What is the purpose of the GROUP BY clause in SQL? Provide a brief example of its syntax. The GROUP BY clause in SQL is used to group rows that have the same values in one or more columns into summary rows. It is often used with aggregate functions to calculate metrics for each group. For example: SELECT department, COUNT(*) FROM employees GROUP BY department;
    2. Explain the difference between the WHERE clause and the HAVING clause in SQL. When would you use each? The WHERE clause filters individual rows based on a specified condition before any grouping occurs. The HAVING clause filters groups based on a specified condition after grouping has been performed by the GROUP BY clause. You use WHERE to filter individual records and HAVING to filter groups of records.
    3. Describe the main categories of SQL data types discussed in the source material. Give one example for each category. The source material outlines several main categories of SQL data types: exact numeric (e.g., INTEGER), approximate numeric (e.g., FLOAT), date and time (e.g., DATE), string (e.g., VARCHAR), and binary (e.g., BINARY).
    4. List three types of SQL operators and provide a brief explanation of what each type is used for. Three types of SQL operators are: arithmetic operators (used for mathematical calculations like addition: +), logical operators (used to combine or modify conditions, like AND), and comparison operators (used to compare values, like equal to: =).
    5. What are SQL joins used for? Briefly explain the purpose of an INNER JOIN. SQL joins are used to combine rows from two or more tables based on a related column between them. An INNER JOIN returns only the rows where there is a match in both tables based on the join condition; rows with no match in either table are excluded.
    6. What is a subquery in SQL? Provide a simple example of how a subquery might be used. A subquery is a query nested inside another SQL query (such as SELECT, FROM, or WHERE). It is often used to retrieve data that will be used in the main query’s conditions. For example: SELECT * FROM employees WHERE salary > (SELECT AVG(salary) FROM employees);
    7. Explain the concept of a stored procedure in SQL. What are some potential benefits of using stored procedures? A stored procedure is a set of SQL statements with an assigned name, which is stored in the database. Benefits include reusability of code, improved performance (as they are pre-compiled), and enhanced security by granting access only to the procedure rather than the underlying tables.
    8. What is a trigger in SQL? Describe a scenario where a trigger might be useful. A trigger is a stored program that automatically executes in response to certain events (e.g., INSERT, UPDATE, DELETE) on a particular table. A trigger could be useful for automatically updating a timestamp field whenever a row in a table is modified, ensuring data integrity or auditing changes.
    9. Describe what a view is in SQL. How does it differ from a regular table? A view is a virtual table based on the result of an SQL statement. Unlike regular tables, views do not store data themselves; instead, they provide a customized perspective of data from one or more underlying tables. Changes made through a simple view might affect the base tables, but complex views are often read-only.
    10. What is the purpose of the ORDER BY clause in SQL? Explain how to sort results in descending order. The ORDER BY clause is used to sort the result set of a SQL query based on one or more columns. To sort results in descending order, you specify the column(s) to sort by and append the DESC keyword after the column name(s). For example: SELECT * FROM products ORDER BY price DESC;

    Answer Key

    1. The GROUP BY clause in SQL groups rows with the same values in specified columns, often used with aggregate functions for summarized data. Example: SELECT department, COUNT(*) FROM employees GROUP BY department;
    2. WHERE filters rows before grouping, while HAVING filters groups after GROUP BY. Use WHERE for record-level conditions and HAVING for group-level conditions on aggregated results.
    3. The main categories are exact numeric (e.g., INTEGER), approximate numeric (e.g., FLOAT), date and time (e.g., DATE), string (e.g., VARCHAR), and binary (e.g., BINARY).
    4. Arithmetic operators perform calculations (+, -, *, /, MOD). Logical operators combine conditions (AND, OR, NOT). Comparison operators evaluate relationships between values (=, <>, >, <, >=, <=).
    5. SQL joins combine rows from multiple tables based on related columns. INNER JOIN returns only matching rows from both tables based on the join condition.
    6. A subquery is a query nested within another query, often used to provide values for conditions in the outer query. Example: SELECT * FROM products WHERE price > (SELECT AVG(price) FROM products WHERE category = ‘Electronics’);
    7. A stored procedure is a pre-compiled set of SQL statements stored in the database, offering benefits like code reuse, improved performance, and enhanced security.
    8. A trigger is a database object that automatically executes SQL code in response to specific events on a table. Useful for auditing changes by logging every update to a separate history table.
    9. A view is a virtual table based on the result of a query, providing a specific perspective on the data without storing it directly. It differs from a regular table by not holding persistent data.
    10. The ORDER BY clause sorts the query result set. To sort in descending order, use the DESC keyword after the column name in the ORDER BY clause (e.g., ORDER BY salary DESC).

    Essay Format Questions

    1. Discuss the importance of data types in SQL. Explain how choosing the appropriate data type for a column can impact database performance and data integrity. Provide specific examples of scenarios where different data types would be most suitable.
    2. Elaborate on the different types of SQL joins (INNER, LEFT, RIGHT, FULL). Explain the conditions under which each type of join is most useful and provide conceptual examples illustrating the results of each join type using sample tables.
    3. Analyze the benefits and drawbacks of using stored procedures and triggers in SQL database design. Consider aspects such as performance, maintainability, security, and complexity. Provide scenarios where each would be a particularly advantageous or disadvantageous choice.
    4. Explain the concept and benefits of using views in SQL. Discuss how views can contribute to data security, query simplification, and data abstraction. Describe different types of views and their specific use cases.
    5. Compare and contrast the use of subqueries and joins in SQL for retrieving data from multiple tables. Discuss the scenarios where one approach might be preferred over the other, considering factors such as readability, performance, and the complexity of the relationships between tables.

    Glossary of Key Terms

    • Clause: A component of an SQL statement that performs a specific function (e.g., SELECT, FROM, WHERE, GROUP BY, ORDER BY).
    • Data Type: The attribute that specifies the type of data that a column can hold (e.g., numeric, string, date).
    • Operator: Symbols or keywords used to perform operations in SQL expressions (e.g., arithmetic, logical, comparison).
    • Join: An SQL operation that combines rows from two or more tables based on a related column.
    • Inner Join: Returns rows only when there is a match in both tables based on the join condition.
    • Outer Join (Left, Right, Full): Returns all rows from one table and the matching rows from the other; if no match, NULLs are used for the non-matching table.
    • Subquery (Nested Query): A query embedded inside another SQL query.
    • Stored Procedure: A pre-compiled collection of SQL statements stored in the database.
    • Trigger: A database object that automatically executes a block of SQL code in response to certain events on a table.
    • View: A virtual table based on the result of an SQL SELECT statement.
    • Aggregate Function: A function that performs a calculation on a set of values and returns a single summary value (e.g., COUNT, SUM, AVG, MIN, MAX).
    • GROUP BY Clause: Groups rows with the same values in one or more columns.
    • HAVING Clause: Filters the results of a GROUP BY clause based on specified conditions.
    • WHERE Clause: Filters rows based on specified conditions before grouping.
    • ORDER BY Clause: Sorts the result set of a query based on specified columns.
    • DESC: Keyword used with ORDER BY to sort in descending order.
    • ASC: Keyword used with ORDER BY to sort in ascending order (default).
    • Alias: A temporary name given to a table or column in a SQL query for brevity or clarity.

    Briefing Document: Review of SQL Concepts and MySQL/PostgreSQL Usage

    This briefing document summarizes the main themes, important ideas, and facts presented across the provided sources, which primarily focus on introducing and demonstrating various aspects of SQL using MySQL and PostgreSQL.

    Main Themes:

    • Fundamentals of SQL: The sources cover core SQL concepts, including data manipulation language (DML) commands (SELECT, INSERT, UPDATE, DELETE), data definition language (DDL) commands (CREATE TABLE, ALTER TABLE, DROP TABLE, CREATE DATABASE, DROP DATABASE, CREATE VIEW, DROP VIEW), clauses (WHERE, GROUP BY, HAVING, ORDER BY, JOIN, LIMIT), data types, operators, and basic SQL functions.
    • Database Management Systems: The documents illustrate the practical application of SQL within two popular database management systems: MySQL and PostgreSQL. This includes installation (for MySQL), connecting to servers, and executing SQL commands within their respective interfaces (MySQL Workbench, command-line interface, and online compilers for PostgreSQL).
    • Data Filtering and Sorting: A significant portion of the content focuses on how to effectively filter data using the WHERE and HAVING clauses and how to sort results using the ORDER BY clause. The use of comparison operators, logical operators (AND, OR, BETWEEN, LIKE, NOT LIKE), and pattern matching is highlighted.
    • Data Aggregation: The GROUP BY and HAVING clauses are explained and demonstrated for summarizing data based on groups, along with aggregate functions like COUNT, SUM, AVG, MAX, and MIN.
    • Joining Tables: The concept of joining data from multiple tables is introduced, with a focus on INNER JOIN and the importance of common fields for linking tables.
    • Advanced SQL Concepts: The sources delve into more advanced topics such as subqueries (nested queries), views (virtual tables), stored procedures (reusable SQL code), triggers (actions performed automatically in response to database events), Common Table Expressions (CTEs/WITH expressions), and window functions (for analytical queries).
    • SQL Functions: Various built-in SQL functions are explained and demonstrated, including mathematical functions (ABS, GREATEST, LEAST, MOD, POWER, SQRT, SIN, COS, TAN, CEILING, FLOOR) and string functions (CHARACTER_LENGTH, CONCAT, LEFT, RIGHT, SUBSTRING/MID, REPEAT, REVERSE, LTRIM, RTRIM, TRIM, POSITION, ASCII).
    • Practical Application and Examples: The sources heavily rely on practical examples and demonstrations within MySQL Workbench and online PostgreSQL environments to illustrate the usage and benefits of different SQL concepts and commands.
    • Database Connectivity with Python: One source provides a basic introduction to connecting to a MySQL database using Python, creating databases and tables, inserting data, and executing queries.
    • Common Interview Questions: One section focuses on typical SQL interview questions, covering topics like INDEX, GROUP BY, ALIAS, ORDER BY, differences between WHERE and HAVING, VIEW, and STORED PROCEDURE.

    Most Important Ideas and Facts (with Quotes):

    • SQL Clauses for Data Manipulation:“we condition one condition two and so on then we have the group by Clause that takes various column names so you can write Group by column 1 column 2 and so on next we have the having Clause to filter out tables based on groups finally we have the order by Clause to filter out the result in ascending or descending order” (01.pdf) – This outlines the basic structure and purpose of key SQL clauses.
    • The WHERE clause filters rows before grouping, while the HAVING clause filters groups after they are formed.
    • SQL Data Types: The document lists various SQL data types, categorizing them as exact numeric (integer, small int, bit, decimal), approximate numeric (float, real), date and time (date, time, timestamp), string (char, varchar, text), and binary (binary, varbinary, image).
    • SQL Operators: Basic arithmetic, logical (all, and, any, or, between, exists), and comparison operators (=, !=, >, <, >=, <=, NOT <, NOT >) are fundamental for constructing SQL queries.
    • MySQL Workbench Installation: The source provides a step-by-step guide to installing MySQL Workbench on Windows, including downloading the installer from the official Oracle website (myql.com), choosing a custom setup, and selecting components like MySQL Server, MySQL Shell, and MySQL Workbench. The importance of setting a password for the root user is emphasized: “now here set the password for your root user by the way root is the default user this user will have access to everything” (01.pdf).
    • Basic MySQL Commands: Commands like SHOW DATABASES, USE <database_name>, SHOW TABLES, SELECT * FROM <table_name>, and DESCRIBE <table_name> are introduced as essential for navigating and inspecting database structures.
    • Creating Tables: The CREATE TABLE command syntax is explained, including defining column names and their data types, and specifying constraints like PRIMARY KEY and NOT NULL.
    • Inserting Data: The INSERT INTO command is used to add new rows into a table, specifying the table name and the values for each column.
    • String Functions:“there’s also a function called position in MySQL the position function Returns the position of the first occurrence of a substring in a string” (01.pdf)
    • “the asky function Returns the asky value for a specific character” (01.pdf)
    • PostgreSQL’s string functions like CHARACTER_LENGTH, CONCAT, LEFT, RIGHT, REPEAT, and REVERSE provide powerful text manipulation capabilities.
    • GROUP BY and Aggregate Functions: The GROUP BY clause groups rows with the same values in specified columns, allowing the application of aggregate functions to each group.
    • HAVING Clause for Filtering Groups: “the having Clause works like the wear Clause the difference is that wear Clause cannot be used with aggregate functions the having Clause is used with a group by Clause to return those rows that meet a condition” (Source 17.pdf).
    • JOIN Operations: SQL joins (INNER JOIN is primarily discussed) are used to combine rows from two or more tables based on related columns.
    • Subqueries (Nested Queries): A subquery is a query embedded within another SQL query, used to retrieve data that will be used in the main query’s conditions.
    • Views (Virtual Tables):“views are actually virtual tables that do not store any data of their own but display data stood in other tables views are created by joining one or more tables” (01.pdf).
    • Views simplify complex queries and can enhance data security. The CREATE VIEW, RENAME TABLE (for renaming views), and DROP VIEW commands are used to manage views.
    • Stored Procedures:“a stored procedure is an SQL code that you can save so that the code can be reused over and over again” (01.pdf).
    • Stored procedures can take input parameters (IN parameters) and help in encapsulating and reusing SQL logic.
    • Triggers: Triggers are SQL code that automatically executes in response to certain events (e.g., BEFORE INSERT, AFTER UPDATE) on a table.
    • Window Functions: Introduced in MySQL 8.0, window functions perform calculations across a set of table rows that are related to the current row, allowing for analytical queries (e.g., calculating total salary per department using SUM() OVER (PARTITION BY)). The RANK(), DENSE_RANK(), and FIRST_VALUE() functions are examples of window functions.
    • Common Table Expressions (CTEs): CTEs, defined using the WITH keyword, are temporary, named result sets defined within the scope of a single query, improving readability and allowing for recursive queries.
    • Database Connectivity with Python: The mysql.connector library in Python can be used to connect to MySQL databases, execute SQL queries, and retrieve results. The basic steps involve creating a server connection, creating databases, connecting to specific databases, and executing queries using cursors.
    • PostgreSQL Specifics: The sources also demonstrate SQL concepts within a PostgreSQL environment using online compilers, highlighting similar SQL syntax and the availability of functions like BETWEEN, LIKE for pattern matching (% for any sequence of characters, _ for a single character), and various mathematical and string functions. The ALTER TABLE … RENAME COLUMN command is shown for modifying table schema. The LIMIT clause in PostgreSQL restricts the number of rows returned by a query.
    • SQL Interview Preparedness: The final source provides insights into common SQL interview questions, emphasizing understanding of fundamental concepts and practical application.

    Overall Significance:

    The provided sources offer a comprehensive introduction to fundamental and advanced SQL concepts, demonstrating their application in both MySQL and PostgreSQL. They emphasize practical learning through examples and hands-on exercises, making them valuable resources for individuals learning SQL or preparing for database-related tasks and interviews. The inclusion of database connectivity with Python further highlights the role of SQL in broader data management and application development contexts.

    Understanding Fundamental SQL Concepts and Operations

    1. What are the fundamental components of a SQL query?

    A fundamental SQL query typically involves the SELECT statement to specify the columns you want to retrieve, the FROM clause to indicate the table(s) you are querying, and optionally, the WHERE clause to filter rows based on specific conditions. Additionally, you might use GROUP BY to group rows with the same values, HAVING to filter groups, and ORDER BY to sort the result set in ascending (ASC) or descending (DESC) order.

    2. What are the common data types available in SQL?

    SQL supports various data types to define the kind of data a column can hold. These include exact numeric types like INT, SMALLINT, BIT, and DECIMAL; approximate numeric types such as FLOAT and REAL; date and time types like DATE, DATETIME, and TIMESTAMP; string data types including CHAR, VARCHAR, and TEXT; and binary data types such as BINARY, VARBINARY, and IMAGE.

    3. What are the different categories of operators used in SQL?

    SQL uses several categories of operators. Arithmetic operators perform mathematical operations (+, -, *, /, MOD). Logical operators (ALL, ANY, OR, BETWEEN, EXISTS, etc.) are used to combine or negate conditions. Comparison operators (=, !=, >, <, >=, <=, NOT <, NOT >) are used to compare values.

    4. How can you set up and connect to a MySQL database using MySQL Workbench and the command line?

    To set up MySQL, you typically download the MySQL Installer from the official Oracle website. During the installation, you can choose to install MySQL Server, MySQL Shell, and MySQL Workbench. You’ll need to configure the server instance, set a password for the root user, and execute the configuration.

    To connect via MySQL Workbench, you open the application, click on the local instance connection, and enter your root password.

    To connect via the command line, you need to navigate to the bin directory of your MySQL installation using the cd command in the command prompt. Then, you can use the command mysql -u root -p, and upon entering your password, you’ll be connected to the MySQL server.

    5. What are some basic SQL commands for database and table manipulation?

    Some basic SQL commands include:

    • SHOW DATABASES; to list the existing databases.
    • USE database_name; to select a specific database to work with.
    • SHOW TABLES; to list the tables within the selected database.
    • SELECT * FROM table_name; to view all rows and columns in a table.
    • DESCRIBE table_name; or DESC table_name; to show the structure of a table (column names, data types, etc.).
    • CREATE DATABASE database_name; to create a new database.
    • CREATE TABLE table_name (column1 datatype, column2 datatype, …); to create a new table with specified columns and data types.
    • DROP TABLE table_name; to delete a table.
    • DROP DATABASE database_name; to delete a database.

    6. How do GROUP BY and HAVING clauses work in SQL?

    The GROUP BY clause in SQL is used to group rows in a table that have the same values in one or more columns into summary rows. It is often used with aggregate functions (like COUNT, MAX, MIN, AVG, SUM) to compute values for each group.

    The HAVING clause is used to filter the results of a GROUP BY clause. It allows you to specify conditions that must be met by the groups. The key difference from the WHERE clause is that WHERE filters individual rows before grouping, while HAVING filters groups after they have been formed.

    7. What are SQL JOINs and what are some common types?

    SQL JOINs are used to combine rows from two or more tables based on a related column between them. This allows you to retrieve data from multiple tables in a single query. Common types of JOINs include:

    • INNER JOIN: Returns rows only when there is a match in both tables.
    • LEFT JOIN (or LEFT OUTER JOIN): Returns all rows from the left table and the matching rows from the right table. If there’s no match in the right table, NULLs are used for the right table’s columns.
    • RIGHT JOIN (or RIGHT OUTER JOIN): Returns all rows from the right table and the matching rows from the left table. If there’s no match in the left table, NULLs are used for the left table’s columns.
    • FULL OUTER JOIN: Returns all rows when there is a match in either the left or right table. If there is no match in one of the tables, NULLs are used for the columns of the table without a match. (Note: MySQL does not directly support FULL OUTER JOIN, but it can be simulated using UNION ALL with LEFT JOIN and RIGHT JOIN).

    JOIN conditions are typically specified using the ON keyword, indicating which columns should be compared for equality.

    8. What are subqueries and stored procedures in SQL?

    A subquery (or inner query) is a query nested inside another SQL query. Subqueries can be used in the SELECT, FROM, WHERE, and HAVING clauses. They are often used to retrieve data that will be used in the conditions or selections of the outer query. Subqueries can return single values, lists of values, or even entire tables.

    A stored procedure is a set of SQL statements with an assigned name, which is stored in the database. Stored procedures can be executed by calling their name. They offer several benefits, such as code reusability, improved performance (as the code is pre-compiled and stored on the server), and enhanced security by granting execute permissions without direct table access. Stored procedures can also accept input parameters and return output parameters.

    Understanding Relational Database Tables

    In relational databases, data is stored in the form of tables. These tables are the fundamental structure for organizing and managing data. You can think of a table as a grid composed of rows and columns.

    Here’s a breakdown of the structure of a database table:

    • Table Name: Each table has a name that identifies the data it holds, for example, “players”, “employees”, “customers”, or “orders”.
    • Columns (or Fields or Attributes):
    • Columns are the vertical structures in a table.
    • Each column represents a specific attribute or category of information about the items stored in the table.
    • At the top of each column is a column name (also known as a field name) that describes the data in that column, such as “player ID”, “player name”, “country”, and “goals scored” in a “players” table. Other examples include “employee_ID”, “employee_name”, “age”, “gender”, “date of join”, “department”, “city”, and “salary” in an “employees” table.
    • Each column is associated with a specific data type that defines the kind of values it can hold. Examples of data types in SQL include integer, smallint, decimal, float, real, date, time, varchar, char, text, binary, etc.. The data type ensures that all values stored in a specific column are of the same type or domain.
    • Columns are also sometimes referred to as fields in a database.
    • Rows (or Records or Tuples):
    • Rows are the horizontal structures in a table.
    • Each row represents a single instance or record (also called a tuple) of the entity that the table describes.
    • For example, in a “players” table, each row would contain the information for one specific player. In an “employees” table, each row would contain the details of a single employee.
    • Cells: The intersection of a row and a column forms a cell, which holds a single piece of data. Each column in a row will contain only one value per row, which is a rule for the first normal form of normalization.
    • Primary Key: A primary key is a special column or a set of columns that uniquely identifies each row in a table. It ensures that no two rows have the same primary key value, and it cannot contain null or empty values. Primary keys are crucial for linking tables together and maintaining data integrity. For instance, “employee_ID” could serve as a primary key in an “employees” table.
    • Index: Tables can be indexed on one or more columns to speed up the process of finding relevant information. An index creates a sorted structure that allows the database to locate specific rows more efficiently without having to scan the entire table.

    SQL (Structured Query Language) commands are used to interact with these tables. You can use SQL to query (retrieve), update, insert, and delete records in a table. The SELECT statement is used to retrieve data by specifying the columns you want to see and optionally filtering the rows based on certain conditions using the WHERE clause. INSERT is used to add new rows to a table, UPDATE to modify existing rows, and DELETE to remove rows.

    The logical structure of a database, including its tables and their relationships, can be visually represented using an Entity-Relationship (ER) diagram. An ER diagram shows entities (which often correspond to tables) and their attributes (which correspond to columns) and the relationships between these entities. This helps in understanding the information to be stored in a database and serves as a blueprint for database design.

    Understanding SQL: Core Concepts and Commands

    SQL (Structured Query Language) is a domain-specific language that serves as the backbone of data management and analysis for relational databases. It is the standard language used by most databases to communicate with and manipulate data. Initially developed by IBM, SQL allows users to interact with databases to store, process, analyze, and manage data effectively. As businesses become increasingly data-driven, proficiency in SQL is a crucial skill for data analysts, developers, and database administrators.

    Here are key aspects of the SQL query language based on the sources:

    • Core Functionality: SQL queries enable you to access any information stored in a relational database. This includes retrieving specific data, updating existing records, inserting new data, and deleting unwanted information.
    • Efficiency: SQL is designed to extract data from databases in a very efficient way. By specifying precisely what data you need and the conditions it must meet, you can minimize the amount of data processed and transferred.
    • Compatibility: The Structured Query Language is compatible with all major database systems, ranging from Oracle and IBM to Microsoft SQL Server and open-source options like MySQL and PostgreSQL.
    • Ease of Use: SQL is designed to manage databases without requiring extensive coding. Its syntax is relatively straightforward, focusing on declarative statements that specify what data should be retrieved or modified, rather than how to perform the operation.
    • Applications of SQL: SQL has a wide range of applications, including:
    • Creating databases and defining their structure (e.g., creating tables with specific columns and data types).
    • Implementing and maintaining existing databases.
    • Entering, modifying, and extracting data within a database. For instance, you can use INSERT to add new records, UPDATE to change existing ones, and SELECT to retrieve data.
    • Serving as a client-server language to connect the front-end of applications with the back-end databases that store the application’s data.
    • Protecting databases from unauthorized access when deployed as Data Control Language (DCL).
    • Types of SQL Commands: SQL commands are broadly categorized into four main types:
    • Data Definition Language (DDL): These commands are used to change the structure of the database objects such as tables. Examples include CREATE (to create tables), ALTER (to modify table structure), DROP (to delete tables), and TRUNCATE (to remove all rows from a table). DDL commands are auto-committed, meaning changes are permanently saved.
    • Data Manipulation Language (DML): These commands are used to modify the data within the database. Examples include SELECT (to retrieve data), INSERT (to add new rows), UPDATE (to modify existing rows), and DELETE (to remove rows). DML commands are not auto-committed, allowing for rollback of changes. The SELECT command is also referred to as Data Query Language (DQL).
    • Data Control Language (DCL): These commands control access to data within the database, managing user privileges and permissions. Examples include GRANT (to give users access rights) and REVOKE (to remove access rights).
    • Transaction Control Language (TCL): These commands manage database transactions. Examples include COMMIT (to save changes permanently) and ROLLBACK (to undo changes).
    • Basic SQL Command Structure: A typical SQL query follows a basic structure:
    • SELECT column1, column2, …
    • FROM table_name
    • WHERE condition(s)
    • GROUP BY column(s)
    • HAVING group_condition(s)
    • ORDER BY column(s) ASC|DESC;
    • The SELECT statement specifies the columns you want to retrieve. You can use SELECT * to select all columns.
    • The FROM statement indicates the table from which to retrieve the data.
    • The optional WHERE clause filters rows based on specified conditions. You can use comparison operators (e.g., >, =, <), logical operators (AND, OR, NOT), BETWEEN to select within a range, and IN to specify multiple values.
    • The optional GROUP BY clause groups rows that have the same values in one or more columns into summary rows, often used with aggregate functions.
    • The optional HAVING clause filters groups based on specified conditions (used with GROUP BY).
    • The optional ORDER BY clause sorts the result set in ascending (ASC) or descending (DESC) order based on one or more columns.
    • Data Types: SQL supports various data types to define the kind of data each column can hold, including exact numeric (integer, smallint, decimal), approximate numeric (float, real), date and time (date, time, timestamp), string (char, varchar, text), and binary data types (binary, varbinary, image).
    • Operators: SQL uses different types of operators to perform operations in queries, such as arithmetic operators (+, -, *, /), logical operators (ALL, ANY, BETWEEN, EXISTS, IN, LIKE, NOT, OR), and comparison operators (=, !=, >, <, >=, <=).
    • Functions: SQL provides built-in functions to perform various operations on data, including:
    • Aggregate functions: Calculate a single value from a set of rows (e.g., COUNT, SUM, AVG, MIN, MAX).
    • String functions: Manipulate text data (e.g., LENGTH, UPPER, LOWER, SUBSTRING, CONCAT, TRIM, POSITION, LEFT, RIGHT, REPEAT, REVERSE).
    • Date and time functions: Work with date and time values (e.g., CURDATE, DAY, NOW).
    • Mathematical functions: Perform mathematical calculations (e.g., ABS, GREATEST, LEAST, ROUND).
    • Joins: SQL allows you to combine data from two or more tables based on a related column. Different types of joins include INNER JOIN (returns rows only when there is a match in both tables), LEFT JOIN (returns all rows from the left table and matching rows from the right), RIGHT JOIN (returns all rows from the right table and matching rows from the left), and FULL OUTER JOIN (returns all rows when there is a match in either left or right table). UNION operator can also be used to combine the result sets of two or more SELECT statements.
    • Subqueries: A subquery (or inner query) is a query nested inside another SQL query. Subqueries can be used in the WHERE, SELECT, and FROM clauses to retrieve data that will be used by the outer query.
    • Stored Procedures: These are pre-compiled SQL statements that can be executed as a single unit. They can take parameters and return values, helping to encapsulate business logic and improve performance.
    • Triggers: Triggers are special types of stored procedures that automatically run when a specific event occurs in the database server (e.g., before or after an INSERT, UPDATE, or DELETE operation on a table).

    In summary, SQL is a powerful and versatile language essential for interacting with relational databases. It provides a structured way to define, manipulate, and retrieve data, making it a cornerstone of modern data management and analysis.

    Essential Skills for Aspiring Data Analysts

    Based on the sources, becoming a data analyst requires a combination of technical and soft skills. The document “01.pdf” outlines several key skill areas for aspiring data analysts.

    According to the source, the steps to become a data analyst include focusing on skills as the first crucial step. These skills are categorized into six main areas:

    • Microsoft Excel Proficiency: While advanced tools exist, proficiency in Excel remains vital for data analysts. Its versatility in data manipulation, visualization, and modeling is unmatched, making it a foundational tool for initial data exploration and basic analysis.
    • Data Management and Database Management Skills: This is indispensable for data analysts as the volume of data grows. Efficient management and retrieval from databases are critical. Proficiency in DBMS systems and querying languages like SQL ensures analysts can access and manipulate data seamlessly. As we discussed previously, SQL is the backbone of data management and analysis. It allows data analysts to access any information stored in a relational database with SQL queries. This includes writing queries, joining tables, and using subqueries.
    • Statistical Analysis: This skill allows analysts to uncover hidden trends, patterns, and correlations within data, facilitating evidence-based decision-making. It empowers analysts to identify the significance of findings, validate hypotheses, and make reliable predictions.
    • Programming Languages (e.g., Python, R): Proficiency in programming languages like Python is essential for data analysis. These languages enable data manipulation, advanced statistical analysis, and machine learning implementations. The source also mentions R programming language as one of the tools a data analyst should be familiar with.
    • Data Storytelling and Data Visualization: This skill is paramount for data analysts. Data storytelling bridges the gap between data analysis and actionable insights, ensuring that the value of data is fully realized. The ability to present insights clearly and persuasively is crucial as data complexity grows. Tools like Tableau and Power BI are mentioned as data visualization tools.
    • Problem Solving and Soft Skills: Strong problem-solving skills are important for data analysts when dealing with complex data challenges and evolving analytical methodologies. Analysts must excel in identifying issues, formulating hypotheses, and devising innovative solutions. In addition to technical skills, data analysts in 2025 will require strong soft skills to excel. These include:
    • Communication: Data analysts must effectively communicate their findings to both technical and non-technical stakeholders, presenting complex data in a clear and understandable manner.
    • Teamwork and Collaboration: Data analysts often work with multidisciplinary teams alongside data scientists, data engineers, and business professionals. Collaborative skills are essential for sharing insights, brainstorming solutions, and working cohesively towards common goals.
    • Domain Knowledge: Knowledge of the domain in which the analyst is working (e.g., pharmaceutical, banking, automotive) is really important. Without a basic foundational domain knowledge, it can be difficult to provide accurate results.

    In summary, a data analyst needs a blend of technical skills in data manipulation (including SQL and Excel), statistical analysis, programming, and data visualization, along with crucial soft skills in communication, teamwork, and problem-solving, complemented by domain knowledge. Our earlier discussions highlight the fundamental role of SQL in a data analyst’s toolkit for interacting with databases [1, Your previous turn].

    Understanding Database Management and SQL

    Based on the sources, database management encompasses the organized collection of structured information or data, typically stored electronically in a computer system. This data is managed using a Database Management System (DBMS), which acts as a storage system for the collection of data.

    Here are key aspects of database management as discussed in the sources:

    • Role of a DBMS: A DBMS is crucial for controlling and managing databases. It provides the necessary tools and functionalities to ensure data is easily retrieved, managed, and updated.
    • Relational Databases: A significant aspect of database management discussed in the source is relational databases. These systems store data in the form of tables. This tabular structure allows for organizing data into tables, rows (records or tuples), and columns (fields).
    • Organization and Indexing: In relational databases, data can be organized into tables with specific structures. Furthermore, data can be indexed to make it easier to find relevant information. An index helps speed up data retrieval operations. A table consists of:
    • Column Names (Fields): These are the attributes of the data stored in the table (e.g., player ID, player name, country, goals scored). Each column should have a unique name. All values within a specific column should be of the same data type or domain.
    • Rows (Records or Tuples): Each row represents a single instance of the entity being described by the table (e.g., information about a specific player).
    • SQL for Database Management: As highlighted in our previous conversation, SQL (Structured Query Language) is a domain-specific language used to communicate with databases [1, Your previous turn]. It plays a vital role in database management by allowing users to:
    • Query databases to retrieve specific information.
    • Update databases to modify existing data.
    • Insert records to add new data.
    • Perform many other tasks related to managing and manipulating data.
    • Store, process, analyze, and manipulate databases.
    • Create a database and define its structure.
    • Maintain an already existing database.
    • Popular Databases: The source lists several popular database systems, including:
    • MySQL.
    • Oracle Database.
    • MongoDB (a NoSQL database).
    • Microsoft SQL Server.
    • Apache Cassandra (a free and open-source NoSQL database).
    • PostgreSQL.
    • Database Management Skills for Data Analysts: Our previous discussion on data analyst skills emphasized that data management and database management skills are indispensable for data analysts [Your previous turn, 3]. The increasing volume of data necessitates efficient management and retrieval from databases, making proficiency in DBMS systems and querying languages like SQL critical. Data analysts need to be able to access and manipulate data seamlessly using SQL.

    In essence, database management involves the strategic organization, storage, retrieval, and manipulation of data using a DBMS. Relational databases, structured in tables, are a common model, and SQL is the primary language used to interact with these systems for various management tasks. These skills are fundamental for professionals like data analysts who work with data to derive insights and support decision-making.

    SQL for Data Analysis Functions

    Based on the sources and our conversation history, data analysis functions involve the process of inspecting, cleaning, transforming, and modeling data with the goal of discovering useful information, informing conclusions, and supporting decision-making. SQL plays a crucial role in performing many of these functions when the data resides in relational databases [1, Your previous turn, Your previous turn].

    Here are some key data analysis functions that can be performed using SQL, as supported by the sources:

    • Data Retrieval and Selection: SQL’s SELECT statement is fundamental for retrieving specific data required for analysis. You can choose particular columns from one or more tables. For example, to analyze player performance, you might select player name and goals scored from a players table.
    • Filtering Data: To focus on relevant subsets of data, the WHERE clause in SQL allows you to filter records based on specified conditions. For instance, you might analyze data only for players from a specific country.
    • Sorting Data: The ORDER BY clause enables you to sort the retrieved data based on one or more columns, which can help in identifying trends or outliers. You could sort players by the number of goals scored in descending order to see the top performers.
    • Removing Duplicates: The DISTINCT keyword is used to retrieve only unique values from a column, which can be important for accurate analysis, such as finding the number of unique cities represented in a dataset.
    • Aggregation: SQL provides aggregate functions that perform calculations on a set of rows and return a single summary value. These are essential for summarizing data:
    • COUNT(): To count the number of rows or non-null values. For example, counting the total number of employees.
    • SUM(): To calculate the total sum of values in a column. For example, finding the total salary of all employees.
    • AVG(): To calculate the average of values in a column. For example, finding the average age of employees.
    • MIN(): To find the minimum value in a column. For example, identifying the lowest salary.
    • MAX(): To find the maximum value in a column. For example, determining the highest salary.
    • Grouping Data: The GROUP BY clause allows you to group rows that have the same values in one or more columns into summary rows. This is often used in conjunction with aggregate functions to perform analysis on different categories. For instance, finding the average salary for each department.
    • Filtering Groups: The HAVING clause is used to filter groups created by the GROUP BY clause based on specified conditions, often involving aggregate functions. For example, identifying countries where the average salary is greater than a certain threshold.
    • Joining Tables: When data for analysis is spread across multiple related tables, JOIN operations in SQL are used to combine data from these tables based on common columns. This allows you to bring together relevant information for a comprehensive analysis, such as combining customer information with their order details. As mentioned in the source, you can even join three or more tables.
    • Using Inbuilt Functions: SQL provides various inbuilt functions that can be used for data manipulation and analysis. These include:
    • Mathematical Functions: For performing calculations (e.g., ABS(), MOD(), SQRT(), POWER()).
    • String Functions: For manipulating text data (e.g., LENGTH(), CONCAT(), UPPER(), LOWER(), SUBSTRING(), REPLACE()).
    • Date and Time Functions: For working with temporal data (e.g., CURRENT_DATE(), NOW(), extracting day, year).
    • Creating Calculated Fields: Using SQL, you can create new columns based on existing data through calculations or conditional logic. The CASE statement allows you to define different values for a new column based on conditions evaluated on other columns, enabling the categorization of data (e.g., creating a salary range category based on salary values).
    • Subqueries (Nested Queries): SQL allows you to write queries within other queries, which can be used to perform more complex data retrieval and analysis. For example, selecting employees whose salary is greater than the average salary calculated by a subquery.
    • Views: Views are virtual tables based on the result of an SQL statement. They can simplify complex queries and provide a focused perspective on the data, making analysis easier by presenting a subset of data in a more manageable format.
    • Common Table Expressions (CTEs): CTEs are temporary, named result sets defined within the scope of a single query. They can break down complex analytical queries into smaller, more readable, and manageable parts.

    These data analysis functions, facilitated by SQL, are crucial skills for a data analyst, as highlighted in our earlier discussion about the necessary skills for this role [Your previous turn]. Proficiency in using these SQL features allows data analysts to effectively extract, manipulate, summarize, and analyze data stored in databases to derive meaningful insights.

    SQL Full Course 2025 | SQL Tutorial for Beginners | SQL Beginner to Advanced Training | Simplilearn

    The Original Text

    hello everyone and welcome to SQL fos by simply learn have you ever wondered how apps manage data or how businesses handle massive data sets the answer lies in SQL structured query language is the backbone of data management and Analysis making it a must have skill for data analyst developers and database administrators as well as IND indes become more datadriven the demand for SQL experts is skyrocketed and by 2025 job opportunities in fields like SQL development and data analysis with search with starting salaries reaching around $50,000 in the US and around 4 to8 lakh perom in India and even experienced professionals earn around $100,000 or 20 lakh perom in India this course will take you from a beginner level to see SQL expert you learn how to write queries join tables use subqueries and apply SQL for Hands-On data analysis and by the end you’ll be equipped to manage and manipulate data like a pro so let’s get started but before that if you’re interested to make a current data analytics check out Simply learn’s postgraduate program in data analytics this comprehensive course is designed to transform you into a data analyst export this program covers essential skills such as data visualization statistical analysis machine learning using industry leading tools and Technologies like XLR Python and even tablet the course link is mentioned in description box below and in the pin comment so hurry up and enroll now in this session we are going to learn about databases how data is stored in relational databases and we’ll also look at some of the popular databases finally we’ll understand various SQL commands on my SQL Server now let’s get started with what is a database so according to Oracle a database is an organized collection of structured information or data that is typically stored electronically in a computer system a database is usually controlled by a database management system or dbms so it is a storage system that has a collection of data relational databases store data in the form of tables that can be easily retrieved managed and updated you can organize data into tables rows columns and index it to make it easier to find relevant information now talking about some of the popular databases we have mySQL database we also have Oracle database then we have mongod DV which is a no SQL database next we have Microsoft SQL Server next we have Apache cassendra which is a free and open source nosql database and finally we have postgress SQL now let’s learn what is SQL so SQL is a domain specific language to communicate with databases SQL was initially developed by IBM most databases use structured query language or SQL for writing and querying data SQL commands help you to store process analyze and manipulate databases with this let’s look at what a table is so this is how a table in a database looks like so here you can see the name of the table is players on the top you can see the column names so we have the player ID the player name the country to which the player belongs to and we also have the goals scored by each of the players so these are also known as fields in a database here each row represents a record or a tle so if you have the player ID which is 103 here the name of the player is Daniel he is from England and the number of goals he has scored is seven so you can use SQL commands to query update insert records and do a lot of other tasks now we’ll see what the features of SQL are SQL lets you access any information stored in a relational database with SQL queries data is extracted from the database in a very efficient way the structured query language is compatible with all database systems from Oracle IBM to Microsoft and it doesn’t require much coding to manage databases now we will see applications of SQL SQL is used to create a database Define its structure implement it and let you perform many functions SQL is also used for maintaining an already existing database SQL is a powerful language for entering data modifying data and extracting data in a database SQL is extensively used as a client server language to connect the front end with the back end the supporting the client server architecture SQL when deployed as data control language DCL helps protect your database from unauthorized access if you categor the steps to become a data analyst these are the ones firstly you need to focus on skills followed by that you need to have a proper qualification then test your skills by creating a personal project an individual project followed by that you must focus on building your own portfolio to describe your caliber to your recruiters and then Target to the entry level jobs or internships to get exposure to the real world data problems so these are the five important steps now let’s begin with the step one that is skills so skills are basically categorized into six steps Ed cleaning data analysis data visualization problem solving soft skills and domain knowledge so these are the tools Excel MySQL our programming language Python programming language some data visualization tools like TBL Loop powerbi and next comes the problem solving so these are basically the soft skill Parts problem solving skills domain knowledge the domain in which you’re working maybe a farma domain maybe a banking sector maybe automobile domain Etc and lastly you need to be a good team player so that you can actively work along with the team and solve the problem collaboratively now let’s move ahead and discuss each and every one of these in a bit more detail starting with Microsoft Excel while Advanced tools are prevalent Proficiency in Excel remains vital for data analyst Excel versatility in data manipulation visualization and modeling is Unown Managed IT serves as a foundational tool for initial data exploration and basic analysis data management database management skill is indispensable for data analyst as data volume saw efficient management and retrieval from datab basis is critical Proficiency in ddb systems and querying languages like SQL ensures analyst can access and manipulate data seamlessly followed by that we have statistical analysis statistical analysis allow analyst to uncover hidden Trends pattern and cor relationships within data facilitating evidence-based decision making it empowers analyst to identify the significance of findings validate hypothesis and make reliable predictions next after that we have programming languages Proficiency in programming languages like python is essential for data analysis these languages enable data manipulation Advanced statistical analysis and machine learning implementations next comes data storytelling or also known known as data visualizations data storytelling skill is Paramon for data analyst data storytelling Bridges the gap between data analysis and actionable insights ensuring that the value of data is fully realized in a world where data driven communication is Central to business success data visualization skill is a CornerStore for data analyst as data complexity grows the ability to present insights clearly and persuasively is Paramount next is managing your customers and problem solving managing all your customers data and Company relationships is Paramount strong problem solving skills are important for data analyst with complex data challenges and evolving analytical methodologies analyst must excel in identifying issues formulating hypothesis and devising innovative solutions in addition to the technical skills data analyst in 2025 will require strong soft skills to excel in their roles here are the top ones data analyst must effectively communicate their findings to both Technical and non-technical stakeholders this includes presenting complex data in a clear and understandable manner next soft skill is teamwork and collaboration data analysts often work with multidisciplinary teams alongside data scientists data Engineers business professionals collaborative skills are essential for sharing insights brainstorming Solutions and working cohesively towards common goals and last but not least domain knowledge knowledge on domain in which you’re currently working is really important it might be a formatical domain it can be an automobile domain it can be banking sector and much more unless you have a basic foundational domain knowledge you cannot continue in that domain with accurate results now the next step which was about the qualification to become a data analyst Master’s courses online courses and boot camps provide strong structured learning that helps you gain in-depth knowledge and specialized skills in data analysis masters programs offer comprehensive academically recr training and often include research projects making sure you’re highly competitive in the job market online courses allow flexibility to learn at your own pace while covering essential topics and boot gaps offer immersive Hands-On training in a short period focusing on practical skills all three parts enhance your credibility keeping you updated on industry Trends and make you more attractive to potential employers if you are looking for a well curated allrounder then we have got you covered simply learn offers a wide range of courses on data science and data analytics starting from Masters professional certifications to post graduations and boot camps from globally reputed and recognized universities for more details check out the links in the description box below and comment section now proceeding ahead we have the projects for data analyst data analyst this projects demonstrate practical skills in data cleaning visualization and Analysis they help build a portfolio showcasing your expertise and problem solving abilities projects provide hands-on experience Bridging the Gap between Theory and real world application this show domain knowledge making you more appealing to employees in specific Industries projects enhance your confidence and prepare you to discuss real world challenges in interviews proceeding ahead the next step is about the portfolio for data analysts a portfolio is a testament that demonstrates your skill and expertise through real world projects showcasing your ability to analyze and interpret data effectively it provides tangible proof of your capabilities making you stand out to the employers additionally it highlights your domain knowledge and problem solving skills giving you a Competitive Edge during job applications and interviews last but not the least data analyst internships internships provide hands-on experience with real world sets tools and workflows Bridging the Gap between Theory knowledge and practical application they offer exposure to Industry practices helping you understand how data is used to drive decisions internships also build you Professional Network enhance your resuming and improve chances of securing a full-time data analy role so let’s understand what 10 year diagram is an entity relationship diagram describes the relationship of entities that needs to to be stored in a database ER diagram is mainly a structural design for the database it is a framework made using specializ symbols to define the relationship between entities ER diagrams are created based on the three main components entities attributes and relationships let’s understand the use of ER diagram with the help of a real world example here a school needs all its Student Records to be stored digitally so they approach an IT company to do so a person from the company will meet the school authorities note all their requirements describe them in the form of ear diagram and get it cross checked by the school authorities as the school authorities approve the year diagram the database Engineers would carry further implementation let’s have a view of an ear diagram the following diagram showcases two entities student and course and the relationship the relationship described between student and course is many to many as a course can be opted by several students and a student can opt for more than one course here student is the entity and it processes the attributes that is student ID student name and student age and the course entity has attributes such as course ID and course name now we have an understanding of Y diagram let us see why it has been so popular The Logical structure of the database provided by a diagram communicates the landscape of business to different teams in the company which is eventually needed to support the business year diagram is a GUI representation of The Logical structure of a database which gives a better understanding of the information to be stored in a database database designers can use ER diagrams as a blueprint which reduces complexity and helps them save time to build databases quickly ear diagrams helps you identify the enti ities that exist in a system and the relationships between those entities after knowing its uses now we should get familiar with the symbols used in your diagram the rectangle symbol represents the entities oral symbol represents attributes a rectangle embedded in a rectangle represents a weak entity a dashed toal represents a derived attribute a diamond symbol represents a relationship among entities double all symbol represents multivalued attributes now we should dive in and learn about the components of ER diagram there are three main components of ER diagram entity attribute and relationship entities have weak entity attributes are further classified into key attribute composite attribute multivalued attribute and derived attribute relationships are also classified into one to one relationships one to many relationships many to one relationships and many to many relationships let’s understand these components of V diagram starting with entities an entity can be either a living or a non- living component an entity is showcased as a rectangle in a near diagram let’s understand this with the help of a near diagram here both student and course are in rectangular shape and are called entities and they represent the relationship study in a diamond shape let’s transition to weak entity and an entity that makes Reliance over another entity is called a weak entity the weak entity is showcased as a double rectangle in ER diagram in the example below the school is a strong entity because it has a primary key attribute School number unlike the school the classroom is a weak entity because it does not have any primary key and the room number attribute here acts only as a discriminator and not a primary key now let us know about attributes attribute an attribute exhibits the properties of an entity an attribute is Illustrated with an oval shape in an ER diagram in the example below student is an entity and the properties of student such as address age name and role number are called its attributes let’s see our first classification under attribute that is key attribute the key attribute uniquely identifies an entity from an entity set the text of a key attribute is underlined in the example below we have a student entity and it has attributes name address role number and age but here role number can uniquely identify a student from a set of students that’s why it is termed as a key attribute now we will see composite attribute an attribute that is composed of several other attributes is known as a composite attribute and oval showcases the composite attribute and the composite attribute oval is further connected with other ovals in the example below we can see an attribute name which can have further subparts such as first name middle name and last name these attributes with further classification is known as composite attribute now let’s have a look at multivalued attribute an attribute that can possess more than one value are called multivalued attributes these are represented as double old shape in the example below the student entity has attributes phone number role number name and age out of these attributes phone number can have more than one entry and the attribute with more than one value is called multivalued attribute let’s see derived attribute an attribute that can be derived from other attributes of the entity is known as a derived attribute in the ER diagram the derived attribute is represented by dashed over and in the example below student entity has both date of birth and age as attributes here age is a derived attribute as it can be derived by subtracting current date from the student date of birth now after knowing attributes let’s understand relationship in ER diagram a relationship is showcased by the diamond shape in the year diagram it depicts the relationship between two entities in the below for example student study course here both student and course are entities and study is the relationship between them now let’s go through the type of relationship first is one to one relationship when a single element of an entity is associated with a single element of another entity this is called one to one relationship in the example below we have student and identification card as entities we can see a student has only one identification card and an identification card is given to one student it represents a one to one relationship let’s see the second one one to many relationship when a single element of an entity is associated with more than one element of another entity is called one to many relationship in the below example a customer can place many orders but a particular order cannot be placed by many customers now we will have a look at many to one relationship when more than one element of an entity is related to a single element of another entity it is called many to one relationship for example students have to opt for a single course but a course can be opted by number of students let’s see many to many relationship when more than one element of an entity is associated with more than one element of another entity is called many to many relationship for example an employee can be assigned to many projects and many employees can be assigned to a particular project now after having an understanding of ER diagram let us know the points to keep in mind while creating the year diagram first identify all the entities in the system embed all the entities in a rectangular shape and label them appropriately this could be a customer a manager an order an invoice a schedule Etc identify relationships between entities and connect them using a diamond in the middle illustrating the relationship do not connect relationships connect attributes with entities and label them appropriately and the attribute should be in Old shape assure that each entity only appears a single time and eradicate any redundant entities or relationships in the ear diagram make sure your ER diagram supports all the data provided to design the database make effective use of colors to highlight key areas in your diagrams there are mainly four types of SQL commands so first we have data definition language or ddl so ddl commands change the structure of the table like creating a table deleting a table or altering a table all the commands of ddl are autoc committed which means it permanently save all the changes in the database we have create alter drop and truncate as ddl commands next we have data manipulation language or DML so DML commands are used to modify a database it is responsible for all forms of changes in the database DML commands are not autoc committed which means it can’t permanently save all the changes in the database we have select update delete and insert as DML commands now select command is also referred to as dql or data query language third we have data control language or DCL so DCL commands allow you to control access to data within the database these DCL commands are normally used to create objects related to user access and also control the distribution of privileges among users so we have Grant and revok which are the examples of data control language finally we have something called as transaction control language or TCL so TCL commands allow the user to manage database transactions commit and roll back our example of TCL now let’s see the basic SQL command structure so first we have the select state stat M so here you specify the various column names that you want to fetch from the table we write the table name using the from statement next we have the we Clause to filter out our table based on some conditions so you can see here we condition one condition two and so on then we have the group by Clause that takes various column names so you can write Group by column 1 column 2 and so on next we have the having Clause to filter out tables based on groups finally we have the order by Clause to filter out the result in ascending or descending order now talking about the various data types in SQL so we have exact numeric which has integer small int bit and decimal then we have approximate numeric which are float and real then we have some date and time data types such as date time time stamp and others then we have string data type which includes car the varar car and text finally we have binary data types and binary data types have binary VAR binary and image now let’s see some of the various operators that are present in SQL so first we have our basic arithmetic operators so you have addition the substraction multiplication division and modulus then we have some logical operators like all and any or between exist and so on finally we have some comparison operators such as equal to not equal to that’s greater than less than greater than equal to or less than equal to not less than or not greater than now let me take you to my MySQL workbench where we will learn to write some of the important SQL commands use different statements functions data types and operators that we just learned in this session we will learn how to install MySQL workbench and then we will run some commands firstly we will visit the official Oracle website that is myql.com and now we’ll move to the downloads page now scroll down and click on my SQL GPL downloads now under Community downloads click on my SQL installer for Windows the current versions are available to download I will choose this installer and click the download button now here just click on no thanks just start my download Once the installer has download it open it you may be prompted for permission click yes this opens the installer we will be asked to choose the setup type we will go with custom click next now you have to select the products you want to install we will install only the MySQL server my SQL shell and the MySQL workbench expand my SQL servers by double clicking on it and choose the version you want to install and click on this Arrow now you have to do the same thing for applications expand applications and choose the MySQL workbench version you want to install and click on the arrow and we’ll do the same thing for my SQL shell we’ll choose the latest version click on the Arrow so these are the products that have to be installed in a system now we will click next I’ll click execute to download and install the server this may take a while depending on your internet speed as the download is completed click next now you see the product configuration click next now we’ll configure our SQL Server instance here we will go with the default settings and click next and under authentication select use strong password encryption for authentication which is recommended and click on next now here set the password for your root user by the way root is the default user this user will have access to everything I will set my password now I’ll click on next and here also we’ll keep the default settings and click on next now to apply configuration we will execute the process once Sol the conf ification steps are complete click finish now you will see the installation is complete it will launch my SQL workbench and my SQL shell after clicking on finish now the shell and workbench has started now we’ll connect by clicking on the root user it will ask for a password enter the password and it will connect successfully yeah the workbench has started now we’ll just connect the server so first we’ll open command prompt now we will reach the path where MySQL files are present you go into this PC local d c program files my SQL my SQL Server 8.0 bin and now I’ll copy this path now we’ll open the command prom and write a command CD space and paste the link and press enter now we write another command that will be my SQL minus u space root minus p and enter now it will ask for your password just enter the password and press enter now the server has started and now we’ll see some commands in my SQL workbench first we will open my SQL workbench now we’ll click on the local instance my SQL 80 and enter the password to connect to the Local Host yeah the my SQL workbench has started now we’ll see some commands the First Command we will see is show databases show databases semicolon and now we will select the whole command and click on this execute button and here we will see the result in the result grit these are the databases that are stored already in the database now there are four databases that is information schema MySQL performance schema and SS now we will select one of the database we will use uh my SQL now we have selected the mySQL database and now in this database we will see which tables are stored in this mySQL database to see that we will run a command show tables we’ll select the command and click on the execute button the these are the tables that are stored in this mySQL database that is columns _ PR component DP and much more now let me now go ahead and open my MySQL workbench so in the search bar I’ll search for MySQL workbench you can see I’m using the 8.0 version I’ll click on it and here it says welcome to my SQL workbench and Below under connections you can see I have already created a connection which says local instance then you have the root the local host and the port number let me click on it you can see the service the username is root and I’ll enter my password and hit okay now this will open the SQL editor so this is how the MySQL workbench looks like here we learn some of the basic SQL commands so first let me show you the databases that are already present so the command is so databases you can hit tab to autoc complete I’ll use a semicolon I’ll select this and here on the top you can see the execute button so if I run this below you can see the output it says show databases seven rows are returned which means currently there are seven databases you can see the names all right now let’s say I want to see the T tables that are present inside this database called world so I’ll use the command use World which is the database name now let me run it so currently I’m using the world database so to display the tables that are present in the world database I can use the show command and write show tables give a semicolon and I’ll hit control enter this time to run it all right so you can see the tables that are present inside this world database so we have three tables in total City Country and Country language now if you are to see the rows that are present in one of the tables you can use the select command so I’ll write select star which basically means I want to display all the columns so star here means to display all the columns then I’ll write my from the table name that is City so this command is going to display me all the rules that are present inside the city table so if I hit control enter all right you can see the message here it says th000 rows were returned which means there were total thousand records present inside the city table so here you can see there’s an ID column a name column this country code district and population all right similarly you can check the structure of the table by using the describe command so I’ll write describe and then I’ll give the table name that is City now let’s just run it there you go the field shows the column names so we have ID name country code district population type here shows the data type of each of the columns so district is character 20 ID is an integer population is also integer null says yes or no which means if no then there are no null values if it’s yes which means there are null values in your table key here represents whether you have any primary key or foreign key and these are some extra information now let’s learn how to create a table in my SQL so I’ll use the create table command for this and before that let me create a database and I’ll name it as SQL intro so the command is create database and I’ll give my database name that is SQL intro me give a semicolon and hit control enter so you can see I have created a new database now if I run this command that is show databases you can see this newly created database that is SQL intro if I scroll down there you go you can see the name here SQL intro okay now within this database we’ll create a table called employee details now this will have the details of some employees so let me first show you how to create a table that will be present inside the SQL intro database so I’ll use the command create table and then I’ll give my table name that is going to be employee uncore details next the syntax is to give the column names so my first column would be the name column which is basically the employee name followed by the data type for this column since name is a text column so I’ll use varar and I’ll give a value of 25 so it can hold only 25 characters okay next I also want the age of the employee now age is always an integer so I’ll give int okay then we can have the gender of the employee so gender can be represented as f for m f for female and M for male so I’m using the card data type or character data type and I’ll give the value as one then let’s have the date of join or doj and this is going to be of data type date all right next we’ll have the city name that is the city to which the employee belongs to so again again this is going to be warar 15 finally we’ll have a salary column and salary we’ll keep it as float since salary can be in decimal numbers as well now I’ll give a semicolon all right so let me just quickly run through it so first I wrote my create command then the table which is also a keyword followed by the table name which is employee details here and then we give the column names such as name age this gender date of join City and salary for each of the columns we also give the data type all right so let me just run it okay so here you can see we have successfully created our first table now you can use the describe command to see the structure of the table I’ll write this describe empore details if I run this there you go so under field you can see the column names then you have the data types null represents if the table can accept null values or not and these are basically empty and we haven’t set any default constraint all right moving ahead now let’s learn to add data to our table using the insert command so on a notepad I have already written my insert statement so let me just copy it and then I’ll explain it one by one all right so if you see this so we have used an insert into statement or a command followed by the table name that is EMP details then this is the syntax using values I have passed in all the records so first we have Jimmy which is the name of the employee then we we have 35 it basically represents the age then m means the gender or the sex then we have the date of join next we have the city to which the employee belongs to and finally we have the salary of the employee so this particular information represents one record or a tle similarly the next employee we have is Shane you can see the age and other information then we have Mary this Dwayne Sara and am all right so let me go ahead and run this so this will help you insert the values in the table that you have created you can see we have successfully inserted six records now to display the records let me use the select statement so I’m using select star from empore details if I run this you can see my table here and the values it has so we have the name column the age column the state of join City salary and these are the values that you can see here moving ahead now let’s say you want to see the Unique city names present in the table so in this case you can use the distinct keyword along with the column name in the select statement so let me show you how you can print the distinct city names that are present in our table now if you notice this table clearly we have Chicago Seattle Boston Austin this New York and this Seattle repeated again so I only want to print the unique values so for that I can write my select statement as select distinct then I’ll give my column name which is City from my table name that is EMP details if I run this you can see my query has returned five rows and these are the values so we have Chicago cattl which was repeated twice is just been shown once then we have Boston Austin and New York now let’s see how you can use inbuilt aggregate functions in SQL so suppose you want to count the number of employees in the table in that case you can use the count function in the select statement so let me show you how to do that so I’ll write select I’ll use my function name name that is Count now since I want to know the total number of employees I’m going to use their name inside the brackets from employee _ details now if I run this this will return the total number of employees that are present in the table so we have six employees in total now if you see here in the result it says count name now this column is actually not readable at all so what SQL provides something called as an alas name so you can give an alas to the resultant output so here I can write select count of name and use an alas as as I can give an alas as countor name and run this statement again there you go you can see here in the resultant output we have the column name as count name which was Alias name now suppose you want to get the total sum of salaries you can use another aggregate function called sum so I’ll write my select statement and this time instead of count I’m going to write sum and since I want to find the sum of salaries so inside the bracket I’ll give my salary column from my table name that is employee details if I run this this will result the total sum of salaries so basically it adds up all the salaries that were present in the salary column now let’s say you want to find the average salary so instead of sum you can write the average function which is ABG so this will give you the average salary from the column salary so you can see it here this says average salary now if you want you can give an alas name to this as well now you can select specific columns from the table by using the column names in the select statement so initially we were selecting all the columns for example like you saw here the star represents that we want to see all the columns from the employee details table now suppose you want to see only specific columns you can mention those column names in the select statement so let’s say I want to select just the name age and the city column from my table that is employee details so this will result in displaying only the name age and City column from the table if I run it there you go it has given only three columns to me now SQL has a we Clause to filter rows based on a particular condition so if you want to filter your table based on specific conditions you can use we Clause now we Clause comes after you give your table name so suppose you want to find the employees with age greater than 30 in this case you can use a we Clause so let me show you how to do it I’ll write select star from my table name that is employee details and after this I’ll use my wear Clause so I’ll write where age greater than 30 if I run this it will give me the output where the age is only greater than 30 so it excluded everything that is less than 30 so we have four employees whose age is greater than 30 here now suppose you want to find only female employees from the table you can also use a wear Clause here so I’ll write select let’s say I want only the name the gender which is sex here comma City from my table that is employee details where I’ll give my column name that is sex is equal to since I want only the female employees I’ll give F and run this statement okay you can see here our employee table has three female employees now suppose you want to find the details of the employees who belong to Chicago or Austin in this case you can use the or operator now the or operator in SQL displays a record if any of the condition separated by R is true so let me show you what I mean so since I want the employees who are from Chicago and Austin I can use an or operator so I’ll write select star from EMP details which is my table name then I’ll give my we Clause where City equal to I’ll give my city name as Chicago and then I’m going to use the or operator or city equal to I’ll write Austin I’ll give a semicolon and let me run it there you go so in the output you can see all the employees who belong to the city Chicago and Austin now there is another way to write the same SQL query so you can use an in operator to specify by multiple conditions so let me just copy this and instead of using the r operator this time I’m going to use the in operator so I’ll delete this after the wear Clause I’m going to write where City and use the in operator inside bracket I’ll give my city names as shago and I want Austin so I’ll give a comma and write my my next city name that is Austin so this query is exactly the same that we wrote on top let me run this you will get the same output there you go so we have Jimmy and Dwayne who are from Chicago and Austin respectively now SQL provides the between operator that selects values within a given range the values can be numbers text or dates now suppose you want to find the employees whose date of join was between 1st of Jan 2000 and 31st of December 2010 so let me show you how to do it I’ll write select star from EMP details where my date of join that is doj between I’ll give my two date values that is 1st of Jan 2000 and I’ll give my second value the date value that is 31st of December 2010 so every employee who has joined between these two dates will be displayed in the output if I run it we have two employees who had joined between 2000 and 2010 so we have Jimmy and Mary here who had joined in 2005 and 2009 respectively all right now in we Clause you can use the and operator to specify multiple conditions now the and operator displays a record if all the conditions separated by and are true so let me show you an example I’ll write select star from employee details table where I want the age to be greater than 30 and I want sex to be male all right so here you can see I have specified two conditions so if both the conditions are true only then it will result in an output if I run it you can see there are two employees who are male and their age is greater than 30 now let’s talk about the group by statement in SQL so the group by statement groups rows that have the same values into summary rows like for example you want to find the average salary of customers in each department now the group by statement is often used with aggregate functions such as count sum and average to group the result set into one or more columns let’s say we want to find the total salary of employees based on the gender so in this case you can use the group by Clause so I’ll write select let’s say sex comma I want to find the total sum of salary as I’ll give an alas name let’s say total salary from my table name that is employee details next I’m going to group it by sex okay let me run it there you go so we have two genders male and female and here you can see the total salary so what this SQL statement did was first it grouped all the employees based on the gender and then it found the total salary now SQL provides the order by keyword to sort the result set in ascending or descending order now the order by keyword sorts the records in ascending order by default to sort the records in descending order you can use the dec keyword so let’s say I want to sort my employee details table in terms of salary so I’ll write select star from empore details and I’ll use my order by clause on the salary column so this will sort all the records in ascending order of their salary which is by default you can see the salary column is sorted in ascending order now suppose you want to sort the salary column and display it in descending order you can use this keyword that is DEC let me run it you can see the output now this time the salary is sorted in descending order and you have the other values as well now let me show you some basic operations that you can do using the select statement so suppose I write select and do an addition operation let’s say 10 + 20 and I’ll give an alas name as addition if I run this it will give me the sum of 10 and 20 that is 30 similarly you can use the subtraction operator and you can change the alas name as let’s say subtract let’s run it you get minus 10 now there are some basic inbuilt functions there are a lot of inbuilt functions in SQL but here I’ll show you a few suppose you want to find the length of a text or a string you can use the length L function so I’ll write select and then use the length function I’ll hit tab to autocomplete let’s say I want to find the length of country India and I’ll give an alas as total length if I run it you see here it returns five because there are five letters in India there’s another function called repeat so let me show you how repeat works so I’ll write select repeat let’s say I want to repeat the symbol that is at the rate I’ll put it in single codes because it is a text character and I want to repeat this character for 10 times close the bracket and let’s run it you can see here in the output it has printed at the rate 10 times you can count it all right now let’s say you want to convert a text or a string to upper case or lower case you can do that as well so I’ll write select and use the function called upper let’s say I want to convert my string that is India to uppercase I’m not giving in any alas name if I run this see my input was capital I and everything else was in small letter in the output you can see it has converted my input to all caps similarly you can change this let’s say you want to print something in lower case you can use the lower function let’s say this time everything is in upper case if I run it it converts India to lower case now let’s explore a few date and time functions let’s say you want to find the current date there’s a function called C which stands for current and this is the function I’m talking about which is current date if I run this you will get the current date that is 28th of Jan 2021 and let’s say you want to extract the day from a date value so you can use the D function let’s say I’ll use D and I want to find the D from my current date if I run this you get 28 which is today’s day now similarly you can also display the current date and time so for that you can use a function that is called now so this will return the current date and time you can see this is the date value and then we have the current time all right and this brings us to the end of our demo session so let me just scroll through whatever we have learned so first I showed you how you can see the databases present in my SQL then we use used one of the databases and checked the tables in it then we created another database called SQL intro for our demo purpose we used that database and then we created this table called employee details with column names like name integer the sex date of joints City and salary I showed you the structure of the database let me run this again so you get an idea you can see this was the structure of our table the then we went ahead and inserted a few records so we inserted records for six employees so you have the employee name the age the gender the date of join the city to which the employee belongs to and the salary of the employee then we saw how you can use the select statement and display all the columns present in the table we learned how you can display the Unique city names we learned how to use different aggregate function like count average and sum then we learned how you could display specific columns from the table we learned how to use we Clause then we used an R operator we learned about in operator the between operator then we used an and operator to select multiple conditions finally we learned about group buy order buy and some basic SQL operations now it’s time to explore some string functions in MySQL so I have given a comment string functions first let’s say you want to convert a certain string into upper case so I can write select the function I’ll use is upper and within this function you can pass in the string let’s say I’ll write India if you want you can give an alas name as let’s say uppercase I’ll give a semicolon and let’s run it there you go so my input was in sentence case and using the upper function we have converted everything into uppercase similarly let me just copy this and I’ll show you if you want to convert a string into a lower case you can use the lower function I’ll run this you can see the result everything is in lower case now of course I need to change the alas name to lower case instead of using lower as the function there is another function that MySQL provides which is called the L case so I’ll just edit this and write L case and let’s say I’ll write India in uppercase let’s run it returns me the same result cool moving on let’s say you want to find the length of a string you can use the character length function I’ll write select use the function character length and I’m again going to pass in my string as India as let’s say total length let’s run it this time I’m going to hit control enter to run my SQL command there you go it has given us the right result which is five because India has five characters in it now these functions you can also apply on a table now let me show you how to do it let’s say we already have the students table and you want to find the length of each of the student names so here you can pass sore name and you can give the same alas name let’s say total length and then you can write from table name that is students if I run this you can see the output it has given me total 20 rows of information this not readable actually let me also so display these student names so that we can compare their length all right I’ll run this again and now you can see the result so Joseph has six characters NES has six vipul has five anubhab has seven similarly if you see Aki has six Tanish has seven ragav has six Cummins has seven rabada has six so on and so forth now instead of using this character length you can also use the function car length it will work the same way let’s see the result there you go it has given us the same result you can either use character length or car length there’s another very interesting function called concat so the concat function adds two or more Expressions together let’s say I’ll write select use the function concatenate the function is actually concat and I’m going to pass in my string values let’s say India is in Asia let’s run this and see our result you can see see here it has concatenated everything let us make it more readable I’ll give a space in between so that you can read it clearly now this is much more readable India is in Asia and if you want you can give an alas name as well as let’s say merged there you go now the same concat operation you can also perform on a table I’m going to to use the same students table let’s say I want to return the student ID followed by the student name and then I am going to merge the student name followed by your space followed by the age of the student and I can give an alas as let’s say name _ AG from my table that is students let’s see how this works okay you see here the result is very clear we have the student ID the student name and the concatenated column that we created which was name _ age where we have the student name with a space followed by the age of the student if I scroll down you can see the rest of the results cool now moving ahead let’s see how the reverse function Works in MySQL so the MySQL reverse function returns a string with the characters printed in reverse order so suppose I write select reverse I’ll use the same string again let’s say I have India let’s run it you will see all the characters printed in reverse order again you can perform the same operation on a table as well let’s say I’ll write select reverse and I’ll pass in the column as student name from my table that is students let’s run it it gives you 20 students and all the names have been printed in reverse order okay now let’s see what the replace function does so the replace function replaces all occurrences of a substring within a string within a new substring so let me show you what I mean I’ll write select replace I’ll pass in my input string which is let’s say orange is a vegetable which is ideally incorrect I’m purposely writing this so that I can replace the word vegetable with fruit okay so what this replace function does is it is going to find where my word vegetable is within the string my input string and it is going to replace my word vegetable with fruit let’s run it and see the output there you go now this is correct which is Orange is a fruit all right now MySQL also provides some trim functions you can use the left trim right trim and just the trim function so let me show you how this left trim Works left trim or L trim removes the leading space characters from a string passed as an argument so see I write select I’ll use the left trim function which is L trim and then I’m going to purposely give a few pces in the beginning of the string I’ll give a word let’s say India and then I’ll give some space after the word India and see how the elri works if I run this it gives me India which is fair enough but before that let’s first find the length of my string so I’ll use my length function here and within this function I am going to find the length of my string which has India along with some leading and trailing spaces I’ll paste this here give a semicolon and I’ll run it okay so the entire string is 17 characters long or the length of the string is 17 now say I use lrim on my same string what it returns me is India and if I run length over it you can see the difference as in you can see how many spaces were deleted from the left of the string you can see here now it says 17 and I’m going to use lrim let’s see the difference it gives me 12 the reason being it has deleted five spaces from the left you can count it 1 2 3 4 and 5 so 17 – 5 is 12 which is correct similarly you can use the rri function which removes the trailing spaces from a string trailing spaces are these spaces when you use left Rim it deletes the leading spaces which is this now let me just replace L trim with r trim which stands for right trim and see the result so the length is 10 now the reason being it has deleted seven spaces from the right of the string if you can count it 1 2 3 4 5 6 and 7 cool you can also use the trim function which will delete both the leading and the TR in spaces so here if I just write trim and I’ll run it it gives me five because India is total five characters long and it has deleted all the leading and the trailing spaces all right there’s also a function called position in MySQL the position function Returns the position of the first occurrence of a substring in a string so if the substring is not found with the original string the function will return zero so let’s say I’ll write select position I want to find where fruit is in my string that is Orange is a fruit I’ll give an alas as name there some error here this should be within double quotes now let’s run it and see the result okay it says at the 13th place or at the 13th position we have the word fruit in our string which is Orange is a fruit now the final function we are going to see is called asky so the asky function Returns the asky value for a specific character let’s say I write select ask key of the letter small a if I run this it will give me the ask key value which is 97 let’s say you want to find the ask key value of 4 let’s see the result it gives me 52 all right in this session we are going to learn two important SQL statements or Clauses that are widely used that is Group by and having first we’ll understand the basics of group by and having and then jump into my SQL workbench to implement these statements so let’s begin first what is Group by in SQL so the group by statement or Clause groups records into summary rows and returns one record for each group it groups the rows with the same group by item expressions and computes aggregate functions for the resulting group a group by Clause is a part of Select expression in each group no two rows have the same value for the grouping column or columns now below you can see the syntax of group by so first we have the select statement and Then followed by the column names that we want to select from we have the table name followed by the wear condition and next we have the group by clause and here we include the column names finally we have the order by and the column names now here is an example of the group by Clause so we want to find the average salary of employees for each department so here you can see we have the employees table it has the employee ID the employee name the age of the employee we have the gender the date on which the employeer had joined the company then we have the department to which each of these employees belong to we have the city to which the employees belong to and then we have the salary in dollars so actually we’ll be using this employees table on my SQL workbench as well so if you were to find the average salary of employees in each department so this is how your SQL query with Group by Clause would look like so we have selected department and then we are using an aggregate function that is AVG which is average and we have chosen the salary column and here we have given an alias name which is average uncore salary which appears in the output you can see here from employees and we have grouped it by department so here in the output you can see we have the department names and the average salary of the employees in each department now let me take you to my MySQL workbench where we’ll Implement Group by and solve specific problems okay so I am on my MySQL workbench so let me make my connection first I’ll enter the password so this will open my SQL editor so first of all let me check the databases that I have so I’ll use my query that is show databases let’s run it okay you can see we have a list of databases here I’m going to use my SQL intro database so I’ll write use SQL intro so this will take us inside this database I run it all right now you can check the tables that are present in SQL intro database if I write show tables you can see the list of tables that are already present in this database to do our demo and understand Group by as well as having let me first create an employee table so I’ll write create table employees next I’ll give my column name as employee _ ID which is the ID for each employee I’ll give my data type as integer and I’ll assign employee ID as my primary key next I’ll give employee name and my data type would be varar I’ll give the size as 25 my third column would be the age column age would obviously be an integer then I have my gender column I’ll use character data type and assign a value of one or size of one next we have the date of join and the data type will be date we have the department column as well this is going to be of varar and 20 will be the size next we have the city column which is actually the city to which the employee belongs to and finally we have the salary column which will have the salary for all the employees okay now let me select and run this you can see here we have successfully created our table now to check if our table was created or not you can use the describe command I’ll write describe employees you can see the structure of the table so far all right now it’s time for us to insert a few records into this employees table so I’ll write insert into employees and I’ll copy paste the records which have already written on a notepad so let me show you so this is my EMP notepad and you can see I have already put the information for all the employees so let me just copy this and we’ll paste it here all right let me go to the top and verify if all the records are fine all right so let’s run our insert query okay so you can see here we have inserted 20 rows of information and now let’s check the table information or the records that are present in our employees table I’ll write select star from employees if I run it you can see here I have my employee ID the employee name age gender we have the city salary and in total we have inserted 20 records now let me run a few SQL commands to check how the structure of our table is let’s say I want to see the distant cities that are present in our table so I’ll write select distinct City from employees if I run on this you see here there are total eight different cities present in our employees table so we have Chicago the Seattle Boston we have New York Miami and Detroit as well now let’s see you want to know the total number of departments that are present so you can use distrct Department if I run this all right you can see we have seven rows returned and here are the department names so we have sales marketing product Tech it finance and HR all right now let me show you another SQL command now this is to use an aggregate function so I want to find the average age of all the employees from the table so I can write select AVG which is the aggregate function for average inside that I have passed my age column from employees if I run this so the average age of all the employees in our table is 33.3 now say you want to find the average age of employees in each department so for this you need to use the group by Clause I’ll give a comment here I want to find the average each in each department so I’ll write select Department comma I’ll write average of age from employees Group by department now if I run this you can see here we have our seven departments on the left and on the right you can see the average age of employees in each of these departments now you can see here in the output it says AVG of age which is not readable so I can give an alas name as average age all right I can bring this down and if you want you can round the values also so you can round the decimal places so I’ll use a round function before the average function and the round function takes two parameters one is the variable and the decimal place you want to round it to so if I run this there you go you can see here we have the average age of all the employees in each of these departments all right now suppose you want to find the total salary of all the employees for each department so you can write select Department comma Now I want the total salary so I’ll use the sum function and I’ll pass my column as salary from employees Group by Department let’s run this query you can see here in the output we have the different departments and on the right you can see the total salary of all the employees in each of these departments now here also you can give an alas name as total underscore salary let’s run it again and you can see the output here all right now moving ahead you can also use the aut by Clause along with the group by Clause let’s say you want to find the total number of employees in each City and group it in the order of employee ID so to do this I can use my select query I’ll write select count of let’s say employee ID and I want to know the city as well from employees Group by City And next you can use the order by Clause I’ll write order by count of employee ID and I’ll write DEC which stands for descending if I run this query you can see here on the left you have the count of employees and on the right you can see the city names so in Chicago we had the highest number of employees working that was four then we had Seattle Houston Boston Austin and the remaining also had two employees so in this case we have ordered our result based on the count of employee ID in descending order so we have the highest number appearing at the top and then followed by the lowest okay now let’s explore another example suppose we want to find the number of employees that join the company each year we can use the year function on the date of joining column then we can count the employee IDs and group the result by each year so let me show you how to do it so I’ll write select I’m going to extract Year from the date of join column I’ll give an alas as year next I’ll count the employee ID from my table name that is employees and I’m going to group it by Year date of join we give a semicolon all right so let’s run this great you see here in the result we have the year that we have extracted from the date of join column and on the right you can see the total number of employees that joined the company each year so we have in 2005 there was one employee similarly we have in 2009 there were two employees if I scroll down you have information of other years as well now if you want you can order this as well based on year or count okay now you can also use the group bu to join two or more tables together so to show you this operation let me first create a sales table so I’ll write create table sales and the sales table will have column such as the product ID which is going to be of integer type then we have the selling price of the product now this will be a float value then we have the quantity sold for each of the products so I’ll write quantity quantity will of integer type next we have the state in which the item was sold and state I’ll put it as worker and give the size as 20 let’s run this so that we’ll create our sales table all right so we have successfully created our sales table next we need to insert a few values to our sales table so I’ve have already written the records in a notepad let me show you okay so here you can see I have my sales text file let me just copy these information I’ll just paste it on the query editor okay now let me go ahead and run this insert command all right so you can see here we have successfully inserted nine rows of information so let me just

    run it through what we have inserted so the First Column is the product ID column then we have the selling price at which this product was sold then we have the quantity that was sold and in which state it was sold so we have California Texas Alaska then we have another product ID which is 123 and these are the states in which the products were sold so let me just confirm with the select statement I’ll write select star from sales I run this you can see we have successfully created our table okay now suppose you want to find the revenue for both the product IDs one to one and let’s say 1 to three since we have just two product IDs here so for that you can use the select query so I’ll write select product ID next I want to calculate the revenue so revenue is nothing but selling price multiplied by the quantity so I’ll use the sum function to find the total revenue and inside the sum function I’ll use my selling price column multiplied by my quantity column I’ll give this an alas name as revenue from my table name that is sales finally I’ll group it by product ID let’s run it there you go so here you can see we have the two product IDs one 121 and 1 12 3 and here you can see the revenue that was generated from these two products all right now let’s see we have to find the total profit that was made from both the products 1 to 1 and 1 to 3 so for that I’ll create another the table now this table will have the cost price of both the products so let me create the table first I’ll write create table let’s say the table name is C product which stands for the cost price of the products I’ll give my first column as product ID this will be an integer and I’ll have my second column as cost price cost price will have floating type values let’s run this so we have successfully created our product cost table now let me insert a few values into the C product table so I’ll write insert into ccore product I’ll give my values for one to one let’s say the cost price was $270 for each and next we have my product as 123 and let’s say the cost price for product 1 123 was $250 let’s insert these two values okay next we’ll join our sales table and the product cost table so this will give us the profit that was generated for each of the products so I’ll write select C do productor ID comma I’ll write sum s. cellor price now here C and S are alas names so if I subtract my cost price from the selling price that will return the profit that was generated I’ll multiply this with s do quantity close the bracket I’ll give an alas name as profit from sales as s so here s stands for the sales table I’m going to use inner join ccore product table as the Alias name should be C where s do productor ID is equal to C do productor ID we are using product underscore ID because this column is the common column to both the tables and finally I’m going to group it by C do productor ID all right so let me tell you what I have done here so I’m selecting the product ID next I’m calculating the profit by subtracting the cost price from the selling price and I multiplied the quantity column I’m using an join to connect my sales and the product cost table and I am joining on the column that is product ID and I have grouped it by c. product ID let’s run this there you go so here you can see for product id1 121 we made a profit of $1,100 and for product ID 1 123 you made a profit of $840 so now that we have learned Group by in detail let’s learn about the having clause in SQL the having clause in SQL operates on grouped records and returns rows where aggregate function results matched with given conditions only so now having and wear Clause are kind of similar but we Clause can’t be used with an aggregate function so here you can see the syntax of having Clause you have the select statement followed by the column names from the table name then we have the we conditions next we have the group bu finally we have having and at last we have order by column names so you can see here we have a question at hand we want to find the cities where there are more than two employees so you can see the employee table that we had used in our group by Clause as well so if you were to find the cities where there are more than two employees so this is how your SQL queries should look like so we have selected the employee ID and we are finding out the count using the count function next we have selected the city column from employees we have grouped it by City And then we have used our having Clause so we have given our condition having count of employee ID should be greater than two so if you see the output we have the different city names and these were the cities where the count of employees was greater than two all right so let’s go to our MySQL workbench and Implement how having works so suppose you want to find those departments where the average salary is greater than $75,000 you can use the having clause for this so let me first run my table which is employees if I run this you can see we had inserted 20 rows of information and the last column we had was salary so the question we have is we want to find those departments where the average salary is greater than $75,000 so let me show you how to do it so I’ll write select Department comma I’ll use the aggregate function that is average salary I’ll give an alas name as AVG underscore salary from employees next we’ll use the group by clause and I want to group it by each department and then I’m going to write my having Clause so in having Clause I’ll use my condition that is having average of salary greater than $75,000 let’s run it and see the output there you go so here you can see there were total three departments in the company that is sales finance and HR where the average salary is greater than $775,000 okay next let’s say you want to find the cities where the total salary is greater than $200,000 so this will again be a simple SQL query so I’ll write select City comma I want to find the total salary so I’ll use the sum function and I’ll pass my column as salary as I’ll give a alas name as total from employees Group by City And then I am going to use my having Clause I’ll pass in my condition as having sum of salary greater than $200,000 all right so let’s run this query there you go so so the different cities are Chicago Seattle and Houston where the total salary was greater than $200,000 now suppose you want to find the Departments that have more than two employees so let’s see how to do it I’ll write select Department comma this time since I want to find the number of employees I’m going to use the count function I’ll write count Star as employee uncore count or empore count which is my alas name from employees next I’ll group it by Department having I’ll give my condition count star greater than 2 let’s run this okay so you have departments such as sales product Tech and it where there are more than two employees okay now you can also use a wear Clause along with the having clause in an SQL statement so suppose I want to find the cities that have more than two employees apart from Houston so I can can write my query as select City comma count Star as EMP count from employees where I’ll give my condition City not equal to Houston I’ll put it in double code since I don’t want to see the information regarding Houston I’ll group it by City having count of employees greater than two so if I run this query you see we have information for cicago and cattl only and we have excluded the information for Houston now you may also use aggregate functions in the having Clause that does not appear in the select Clause so if I want to find the total number of employees for each department that have an average salary greater than $75,000 I can write it something like this so select Department comma count star as EMP count from employees Group by department and in the having Clause I’m going to provide the column name that is not present in the select expression so I’ll write having average salary greater than 75,000 this is another way to use the having Clause let’s run this all right you can see we have department sales finance and HR and you can see the employ count where the average salary was greater than 75,000 okay so let me run you from the beginning what we did in our demo so first we created a table called employee then we inserted 20 records to this table next we explored a few esql commands like distinct then we used average and finally we started with our group by Clause followed by looking at how Group by can be used along with another table and we joined two tables that was sales and product cost table to find out the profit then you learned how to use the having Clause so we explored several different questions and learned how to use having an SQL in this session we will learn about joints in SQL joints are really important when you have to deal with data that is present on multiple tables I’ll help you understand the basics of joints and make you learn the different types of joints with Hands-On demonstrations on MySQL workbench so let’s get started with what are joints in SQL SQL joint statement or command is often used to fetch data present in multiple tables SQL joints are used to combine rows of data from two or more tables based on a common field or column between them now consider this example where we have two tables an orders table and a customer table now the order table has information about the order ID which is unique here we have the order date that is when the order was placed then we have the shipped date this has information about the date on which the order was shipped then we have the product name which basically is the names of different products we have the status of delivery whether the product was delivered or not or whether it was cancelled then we have the quantity which means the number of products that were ordered and finally we have the price of each product similarly we have another table called customers and this customer table has information about the order ID which is the foreign key here then we have the customer ID which is the primary key for this table we also have the phone number customer name and address of the customers now suppose you want to find the phone numbers of customers who have ordered a laptop now to solve this problem we need to join both the tables the reason being the phone numbers are present in the customers table as you can see here and laptop which is the product name is present in the orders table which you can see it here so using a join statement you can find the phone numbers of customers who have ordered a laptop now let’s see another problem where you need to find the customer names who have ordered a product in the last 30 days in this case we want the customer name present in the customer’s table and the last 30 days order information which you can get from the order date column that is present in the orders table okay now let’s let’s discuss the different types of joints one by one so first we have an inner joint so the SQL inner joint statement returns all the rows from multiple tables as long as the conditions are met from the diagram ADB you can see that there are two tables A and B A is the left table and B is the right table the orange portion represents the output of an inner joint which means an inner joint Returns the common records from both the tables now you can see the syntax here so we have the select command and then we give the list of columns from table a which you can see here is the left table followed by the inner join keyword and then the name of the table that is B on a common key column from both the tables A and B now let me take you to the MySQL workbench and show you how inner join Works in reality so here I’ll type MySQL you can see I have got my SQL workbench 8.0 version installed I’ll click on it it will take some time to open okay I’ll click on this local instance and here I’ll give my password okay so this is how an SQL editor on my SQL workbench looks like so first of all let me go ahead and create a new database so I’ll write create database this is going to be my command followed by the name of the database that is going to be SQL joints I give a semicolon and hit control enter this will create a new database you can see here one row affected now you can check whether the database was created or not using show databases command if I run it here you can see I have SQL joints database created now I’ll use this database so I’ll write use SQL joints okay now to understand inner join consider that there is a college and in every College you have different teams for different sports such as Cricket football basketball and others so let’s create two tables cricket and football so I’ll write create table and my table name is going to be cricet next I’m going to create two columns in this table the First Column is going to be cricet ID then I’m going to give the data type as int and use the autoincrement operator I’m using Auto increment because my Cricket ID is going to be my primary key then I’m going to give the name of the students who are part of the cricket team and for this I’ll use war card data type and give the length as 30 I’ll give another comma and I’ll assign my Cricket ID as primary key within brackets I’ll give ccore ID cricket ID is nothing but a unique identifier for each of the players like you have role numbers in college okay let me just run it all right so we have successfully created our cricket table similarly let me just copy this and I’ll paste it here I’ll create another table called football this will have the information of all the students who are part of the football team and instead of cricket I am going to give this as football idid all right and the name column will have the names of the students I’ll change my primary key to football ID all right let me run this okay so now we have also created our football table the next step is to insert a few player names into both the tables so I’ll write my insert into command first let’s load some data to our cricket table so I’ll write cricet and I’ll give my name column followed by values and here I’ll give some names such as let’s say Stuart we give another comma the next player I’ll choose is let’s say Michael similar I’ll add a few more let’s say we have Johnson the fourth player I’ll take is let’s say hidden and finally we have let’s a Fleming okay now I’ll give a semicolon and run this okay so let me just check if all the values were inserted it properly for this I’ll use select star from table that is Cricket if I run it you can see I have created a table and have successfully inserted five rows of information now similarly let’s insert a few student names for our football table so I’ll change this to football and obviously there would be students who will be part of both cricket and football team so I’ll keep a few repeated names let’s say Stuart Johnson and let’s say Hayden are part of both cricket and football team then we have let’s say Langer and let’s say we have another player in the football team that is astral I’ll just run it okay you can see there are no errors so we have successfully inserted values to our football team as well let me just recheck it I’ll write select star from football all right so we have five players in the football team as well okay now the question is suppose you want to find the students that are part of both the cricket and football team in this case you can use an inner join so let me show you how to do it so I’ll write select star from cricket as I’m using an alias name as C which stands for Cricket then I’m going to write inner join my next table is going to be football as F which is an alas name for the football table then I’m going to use the on command or operator and then I’ll give the common key that is name here so C do name is equal to F do name So based on this name column from both the table my inner John operation will be performed so let’s just run it there you go so Stuart Johnson and Hayden are the only three students who are part of both the teams all right now you can also individually select each of the columns from both the tables so let’s say I write select c. ccore ID comma C do name comma F do football ID comma f. name from I’ll write Cricket as C inner join football as F on C do name is equal to F do name now if I run this you see we get the same output here as well all right now let’s explore another example to learn more about inner joints so we have a database called classic models let me first use classic models I’ll run this okay now let me just show the different tables that are part of classic tables all right so here you can see there are tables like customers there’s employees office there’s office details orders payments products and product lines as well all right so let me use my select statement to show what are the columns present in the products table okay so this product table has information about different product names you have the product code now this product code is unique here we also have the product vendor a little description about the product then we have the quantity in stock buying price and MSRP let’s see what we have in product lines if I run it you see here we have the product line which is the primary key for this table then we have the textual description for each of the products this is basically some sort of an advertisement all right now suppose you want to find the product code the product name and the text description for each of the products you can join the products and product lines table so let me show you how to do it I’ll write my select statement and choose my columns as product code then we have product name and let’s say I want the text description so I’ll write this column name okay then I’ll use from my first table that is products inner join product lines I can use using the common key column that is product line close the bracket I’ll give a semicolon and if I run it there you go so you can see the different product codes then we have the different product names and the textual description for each of the products so this we did by joining the products table and the product lines table all right now suppose you want to find the revenue generated from each product order and the status of the product to do do this task we need to join three tables that is orders order details and products so first let me show you what are the columns we have in these three tables you have obviously seen for the products table now let me show you for orders and Order details table so I’ll write select star from orders if I run it you can see it has information about the order number the date on which the order was placed we also have the shipment date we also have the status column which has information regarding whether the order was shipped or cancelled then we have some comments column we also have the customer number who ordered this particular product similarly let’s check what we have under order details so I’ll write select star from order details if I run it you can see it has the order number the product code quantity of each product we have the price of each product then we have the order line number okay so using the product orders and Order details let’s perform an inner join so I’ll write select o do order number comma o do status comma I need the product name which I’ll take from the products table so I’ll write P do product name now here o p are all alas name for the tables orders products and I’ll use OD for order details comma since we want to find the revenue we actually need to find the product of quantity ordered into price of each product so I’ll use a sum function and inside the SU function I’ll give quantity ordered multiplied by the price of each item I’ll use an alas as Revenue then I’ll use my from Clause from orders as o inner join order details as I’ll use an alas name as OD on I’ll write o do order number is equal to OD do order number I’ll use another inner join and this time we’ll join the products table so I’ll write inner join products as p on P do product code is equal to OD do product code and finally I’ll use the group by clause and group it by order number all right let me run this okay there’s some mistake here we need to debug this it says you have an error in your SQL syntax check the manual all right okay I think the name of the tables is actually orders or not order all right now let’s run it okay there’s still some error it says classic models. product doesn’t exist so so again the product name is I mean the table name is products and not product so let’s run it again all right there you go so we have the order number the status the product name and the revenue this we got it using inner join from three different tables now talking about left joins the SQL left join statement returns all the rows from the left table and the matching rows from the right table so if you see this diagram you can see we have all the rows from the left table that is a and only the matching rows from the right table that is B so you can see this overlapped region and the Syntax for SQL left join is something like this so you have the select statement and then you give the list of columns from table a which is your left table then you use the left join keyword followed by the next table that is table B on the common key column so you write a do key is equal to B do key okay now in our classic models database we have two tables customers and orders so if you want to find the customer name and their order ID you can use these two tables so first let me show you the columns that are present in customers and orders I think orders we have already seen let me first show you what’s there in the customer table okay so you can see we have the customer number the name of the customer then we have the contact last name the contact first name we have the phone number then there’s an address column there are two address columns actually we have the city name the state and we have other information as well and similarly we have our orders table so I’ll write select start from orders so I’ll write select star from orders if I run this you can see these are the information available in the orders table okay so let’s perform a left join where we want to find the customer name and their order IDs so I’ll write select C do customer name or let’s say first we’ll choose the customer number comma then I want the customer name so I’ll write C do customer name then we have the order number column which is present in the orders table and let’s say I also want to see the status then I’ll give my left table that is customers as C left join orders as o on C Dot customer number equal to O do customer number let’s run it okay again there is some problem all right so the table name is customers let’s run it so there’s another mistake here this is customer number so B is missing cool let me run it all right so here you can see we have the the information regarding the customer number then the respective customer names we have the order number and the status of the shipment so if I scroll down you’ll notice one thing there are a few rows you can see which have null values this means for customer number 125 and for this particular customer name there were no orders and similarly if I scroll down you will find a few more null values you can see here there are two null Val values here for customer number 168 and 169 there were no orders available all right now to check those customers who haven’t placed any orders you can use the null operator so what I’ll do is here I’ll just continue with this I’ll use a where clause and write where order number is null now let me run this okay so here you can see there are 24 customers from the table that don’t have any orders in their names okay now talking about right joins so SQL right join statement returns all the rows from the right table and only matching rows from the left table so here you can see we have our left table as a and the right table as B so the right join will return all the rows from the right table and only the matching rows from the left table now talking about the syntax so here you can see we have the select statement followed by the select statement you’ll have the list of columns that you want to choose from table a write join table B on the common key column from both the tables all right now to show how write join works I’ll be using two tables that is customers and employees so let’s see the rows of data that are present in the customer table first so I’ll write select star from customers let’s run it so here you have the customer number the customer name then we have the phone number the address of the customers you also have the country to which the customer belongs to the postal code and the credit limit as well similarly let’s see for the employees table here I’ll change customer customers to employees let’s run it okay so we have the employee number the last name the first name you have the extension the email ID the job title and also reports to here means the manager okay so based on these two tables we’ll find the customer name the phone number of the customer and the email address of the employee and join both the tables that is customers and employees so let me show you the command so I’ll write select C do customer name comma then we have C do phone I’ll give a space here next I want the employee number from the employee table so I’ll write e do employee number comma e do email from customers as C right join employees as e on E do my common key column is employee number here so I’ll write e do employee number is equal to C dot we have sales Representatives employee number and I’m also going to order it by the employee number column okay so you can see I have my customer name selected from the customers table the phone number of the customer then we have the employee number and the email address so let me run it okay there’s some problem all right so the table name is customers actually let’s run it once again there you go so you can see here we have all the values selected from our right table which is the employees table you can see right on employees which means your employees table is to the right and then we have the customer name and phone numbers of the customers from the customer table which is actually your left table so you have a few employee number such as one2 this 1056 which don’t have any customer name or phone numbers okay so there’s another popular join which is very widely used in SQL known as self joints so self joints are used to join a table to itself so in our database we have a table called employees let me show you the table first all right so here you can see we have the employee number the last name the first name of the employee you have the email ID and here if you see we have a column called reports 2 now this you can think of as the manager column so the way to read is for example for employee number 1056 the manager is one2 so if you check for one2 we have Dane Murphy then if I scroll down let’s say for employee number 1102 yeah for employee number 1102 the manager is 1056 so here you can see who is at 1056 you have Mary Patterson similarly if I scroll down let’s say for employee number 11 188 we have the manager as 11 43 now if I check the table at 1143 we have Anthony bow so so the employee Julie feli reports to Anthony bow all right now suppose you want to know who is the reporting manager for each employee so for that you can use a self jooin so let me show you how to join this employees table I’ll write select and then I’m going to use a function called concat within brackets I’ll start with my alas name that is m dot then I’ll write last name I’m going to concat last name followed by a comma then I’ll have my first name I’ll close this bracket and then I’m going to give my alas name let’s say manager here comma next I’m going to concat the same last name and first name and this time I’m going to use a separate alas let’s say e which stands for employee so I’ll write e do last name comma and within single codes I’ll give my comma and then I’ll write e do first name I close this bracket I’ll give an alas as let’s say employee from I’ll write employees as e inner join employees as M on M do I’ll use my common key column as employee number so I’ll write M do employee number is equal to e do here I’m going to use the reports two column and then I’ll order it by let’s say manager okay now let’s run this there you go so you have your two columns as manager and employee so for employee Louie bonder the manager is zarad bonder similarly if I scroll down you have there are multiple employees reporting to this particular manager similarly we have our manager as Anthony bow and we have different employees who are reporting to this particular manager and so on all right now moving ahead now let’s see what a full join is so SQL full outer join statement returns all the rows when there is a match in either left or right table now you must remember that MySQL workbench does not support full outer join by default but there’s a way to do it so by default this is how the syntax of full outer joint looks like now this statement will work on other SQL databases like micros moft SQL server but it won’t work on MySQL workbench I’ll show you the right way of using full auto join on MySQL workbench so to show full outer join I’m going to first use a left join and then we’ll also use a right join and finally we’ll use a union operator so the union operator is used to combine the result set of two or more select statements so first of all let me write C do customer name so for this example I’m using the customer table and the order table comma o do order number so I just want to know the customer name and the order number related to the customer from I have customers as C left join I’ll write orders as o on C do customer number is equal to O do customer number let me just copy this and after this I’m going to use my union operator so Union operator is used to merge results from two or more tables so basically this performs a vertical join and next I am going to use my right join operation so here instead of left join I’ll write right rest all looks fine let me just run it there you go so we have successfully run our full outer join operation you can see we have the different customer names and the order that each customer had placed all right so that brings us to the end of our demo session so let me just run through whatever we did in this session so first we created a database called SQL joints then we created two tables like cricket and football then we had inserted a few rows to each of these tables then we used this table to learn about inner join next we used a database called classic models it had multiple tables so we explored all of these tables like products there was product lines orders customers and employees and learned how to use inner join left join self join right join as well as full outer join in this video we will learn what is a subquery and look at the different types of subqueries then we learn subqueries with select statement followed by subqueries with insert statement moving further we will learn subqueries with the update statement and finally we look at subqueries with delete statement all these we will be doing on our MySQL workbench so before I begin make sure to subscribe to the simply learn Channel and hit the Bell icon to never miss an update so let’s start with what is a subquery so a subquery is a select query that is enclosed inside another query so if I show you this is how the basic structure of a subquery looks like so here whatever is present inside the brackets is called as the inner query and whatever is present outside is called the outer query so first the inner query gets executed and the result is returned to the outer query and then the outer query operation is performed all right now let’s see an example so we have a question at hand which is to write a SQL query to display Department with maximum salary from employees table so this is how our employees table looks like it has the employee ID the employee name age gender we have the date of join Department City and salary now to solve this query my subquery would look like this so I’ll first select the department from my table that is employees where I’ll use the Condition salary equal to and then I’ll pass in my inner query which is Select Max of salary from employees so what this does is it will first return the maximum salary of the employees in the table then our outer query will get executed based on the salary returned from the inner query so here the output is department sales has the maximum salary so one of the employees from the sales department earns the highest of the maximum salary if you see in our table the employee is Joseph who earns $115,000 all right and Joseph is from the sales department now let’s see how this query works so here we have another question which is to find the name of the employee with maximum salary in the employees table so this is our previous employees table that we saw and to find the employee who has the maximum salary my subquery would look something like this so I’m selecting the employee name from my table that is employees where I’m using the Condition salary equal to and then then I’m passing in my subquery or the inner query so first I’m selecting the maximum salary this will return a particular value that is the highest salary from the table and if you see our table the highest salary is $115,000 so our query becomes select employee name from employees where salary equal to $115,000 so the employee name is Joseph here and that’s the output now if you want to break it down here you can see first the inner query gets executed so our SQL query will first execute the inner query that is present inside brackets select maximum salary from employees the result is $115,000 and then based on the returned result our outer query gets executed so the query becomes select employee name from employees where salary equal to $115,000 and that employee is Joseph all right now we’ll learn the different types of subqueries so you can write subqueries using select statement update statement delete and insert statement we’ll explore each of this with the help of example on my my SQL workbench so let’s learn subqueries with the select statement so subqueries are majorly used with the select statement and this is how the syntax looks like you select the column name from the table name then you have the WHERE condition followed by The Columns that you want to pass the operator and inside that you have the subquery so here is an example that we will perform on our MySQL workbench so in this example we want to select all the employees who have a salary less than average salary for all the employees this is the output so let’s do this on my MySQL workbench all right so let me log into my local instance I’ll give my password okay so you can see I’m on my MySQL workbench so let’s start by writing our subquery using the select statement okay so for this demo session we’ll be using a database that is subqueries you can see it here I have a database called subqueries so I’ll use this subqueries database and we’ll create a few tables as well okay if I run it now we are inside the subqueries database so let me just show you the tables that are present inside this database I’ll write show tables if I run it okay there are two tables employees and employees undor B uh we’ll use this table throughout our demonstration all right now for our select subquery we want to fetch the the employee name the department and the salary whose salary is less than the average salary so we will be using the employees table so let me first show you the records and the columns we have in the employees table so I’ll write select star from employees and run it okay you can see here we have 20 rows of information we have the employee name the employee ID age gender date of join Department City and salary so this is the same table that we saw in our slide slides okay now for our subquery I’ll write select I want to choose the employee name the department and the salary there should be a comma here instead of a period next I’ll give my table name that is employees where my salary is less than and after this I’ll start my inner query or the subquery I’ll write select average salary so I’m using the AVG function to find the average salary of all the employees from my table that is employees if I give a semicolon and run this you’ll see the output so we have total 12 employees in the table whose salary is less than the average salary now if you want you and check the average salary so the average salary is $753 now the employees who have a salary less than the average salary so these are the people all right now moving back to our slides okay now let’s see how you can use subqueries with the insert statement now the insert statement uses the data return from the subquery to insert into another table so this is how the syntax looks like so you write insert into table name followed by select individual column so start from the table use the wear clause and then you give the operator followed by the inner query or the subquery so here we will explore a table called products table we are going to fetch few records from the products table based on a condition that is the selling price of of the product should be greater than $100 so only those records will fetch and put it in our orders table all right so we are going to write this query on my MySQL workbench so let’s do it I’ll give my comment as update subquery all right so first of all let’s create a table that is products so I’ll write create table products then we’ll give our column names the First Column would be the product ID of type integer then we have the column as item or the product which is of type Vare 30 next we have the selling price of the product the selling price will be of type float and finally we have another column which is called the product type and again product type is of the data type bar car I’ll give the size as 30 close the bracket and give a semicolon now let’s just run it okay so we have successfully created our products table now let’s insert a few records to our products table so I’ll write insert into products for followed by values I’ll give four records the first product ID is 101 the product is let’s say jewelry then the selling price is let’s say $800 and the product type is it’s a luxury product next let’s insert one more product detail the product ID is 102 the product is let’s say t-shirt the price is let’s say $100 and the product type is non-luxury next I’ll just copy this to reduce our task we’ll edit this the third product’s ID is 103 the product is laptop and let’s say the price is $1,300 and it’s a luxury product I’ll paste again and finally I’ll enter my fourth product which is let’s say table and the price is $400 and it’s a non-luxury product I’ll give a semicolon and we’ll insert these four records to our products table you can see see we have inserted four records let’s just print it now so I’ll write select star from products if I run it you can see we have our four products ready now we need to create another table where we are going to put some records from our products table so that new table is going to be the orders table so I’ll write create table orders now it will have three columns the order ID order ID will be of type integer then we have product underscore sold this will be of type varing character of size 30 and finally we have the selling price column this will be of type float let’s create our orders table the table name should be orders and there is some mistake here okay we should close the brackets okay let me run it so we have our orders table ready now let’s write our insert subquery so I’m going to insert into my table that is orders and I’ll select the product ID comma the item and the selling price or the sell price from my table that is products where I’ll write product ID in I’ll write my inner query select prodad ID or the product ID from products next I’ll give a wear Clause where the selling price is greater than $11,000 so let me tell you what I’m going to do here I’m going to insert into my orders table the product ID the item name and the s selling price from my products table where the product ID has this condition so let me first run this condition for you which is Select prod ID from products where the selling price is greater than 1,000 if I run this okay there is some issue here the column name is actually prodad ID now let’s run it again so that we can see the product IDs of the products which have a selling price greater than 1,000 so it is 101 and 103 now let’s run the entire query there is another mistake here let’s debug the mistake now this should be product ID instead of product _ in let’s insert again all right so we have successfully inserted two records to our table that is orders now let’s see the orders table I’ll write select star from orders if I run it there you go so there were two products from our product table that were jewelry and laptop which have a selling price greater than $11,000 so the selling price for jewelry was $1,800 and for laptop it was $1,300 so this is how you can use a subquery using the insert statement all right now going back to our slides again all right now let’s see how you can use subqueries with the update statement now the sub sub queries can be used in conjunction with the update statement so either single or multiple columns in a table can be updated when using a subquery with the update statement so this is how the basic syntax of an update subquery looks like so you write update table followed by the table name you set the column name you give the we operator and then you write your inner subquery so we are going to see an example where we’ll use this employees table and using this employees table we will update the records of the salaries of the employees by multiplying it with a factor of 35 only for those employees which have age greater than 27 so we are going to use a new table called employees Corb for this as well so let’s see how to do it so I’ll give my comment as update subquery before we see the subquery let’s see what we have in the table employees Corb this is basically a replica of the employees table there you go it has the same records that our employees table has we are going to use both the employees table and the employees _ B table to update our records so I’ll write update employees set salary equal to let me bring this to the next line I’ll write set salary equal to salary multiplied by 35 where age in then I’ll write select age from my other table that is employees uncore B where age is greater than equal to let’s say 27 all right so let me run through this query and tell you what we are going to do so I’m going to update the records of the employees table specifically for the salary column so I’m checking if the age is greater than 27 then we’ll multiply the salaries of the employees with a factor of. 35 in the employees table let me just run this then we’ll see our output okay so it says 18 rows affected which means there are total 18 employees in the table out of the 20 employees whose age is greater than 27 now if you see I’ll write select star from employees you can see the difference in the salaries if I scroll to the right you can see these are the up updated salaries okay now if you check for employees who have an age less than or equal to 27 for example Marcus whose age is 25 his salary is the same we haven’t updated his salary then if you see if you have okay there is one more employee Maya we haven’t updated the salary of Maya because the age is less than 27 all right now let’s go back to our slides again as you can see we got the same output on our MySQL workbench now let’s explore how you can write subqueries with the delete statement now sub queries can again be used in conjunction with the delete statement so this is how the basic syntax of a delete query using subquery would look like you write delete from the table name where Clause the operator value followed by the inner query in within brackets so here we are going to use the employees table and what we are going to do is we’ll delete the employees whose age is greater than equal to 27 so let’s see how you can do it all right so I’ll give my comment as delete subquery so we’ll follow the syntax tax that we saw I’ll write delete from my table name that is employees I’ll write where age in and then I’ll start my inner query or the subquery I’ll write select age from employees uncore B where AG is let’s say greater than equal to 32 or let’s say the AG is less than equal to 32 close the bracket and I’ll give my semicolon let me first run the inner query for you so that you get an idea of the employees who are less than 32 years of age so there are nine employees in the table who have an age less than equal to 32 so we are going to delete the records if I run this okay it says nine records deleted now let’s print or display what we have in the employees table if I run this there you go so if you see the age table we have total 11 employees now and all their ages are greater than 32 because we have deleted all those employees who had an age less than equal to 32 okay so let me show you from the beginning what we did so first we used our subqueries database then we used our employees table so we started by looking at how you can use the subquery with a select statement this should be insert instead of update so we learned how to write an insert subquery we use two tables products and our a table moving ahead we saw how to write subqueries using the update command so we updated the salaries of the employee by a factor of. 35 for those who had an age greater than equal to 27 and finally we saw how to use the subquery using the delete statement so we deleted all those records for the employees whose age was less than equal to 32 so let’s start with what is normalization normalization in dbms is a method used to organize data within database to reduce repetition by breaking down large data sets into smaller more manageable tables and ensuring these tables are properly related normalization helps prevent issues like data rency data rency means the unnecessary repetition or duplication of data within a database for example when a same piece of data is stored in multiple places it can lead to inconsistencies and take up more storage space than needed for example Data rency before normalization you can see the table mentioned above where we have order ID customer ID customer name customer address product and quantity you might see some of the data which is being repeated again and again in the above table the customer address for John do is repeated three times let’s suppose if John do moves to a new address every occurrence of his address in the table must be updated if any instances missed during the update it leads to inconsistencies and errors can occur in the database the solution is reducing the rency through normalization let’s check it out how so you can see this is the normalized table we have created first is the normalized customer table and then we have the order table so what are the benefits of normalization the address for JN do is stored only once in the customer table if JN do address changes it needs to be updated in one place ensuring consistency through the database this reduces the risk of errors and maintains data Integrity the process involves multiple steps that transform data into a tab below format removing duplicates and establishing clear connections between different tables making the database more efficient and reducing problems like errors during data insertion updates or deletion let’s now discuss the types of dbms normal forms normalization rules are categorized into different normal forms the first one is one and if for a table to be in first normal form it must satisfy the four rules single valued Atomic attributes each column should contain only one value per row this means that there should be no repeating groups or arrays within a single column same domain values all values stored in a specific column should be of the same data type or domain for example if a column is meant to store dates all values in that column should be dates then we have unique column names each column in the table should have a unique name this ensures Clarity and avoids confusion when referring to a specific column then we have order of data which doesn’t matter the order in which rows are stored in the table should not affect the data or its Integrity let’s check the example of the first normal form consider the following unnormalized table customer ID customer name and the phone numbers as you can see the phone numbers are repeated twice the problems with the original table is the nonatomic values the four numbers column contain multiple phone numbers separated by commas which violates the atomicity rule of 1 andf converting to First normal form to bring this table into one and F we must ensure that each column contains only Atomic value this involves splitting the rows where there are multiple phone numbers as you can see we have splitted the data each row now has a single phone number ensuring that the phone number column contains Atomic value same domain names all the values in the phone number column are consistent in format and type all are phone numbers then we can see that the unique column names the colums customer ID customer name phone number which has unique name satisfying the requirement order of data the order in which the rules appear does not matter as the data’s meaning and integrity are preserved by applying these rules the table now confirms the first normal form eliminating any rency related to the four numbers and ensuring data is stored in a more organized and efficient manner let’s go through each of these database normal forms step by step with simple examples to help you grasp the concepts more easily let’s talk about the second normal form for a table to be in second normal form it must satisfy the following condition number one it must be in one and F number two no partial dependency every non key attribute should be fully dependent on the entire primary key not just part of it this rule applies primarily to tables with composite primary Keys example of second normal form is consider the following table that is in one NF the order ID product ID product name quantity and the supplier name the problems with this table is that the partial dependency the product name and the supplier name depend only on product ID not the entire bio primary key which is order ID and product ID this violates 2nf converting to Second normal form to bring the table into 2nf we separate the data into two tables to remove partial dependencies order table and the product table no partial dependency in the order table quantity is fully dependent on both order ID and product ID in the product table product name and supplier name are dependent only on the product ID this ensures that each each non key attribute is fully dependent on the primary key bringing the tables into 2 andf let’s now talk about the third normal form 3 andf for a table to be in third normal form it must satisfy the following condition number one it must be in 2 andf number two there should be no transitive dependency where non-key attributes depend on other non-key attributes rather than the primary key let’s check out the example of a third normal form consider the following table that is in 2nf the problems with the tnf table is that the transitive dependency the instructor name is dependent on the course name which is not directly on student ID or course ID and this violates 3 andf so how do we convert this into 3 andf to achieve 3 andf we split the table to remove the transitive dependency student course table and course table no transitive dependency now the student course table there are no non-key attributes depending on other non-key attributes the course Table stores the course and instructor information separately this structure eliminates transitive dependency uring the tables conform to 3 andf Let’s now talk about the boys called normal form which is bcnf bcnf is an extension of the third normal form 3nf a table is in bcnf if it is in 3nf and for every functional dependency a implies to B A should be a Super Key let’s check out the example of a boy Squad normal for bcnf so you can see this table here consisting of employee ID department and the manager the problem with this table is that the bcn a violation in this table Department determines manager but department is not a Super Key since employee ID is the primary key this violates bcnf so how do we convert this to bcnf to achieve bcnf we split the table to ensure that every determinant is a Super Key as you can see the employee table and the department table the super key requirement in the employee table employee ID is the primary key and in the department table department is now the primary key the decomposition ensures that every functional dependency is Satisfied by a Super Key meeting the requirements of bcnf let’s now talk about the fourth normal form which is 4nf a table is set to be in 4nf if it is in bcnf and has no multivalue dependencies so let’s consider an example of a fourth normal form consider a table where an employee can have multiple skills and work on multiple projects as you can see the employee ID skill and the project the problem with this table is that it is multivalue dependency an employee skill is independent of the project but both are stored in the same table this leads to multivalue dependency violating 4nf so in order to achieve 4nf we separate the skills and the projects into different tables the employee skill table and the employee projects table and now you can see that no multivalue dependency by separating the skills and the projects we eliminate multivalue dependencies ensuring the table conform to for and let’s now talk about the fifth normal form the employee skill table and the employee projects table so as you can see that no multivalue dependencies is there by separating the skills and the projects we eliminate multivalue dependencies ensuring the tables conformed to 4 and F now let’s talk about the fifth normal form which is 5 and f a table is said to be in fifth normal form if it is in forf and cannot be decomposed into any smaller tables losing information also known as joint dependency let’s consider an example of a fifth normal form this is a table here that records the relationship between suppliers parts and the project the problem with this table is that the join dependency the table has a complex relationship between suppliers parts and projects that can be decomposed further so how do we convert this into fifth normal form form in order to achieve 5 andf we break the table into smaller related tables the suppliers part table and the suppliers project table also Parts project table eliminating joint dependency by decomposing the table into three smaller tables we remove the complex relationship and eliminate the joint dependency ensuring the tables confirmed to 5 andf So currently I am on my MySQL workbench let me connect to the local instance so I’ll give my pass word I’ll click on okay all right so this is my my SQL workbench query editor so first we are going to learn subqueries let me give a comment and write subqueries all right so first of all let’s understand what a subquery is so a subquery is a query within another SQL query that is embedded within the where Clause from clause or having Clause so we’ll explore a few scenarios where we can use subqueries so for that I’ll be using my database that is SQL uncore intro so I’ll write my command use SQL uncore intro now this database has a lot of tables I’ll be using the employees table that is present inside SQL intro Let me just expand this and you can see here we have an employees table so let me first show you the contents within this table I’ll write select star from employees let me execute it okay you can see here we have the employee ID employee name age gender there’s date of join Department City and salary and we have information for 20 employees if I scroll down you can see there are 20 employees present in our table so let’s say you want to find the employees whose salary is greater than than the average salary in such a scenario you can use a subquery so let me show you how to write a subquery I’ll write the select statement in the select statement I’ll pass my column names that I want to display so the column names I want are the employee name then I want the department of the employee and the salary of the employee from my table name that is employees next I’ll use use a we condition where my salary should be greater than the average salary of all the employees so I’ll write salary greater than after this I’m going to write my subquery so I’ll give select average of salary from my table name that is employees and I’ll close the bracket and give a semicolon so what it does is first it is going to find the average salary of all the employees that are present in our table once we get the average salary number we’ll use this wear condition where salary is greater than the average salary number so the inside subquery let me run it first if I run this this gives you the average salary of all the employees which is $275,300 now I want to display all the employees who have salary greater than $75,500 so let’s run our subquery there you go so there are eight employees in our table who have a salary greater than the average salary of all the employees all right next let’s see another example suppose this time you want to find the employees whose salary is greater than John’s salary so we have one employee whose name is John let me run the table once again okay if I scroll down you see we have an employee as John you see this our employee ID 116 is John and his salary is $67,000 I want to display all the employees whose salary is greater than John’s salary so B basically all the employees who are earning more than $65,000 I want to print them so let’s see how to do it I’ll write select I want the employee name comma the gender of the employee I also want the department and salary from my table name that is employees I’ll write where salary is greater than I’ll start my opening bracket inside the bracket I’m going to give my inner query that is Select salary from employees where the employee name is John So within single quotations I’ll give John as my employee I’ll end with a semicolon so let me first run my inner query so this will give us the salary that John has which is $67,000 now I want the employees who are earning more than $667,000 so let’s run our subquery okay so you can see 12 rows returned which means there are 12 employees in our table who are earning more than $67,000 you see here all these employees have a salary greater than6 $7,000 okay now you can also use subqueries with two different tables so suppose you want to display some information that are present in two different tables you can use subqueries to do that so for this example we’ll use a database that is called classic models you can see the first database so let me use this database called classic Model models I’ll write use classic models now this database was actually downloaded from the internet there’s a very nice website I’ll just show you the website name so this is the website that is MySQL tutorial.org you can see here they have very nice articles blogs from where you can learn my SQL in detail so we have downloaded the database that is classic models from this website you see here they have a MySQL sample database if you click on this it will take you to the link where you can download the database so they have this download link which says download my SQL sample database and the name of the database is classic Models All right so we are going to use this classic models database throughout our demo session if I expand the tables section you can see see there are a lot of tables that are present inside this classic models database we have Cricket customers there’s employees office there’s orders order lines and many more so for our subquery we’ll be using two tables that is order details and products table first let me show you the content that is present inside the products table first if I run this you see here it says 110 rows returned which means there are 110 different products that are present in our table which has the product code the product name product line we have the product vendor description quantity and stock Buy price MSRP the other table we are going to use is order details which has the details of all the orders let me show you the records order details tables has okay so there are thousand records present in this table you have the order number the product code quantity ordered price of each item you have the order line number as well okay now we want to know the product code the product name and the MSRP of the products whose price of each product is less than $100 for this scenario we are going to use two different tables and we are going to write a subquery okay so if you see here in the order details table we have a column called price each I want to display the product code the product name and the MSRP of the products which have a price of each product less than $100 so the way I’m going to do is I’ll write select product code comma product name now one thing to remember that this product name is actually present inside our products table and product code is present in both the tables that is products and Order details here you can see this is the product code column comma MSRP which is present inside the products table again from my table that is products where I’ll write product code I’m going to use the in operator next I’ll write my inner query that is Select product code from my table order details where my price of each product is less than $100 let me run this okay so you can see there are total 83 products in our table which have a price less than $100 you can see the price here okay now we learn another Advanced Concept in SQL which is known as stored procedures I’ll just give a comment saying stored procedure okay so first let’s understand what is a stored procedure a stored procedure is an SQL code that you can save so that the code can be reused over and over again so if

    you want to write a query over and over again save it as a stored procedure and then call it to execute it so in this example I want to create a stored procedure that will return the list of players who have scored more than six goals in a tournament so I have a database is called SQL IQ these are a few databases that I’ve have already created so this database has a table called players if I expand the tables option you see we have a table called players and you can see the columns player ID the name of the player the country to which the player belongs to and the number of goals each player has scored in a particular tournament so I’ll write a store procedure that will return the list of top players who have scored more than six goals in a tournament so first of all let me Begin by using my SQL IQ database we’ll run it so now we are inside the SQL IQ database let me select star from players to show the values that we have in the players table you can see there are six players in our table we have the player ID the names of the players the country to which these players belong to and the goals they have scored so I’ll write a stored procedure so the stor procedure syntax is something like this it should start with a D limiter okay in the D limiter I’ll write Amberson erson next I’ll write create procedure followed by the procedure name let’s say I want to name my procedure as topor players next statement is begin after begin I’ll write my select statement I want to select the name of the player the country and the goals each player has scored from my table that is players where I’ll write goals is greater than six we give a semicolon then I’ll end my procedure with a d limiter that was done double Amberson next I’ll write D limiter and give a semicolon now the semicolon suggests this is a default DM there should be a space okay now let’s run our stored procedure there you go so you have successfully created our store procedure now the way to run a store procedure is you need to use the call method and give the procedure name that is topor players in our case with brackets and a semicolon let’s execute it okay there is some problem here so we made a mistake while creating a procedure the name of the column is goals and not go goal let me create that procedure again okay it says the procedure topor player already exists let’s just edit the procedure name instead of top player we’ll write it as top players and similarly we’ll edit here as well now let’s create it again okay now to call my procedure I’ll write call space followed by the procedure name which is topor players if I run this you can see we have two players in our table who have scored more than six goals so we consider them as the top players in a particular tournament all right now there are other methods that you can use while creating a stored procedure one of the methods is by using an in parameter so when you define an in parameter inside a stored procedure the calling program has to pass an argument to the stored procedure so I’ll give a comment stored procedure using in parameter all right so for this example I’ll create a procedure that will fetch or display the top records of employees based on their salaries so if we have a table in our SQL IQ database which is called employee details I’m going to use this table you can see we have the name of the employee the age sex then we have the date of join City and salary using this table I’ll create a procedure that will fetch or display the top records of employees based on their salaries and we’ll use the in parameter so let me show you how to do it I’ll write delimiter this time I’m going to use forward slash I’ll write create procedure followed by the procedure name let’s say SP for stor procedure sort by salary is the name of my procedure and inside this procedure I’ll give my parameter in I’ll create a variable V and assign a data type integer then I’ll write begin followed by my select statement where I’ll select the name age salary from my table name that is EMP details or employee details I’m going to order this by salary descending and I want to display limited number of Records so I’m using this limit keyword and my variable V which I created here here I end my select statement I end my stored procedure with forward slash and I’ll go back to my default delimiter that is semicolon all right so let me run this there should be a space here all right so let’s run this okay you can see we have successfully created our second stored procedure which is Spore sort by salary now you can also check whether the stored procedure was created or not here you have an option to see the stored procedures let me just refresh this and you can see we have three stored procedures that we have created so far one is Spore sort by salary the other two were topor play and topor players okay now let’s call our stor procedure I’ll write call space followed by the stored procedure name which is Spore sort by salary and inside this I’ll give my parameter which was actually V and this V we have used in limit let’s say I want to display only the top three records of the employees who have the top three highest salaries okay so let me run it there you go so ammy Sara and Jimmy were the top three employees who have the highest salary so you saw how you could use the in parameter in a stored procedure we created a variable and that variable we used in our select statement and we called our stored procedure and passed in that variable okay now instead of a select statement inside a stored procedure you can also use other statements let’s say update so I’ll create a stored procedure to update the salary of a particular employee so in this procedure instead of Select statement we’ll use the update command in this example we’ll use the in operator twice let me show you how to do it I’ll write my D limiter first which is going to be for slash then I’ll write create procedure my name of the procedure is going to be update salary and inside the update salary name I’ll write in and then temp underscore name which will be a temporary name variable and the type I’ll assign is varar 20 I’ll again use my in parameter I’ll write in next my other variable would be newcore salary and the data type would be float I’ll write begin and write my update command or update statement I write update table name that is employee details set salary equal to newcore salary where name is equal to my temporary variable that is tempore name so this is my update command and I’ll and the delimiter all right so let’s run this okay we have successfully created our stored procedure if I refresh this you can see I have my store procedure update _ salary okay now let’s say first of all I’ll display my record that are present inside employee _ details table okay so we have six rows of information let’s say you want to update the salary of employee Jimmy or let’s say Mary from 70,000 to let’s say 72,000 or let’s say 80,000 so I’ll call my store procedure that is update uncore for salary and this time I’m going to pass in two parameters the first parameter will be the employee name and next with a comma I’ll give my new salary that I want to so my employee name let’s say is Mary and the salary I want to be updated is let’s say $880,000 I’ll give a semicolon and I’ll run it you can see it says one row affected now let’s check our table once again there you go if you see this record for Mary we have successfully updated the salary to $80,000 now moving ahead we learn to create a stored procedure using the out parameter so I’ll give a comment stor procedure using out parameter Okay so so suppose we want to get the count of total female employees we will create total employees as an output parameter and the data type would be an integer the count of the female employees is assigned to the output variable which is total uncore emps using the into keyboard let me show you how to write a stored procedure using the out parameter so first I’ll declare my delimer to forward slash I’ll write create procedure followed by the procedure name it is going to be Spore count employees and inside this I’m going to give my out parameter and the variable name that is total uncore emps which is total employees and the data type will be integer next I’m going to write begin followed by my select statement that is Select I want the count of total employees and the output I’m going to put into my new variable that is total _ emps from my table that is empore details where sex is equal to F which means female I’ll give a semicolon next I’ll end it with the D limiter and I’m going to change the D limiter to a default D limiter that is colon so let me tell you what I’m doing here I’m creating a new stor procedure that is Spore count employees using this stored procedure I’m going to count the total number of female employees that are present in our table empore details so I’ve used my out parameter and I’m creating a new variable called total uncore emps the data type is integer here in the select statement I’m counting the names of the employees and the result I’m storing it in total _ emps I have used my wear condition where the gender of the sex is female so let’s run this okay so we have created our stored procedure let’s refresh this okay you can see we have our new stored procedure Spore count employees now to call it I’ll write call the name of the procedure that is countor Spore count employees within brackets I’ll pass in the param meter as at the rate fcor EMP I’ll give a semicolon then I’ll write select at the rate fcor EMP as female employees okay so as is an alias name let’s run this one by one first I’ll call my procedure and then we’ll display the total number of female employees you can see in our table we have three female employees all right now with this understanding let’s move on to our next Topic in this tutorial on Advanced SQL now we are going to learn about triggers in SQL so I’ll give a comment here triggers in SQL so first let’s understand what is a trigger so a trigger is a special type of stored procedure that runs automatically when an event occurs in the database server there are mainly three types of triggers in SQL we have the data manipulation trigger we have the data definition trigger and log triggers in this example we’ll learn how to use a before insert trigger so we will create a simple students table that will have the students role number the age the name and the students marks so before inserting the records to our table we’ll check if the marks are less than zero so in case the marks are less than Z our trigger will automatically set the marks to a random value let’s say 50 so let’s go ahead and create our table that is students all right so I’ll write create table student now this table will have the student role number the data type is integer we will have the age of the students again the data type is integer we have the names of the students so the third column would be name the data type would be variable or varying character size I’m giving it as 30 finally we have the marks as floating type so let’s create this table which is student so we have created our table now I’ll write my trigger command so trigger command will start with D limiter like how our usual stored procedures have next this time I’ll write create trigger then you you need to give the name of the trigger that is Mark underscore let’s say verify I’m going to use a before insert trigger so I’ll write before insert on my table name that is student next I’ll write for each row if new do marks is less than zero then we set new do marks equal to 50 so this is my condition first we’ll check before inserting if any student has marks less than zero will assign a value 50 to that student because usually the marks are not less than zero in any exam I’ll write end if semicolon and I’ll close the delimiter so this is my trigger command I’ll run it it says trigger already exists in this case we need to update the trigger name let’s say I’ll write marks _ verify uncore student for STD let’s run it again okay there is an error here because in our table the column name is Mark and not marks so here we need to change it as Mark instead of marks all right let’s run it okay so we have created our trigger now let me insert a few records to the student table so I’ll write insert into student I’ll write values it give the values as 501 which is the student role number the age is let’s say 10 the name is let say Ruth and the marks is let’s say 75.0 give a comma we’ll insert our second student record student role number is 502 age is 12 the name is let’s say mic and this time I’m purposely giving a value of minus 20.5 give another comma we’ll insert the third record for student role number 503 age is 13 the name is Dave and let’s say the marks obtained by Dave is 90 now we’ll insert our final record for student number 504 the age is 10 name I’ll enter as Jacobs and this time again I’m purposely giving the marks in negative 12 point let’s say 5 close the bracket and give a semicolon and I’ll run my insert statement okay so we have inserted four rows of information to our student table now let me run the select query I’ll write select star from student if I run this you see the difference there you go so originally we had inserted for 502 the marks was minus 20.5 and for 504 for Jacobs the marks was – 12.5 our trigger automatically converted the negative marks to 50 because when we created our trigger we had set our marks to 50 in case the marks were less than zero so this is how a trigger works now you can also drop a trigger or delete a trigger you can just write drop trigger followed by the trigger name in this case our trigger name is marks _ verore St I’ll just paste this here and if you run this it will automatically delete your trigger I give this as a comment okay now moving on now we are going to learn about another crucial concept in SQL which is very widely used this is known as views so views are actually virtual tables that do not store any data of their own but display data stood in other tables views are created by joining one or more tables I’ll give a comment as views in SQL okay now to learn views I’m going to use my table which is present inside classic models data datase now this database as I mentioned we had downloaded we had downloaded it from the internet so first of all let me write use classic models so I’ll switch my database first all right now we are inside classic models so here let me show you one of the tables which is called customers so I’ll write select star from customers okay I missed s here let’s run it again so this is my customer table which is present inside classic models database it has the contact last name the contact first name the customer name customer number we have the address State country another information now I’ll write a basic view command using this customer table the way to write is I’ll write create view followed by The View VI name which is cust _ details then you write as select I’m going to select a few column names from my original customer table which is this one so I need the customer name let’s say I need the phone number and the city so you have this information here you have the phone number and the city all right I’ll write from my table that is customers if I run this my view that is cust details will be created let’s run it there’s some error here because the name of the table is customers and not customer I’ll give an S and I’ll run it again all right so you can see we have created our view and to display the contents that are present inside our view I can write select star from followed by The View name that is custor details let’s run it there you go so we have the customer name the phone number and the City of the different customers that we have in our table all right now let’s learn how you can create views using joins so we’ll join two different tables and create a view so for that I’m going to use my products table and the products lines table I’m talking about the products table and the product lines table present inside classic models database so before I start let me display the records that are present inside the products table let’s run it so these are the different products you can see here now let’s see what we have in product lines table so we have the product line the text description and there’s some HTML description and image so I’ll create a view by joining these two tables and we’ll fetch specific records that are present in both the tables so let me first start by writing create view followed by The View name that is product underscore description as I’ll write select product name comma then I’ll write quantity in stock I also want the MSRP now these three columns are present inside the products table and next from the product l table I want the text description of the products so I’ll write from products table I’ll give an alas as P followed by Inner join my other table that is product lines as let’s say PL on the common column that is product line so P dot product line is equal to I’ll give a space PL do product line okay so here we have used an inner joint to fetch specific columns from both the tables and our view name is productor description let us run it all right so we have our view ready now let me view or display what is present inside our productor description view I like select star from productor description let’s run it there you go so we have the product name the quantity in stock MSRP and textual descriptions of the different products in the table okay now there are are a few other operations that you can perform let’s say you want to rename a view instead of productor description you want to give some other name so I’ll just give a comment rename description so to rename a description you can use the rename statement I’ll write rename table product underscore description Which is my old name I want to change this name to let’s say I’ll give vehicle description since all our products are related to some of the other vehicle so I’ll write vehicle description okay let us run it all right so here you can see I have renamed my view so here if I just refresh it and I’ll expand this you can see we have the Cur details view and we have the vehicle _ description view okay now either you can view all the views from this panel or you can use a command let’s say I’ll write display views is the comment now to show all the views you can use show full tables where table underscore type is equal to within single code I’ll write view so this is the command that will display all the views that are present inside a database there is some error here let’s debug the error this should be okay so instead of table types it should be table type equal to view let’s run it you can see the two different views that we have one is customer details another is vehicle _ description okay now you can also go ahead and delete a view for that you can use the drop command so I’ll write drop view followed by The View name let’s say I want to delete customer _ details or custor details view I’ll write drop View ccore details let’s run it you can see here we don’t have the custor details view anymore all right now moving to our final section in this demo here we will learn about Windows functions Windows functions were Incorporated in my SQL in the 8 .0 version so Windows function in my SQL are useful applications in solving analytical problems so using the employees table present inside my SQL intro database so we’ll find the total combined salary of the employees for each department so first let me switch my database to SQL undor intro database I’ll run it okay and display my table that is employee so here we have 20 employees in our table using this table we are going to find the combined salary of the employees for each department so we will partition our table by department and print the total salary and this we are going to do using some windows functions in MySQL so I’ll write select I want the employee name the age of the employee and the department of the employee comma next I’ll write the sum of salary over I want to partition it by department so I’ll write Partition by Department which is D and I’ll give an alas as total salary so that it will create a new column with the name total salary from my table that is employees the output will be a little different this time let’s execute it and see the result there you go so here we have created another column in our result that is total salary and for each of the employees and the respective departments we have the highest salary so in finance the highest salary of one of the employees was $155,000 similarly if I come down we have the highest salary from HR if I scroll further we have the highest salary from it marketing product sales and the tech Team all right now we’ll explore a function which is called row number now the row number function gives a sequential integer to every row within its partition so let me show you how to use the ru number function I’ll write select rore number function over my column would be salary so I’ll write order by salary I’ll give the alas as ronom give a comma and I want to display the employee name and the salary of the employee from my table that is employees and I’ll order by salary so let’s see how our row number function will create sequencial integers okay you can see here we have a row number column and we have successfully given row numbers to each of the records you can see it starts from one and goes up till 20 okay now this row number function can be used to find duplicate values in a table to show that first I’ll create a table I’ll write create table let’s say I’ll give a random name that is demo and let’s say we have in this table the student ID which is of type integer and we have the student name which is of type varar the size is 20 I’ll create the small table with a few records let’s create this table first now we are going to insert a few records to our demo table so I’ll write insert into demo values I’ll give one1 the name is Shane give a comma I’ll insert the second student name one2 the name is Bradley we give a comma this time for 103 we have two records let’s say the name of the student is her give a comma I’ll copy this and we’ll paste it again so we have duplicated 103 next we have 104 for the name of the student let’s say is Nathan then again let’s say for the fifth student which is Kevin we have two records I’ll copy this and I’ll paste it here let me give a semicolon and we’ll insert these records to our table demo all right now let me just run this table for you I’ll write select star from demo if you see this we have a few information that are duplicated in our table that is for student ID 103 and student ID 105 now I’m going to use my row number function to find the duplicate records present in my table I’ll write select student uncore ID comma student uncore name I’ll give another comma and write rore number over within brackets I’ll write Partition by store ID comma store name okay then I’ll write order by store ID close the bracket I’ll give an alas as rum from my table that is demo let’s just run it you can see here okay let me just delete n from here and do it again all right if you see here there is just one student in the name Shane we have one student in the name Bradley but here if you see for her the second record it says two which means there are two records for H and if I scroll down there is one record for Nathan and there are two records for Kevin which means Kevin is also repeated okay now we are going to see another Windows function that is called rank function in my SQL so the rank function assigns a rank to a particular column now there are gaps in the sequence of ranked values when two or more rows have the same rank so first of all let me create a table and the name of the table would be a random name we’ll give it as let’s say demo one and it will have only one column let’s say variable a of type integer we’ll create this table first okay now let’s go ahead and insert a few records to our table which is demo one so I’ll write value 101 102 let’s say 103 is repeated I’m doing this purposely so that in the output you can clearly distinguish what the rank function does next we have 104 105 we have 106 and let’s say 106 is also repeated finally we have 107 okay let me insert these values to my table that is demo one okay this is done now if I write select Vore a and use my rank function I’ll write rank over then I’ll order by my variable that is Vore a as an alas name let’s a test rank from my table that is demo one let me execute this and show you how the rank function works if I run this there you go so here if you mark So for variable a101 the test rank is 1 for 102 the test rank is two but for this value which is 103 the test rank is repeated because there was a repetition for 103 so we have skipped the rank four here for 104 the rank is 5 now for 105 the rank is 6 now for 106 again since the record was repeated twice we have skipped the eighth Rank and our rank function assigned the same value which is 7 for 106 and for the last value 107 the rank is 9 all right now moving ahead we’ll see our final Windows function which is called first value so first value is another important function in my SQL so this function Returns the value of the specified expression with respect to the first row in the window frame all right so what I’m going to do is I’m going to select the employee name the age and salary and I’ll write first underscore value which is my function and pass in my employe name and then I’ll write over order by my column that is salary descending I’ll give an alas as highest uncore salary from my table that is employees so let me run this and see how the first underscore value function works all right so in our table Joseph was the employee who had the highest salary which was $115,000 so the first value function populated the same employee name throughout the table you can see it here now you can also use the first uncore value function over the partition so let’s say you want to display the employee name who has the highest salary in each department so for that you can use the partition I’ll write select _ name comma I want the department and the salary comma I’ll use my function that is first underscore value follow by the name of the employee inside my first value parameter I’ll write over here I’m going to use partition I’m going to partition it by department since I want to know the employee name who has the highest salary in each department and I’m going to order by salary descending and I’ll give my alas again as highest salary from my table that is employees so let’s run this and see the difference in the output okay so as you can see here we have the employee who had the highest salary from each department so for finance Jack had the highest salary from HR it was Marcus similarly in it it was William if I scroll down for marketing it was John for product it was Alice who had the highest salary similarly in sales we had Joseph and in Tech we had Angela so this is how you can use the first uncore value function using partition all right so that brings us to the end of this demo session on our tutorial so let me just scroll through and show you what we did from the beginning first we learned about subqueries in SQL so we initially wrote a simple subquery and then we used our classic models database which was downloaded from the internet I’d also shown you the link from where you can download this database here we used two different tables and we performed a subquery operation we learned how to create stored procedures so we learned how you can use the in operator or the in parameter as well as the out parameter in store procedure after stored procedure we learned another crucial Concept in SQL which is called triggers now triggers are also special kind of store procedures so we saw how to write a before insert trigger you can see it here next we learned how to delete a trigger we also saw how to work with views in SQL so views are basically virtual tables that you can create from existing tables we also saw how you can use views using two different tables and an inner join and we learned how to display views how to rename view names how to delete a view and finally we explored a few Windows function in this tutorial we will learn how to work with databases and tables using SQL with python to do this demo we will be using our jupyter notebook and the MySQL workbench you can see it here so we will write our SQL queries in the jupyter notebook with python like syntax if you don’t have MySQL or jupyter notebook install so please go ahead and install them first while installing the MySQL workbench you’ll be asked to give the username and password let me show you so I am on my MySQL workbench so once you connect it will ask for the username and the password so I’ve given my username as root and password you can give while installing it we will be using the same user ID or the username and the password to make our connection so let’s get started with our Hands-On demonstration part first and foremost let me go ahead and import the necessary libraries I’ll give a comment as import libraries all right so first I’ll import MySQL do connector next from MySQL doc connector I’m going to import my error method or the error module next I want to import pandas as PD so let’s run this okay there is some error here this should be capital E and not small all right you can see I have imported my important libraries now I’m going to create a function that will help us create a server connection so I’ll write my userdefined function by using the DF keyword I’ll write create underscore Server uncore Connection this is going to be my function name and it will take in three parameters first is the host name next is the username and then we have the user password all right I’ll give a colon and then in the next line I’m going to Define a variable which is going to be connection and I’ll assign it to a value called none now we’ll be using exception handling techniques to connect to our MySQL server the tri block lets you test a block of code for errors and the accept block will handle the errors so I’ll write try and give a colon and then I’m going to reassign the connection variable to a method which is MySQL do connector do connect now this MySQL connector. connect method sets up a connection so it establishes a session with the MySQL server if no arguments are passed it uses the already configured or default values so here we are going to pass in three parameters the first is the host name I’ll write host equal to host name which is hostor name name I’ll give a comma then I’ll write user equal to user uncore name next will be my password and I’ll assign the value user _ password all right now I’m going to use a print statement and write mySQL database connection successful after this I’ll give my accept blog so I’ll use the keyword accept here I’ll write error as err give a colon and then I’m going to use the print statement here I’m going to use some print formatting techniques using the F letter I’ll write error colon and I’ll use curly braces give VR and then I’ll close the double codes after this I’m going to return my connection all right let me give a comment here we are going to assign our password so we need to put our MySQL terminal password so this password you assign it while installing MySQL workbench I’ll write PW and I’ll give my password which is simply at the rate 1 2 3 4 5 and then I’m going to give my database name so I’ll give database name here I’m going to write DB equal to this is the database I want to create which is going to be MySQL python let me just scroll this down okay now I’ll say connection equal to I’ll pass in my user defined function name which is create server connection and the parameters which are going to be Local Host that is my host name my username which is root and then I’ll give PW which is my password that is exact L simply at the rate 1 2 3 4 5 let’s just run it now okay there is an error here we need to remove this double quotation all right made another mistake here this this should be root okay you can see here my SQL database connection successful all right next we are now going to create a database that is MySQL _ python so I’ll give a comment create MySQL uncore python database again to create this database I’m going to create another user defined function using the DF keyword I’ll write the function name as create database passing the parameters as connection comma query give a semicolon and in the next line I’ll write cursor equal to I’m going to make the connection so I’ll write connection dot cursor and I’ll give the parenthesis so this mysql’s cursor of MySQL connector python is used to execute statements to communicate with the mySQL database the MySQL cursor class initiates objects that can execute operations such as the MySQL statements okay next I’m going to again use my try and accept block so I’ll write try give a coolon and here I’m going to use cursor do execute within that I’m going to pass in my query next I’ll use a print statement and the message I’m going to display is database created successfully after this I’m going to write my except block I’ll write accept error as err give a colon and then I’ll use a print statement I’ll write print I’ll use the formatting again error colon and I’ll write within single codes I’ll give curly braces err and then I’ll close the double codes next let’s use the variable create underscore database underscore query and here I’m going to write my SQL query to create the database so I’ll write create database and followed by that I’ll give my database name which is going to be MySQL python okay after this I’ll call my function which is create database and I’ll pass in the parameters the first one is connection and next the query qu is create _ database _ query let me just copy it and I’m going to paste it here all right so what I’m doing here is I am creating a new function that is to create a new database with the name MySQL undor python which you can see it here now this function takes in two parameters connection and query I’m using the connection. cursor function which is often used to execute SQL statements using Python language and then I have created my try and exer blocks so this Tri block statements will try to create my new database which is MySQL python in case it fails to create the new database the exer block will work so here I’m writing my SQL query to create a new database which is create database followed by the database name and I’m assigning it to a variable which is create data datase query and then I’m calling my function create database and passing in the two parameters connection and the query all right so let’s just run it all right you can see here it has created my database successfully now you can verify this by checking the MySQL workbench or the MySQL shell you can see on the MySQL workbench here on the left panel under schemas there is a database called MySQL python let me just expand it now we haven’t created any table so it’s not showing it now the next step we are going to connect to this database so let’s go ahead and connect to our database that we have just created I’ll write the comment as connect to database now to connect to a database I’m again going to create a userdefined function using the DF keyword I’ll write create underscore DB which is for database _ connection and the parameters it will take is the host name followed by the username then we have the user password and finally we have the database name I’ll give a colon in the next line I’m going to create my variable which is connect connection and then I’ll assign it to a value none after this I’m going to use my exception handling techniques so I’ll write my tri block first I’m going to reassign my connection variable using the MySQL connector method so I’ll write MySQL do connector do connect so this this method we’ll take in the parameters so first it will take the host name I’ll write host equal to hostor name I’ll give a comma next it will take the usern name so user equal to user name another comma next it will take the user password I’ll use pass WD equal to user uncore password we give another comma and this time is going to be the database name so I’ll write database equal to dbor name now let’s use the print statement and and the message we are going to print is mySQL database connection successful all right finally we’ll write my accept block I’ll write accept error as err give a colon and then I’ll use the print statement f F within double Cotes I’ll write error colon within single Cotes curly braces I’ll write err and we’ll close the double quotes finally this function will return the connection value all right let’s run it and there you go it has run successfully so we have connected to our database now it’s time for us to execute SQL queries I’ll give another comment saying execute SQL queries all right now to execute our SQL queries I’ll use another user defined function which is execute underscore query and I’ll pass in the parameters as connection and query give a colon I’m going to write cursor equal to connection do cursor now this is used to establish a connection and run SQL statements next we’ll use the try and accept block so I’ll write try cursor dot execute this will take in one parameter which is going to be my query and then I’ll write connection do commit which is another method now let’s use the print statement so I’ll write print let’s say the message would be query was successful and then we’ll write our accept block which is accept if the tri block doesn’t work through an error using the print statement within double codes inside the inside the curly braces I’ll write err and close the double codes all right so let’s run it okay so we have successfully created our various functions that we needed to create a database establish a connection and to execute our queries all right now it’s time for us to create our first table inside the MySQL _ python database so to do that I’m going to write my create command in SQL so first we are going to assign our SQL command to a python variable using triple codes to create a multi-line string so let me show you how to do that I’ll write my variable name which is going to be create orders table it is always recommended to use relevant variable names to make it more readable and now I’m going to use triple codes so the triple quote will ensure I can create my multi-line string inside the triple quote I’m going to write my create command which is create table here I’m going to create an orders table first and inside the orders table I’m going to create my column names the First Column would be the order ID it is going to be of type integer and I’ll assign this order ID as my primary key column we’ll give a comma next the second column would be customer underscore name the customer name column would be of type varing character so I’ll write varar and I’ll give a size of 30 and this is also going to be not null moving ahead my fourth column would be the product name column so I’ll write productor name product name will be of type varing character the size is let’s say 20 and it is also not null next I’m going to create my fourth column which is the date on which the item was ordered or the product was ordered so I’ll write date ordered the data type will be date next I’ll create a quantity column to keep track of the number of quantities that were ordered this is of type integer my next column would be unit price which will basically have information about the price of each unit of product unit price can be of type float and finally I’ll have the phone number of the customer I’ll write phone number phone number can be kept as of type varing character I’ve have assigned a size of 20 now let’s give a semicolon and we’ll close the the triple codes all right so this is how the syntax would look like next to run this we are first going to call our create DB function so let me give a comment as connect to the database I’ll write connection equal to create _ dbor connection my parameters would be my host name which is Local Host my username which is root comma my password and then my database name which is MySQL python so I’ll write just DB all right finally let’s execute this query using the execute underscore query function that we had created earlier this takes in two parameter the first one is connection followed by the variable name which is create orders uncore table let us run it okay there is some error here let’s see what’s the error okay so here we have put four double code this should be triple codes now let’s run it okay there is another here let’s debug it it says name cursor not defined let me just roll it to the above cell if you see here in our execute underscore query function instead of cursor I have written cursor so R is missing let’s redun this and now let’s run this again there you go you can see here my SQL database connection successful even our query was also successful now if you want to recheck if the table that is orders was created or not you can check it on the MySQL workbench so let me show you how to do it so I am on my MySQL workbench and under MySQL python database you have something called as tables let me just right click and I’ll select refresh all there you go you can see this Arrow just click on this arrow and here you can see we have a table called orders so we have created our table called orders now you can check the columns as well you have the order ID you have the order ID the customer name product name ordered date quantity unit price and phone number now it’s time for us to insert a few records to this table which is orders now to insert records I’ll give a comment as insert data I’ll start with the variable name let’s say the variable name is data underscore orders I’ll give triple Cotes next I’ll write my insert into command so I’ll write insert into my table name that is orders for followed by values and now I’ll start entering my records for each of the rows so first I’ll give one1 which is the order ID then I’ll give the customers’s name let’s say Steve and the product he had ordered is let’s say laptop then I’ll give my date in which the item was ordered let’s say it is 2018 I’ll choose 06 as the month and the date is let’s say 12 we give another comma this time we’ll pass in the quantity which is two let’s say the price of each laptop was $800 and we’ll give a phone number this is random let’s say 62 9 3 7 3 0 Let’s see 802 all right similarly I’m going to insert five more records of different customers and their items that they have purchased to this table orders so here on my notepad I have my rest of the five records let me just copy it and we’ll paste it in the cell here this will save us some time okay let me recheck if everything is fine I’ll give a comma here all right so we have six customers in our table which have their customer IDs from 101 to 106 you have Steve jaw Stacy Nancy Maria and Danny you have the different items they have purchased laptop books trousers t-shirts headphones and smart TV is the date on which they had ordered this item the number of quantities they had ordered and then we have the unit price and some random phone numbers so let’s create the connection now I’ll write connection equal to I’ll write create undor dbor connection then I’ll going to give my same parameters let me just copy it from the top is Local Host the host name root is my username then we have password and the database name and then I’ll use the same query as above which is execute query I’ll copy this paste it here and instead of of create orders table variable I’ll put as data _ orders so this will store my insert into command you can see the variable I’ve used here is dataor orders now it’s time let’s just run it all right there was some mistake here let’s debug it again this should be triple quotes and not four now let me rerun it again there you go you can see here my SQL database connection successful and my query was also successful now we’ll create another user defined function which will help us read query and display the results so I’ll write my function name as DF read uncore query this will take in two parameters connection and query then I’ll write cursor equal to connection do cursor I’ll put my result as none and then I’ll use my try and except block I’ll write try cursor dot execute this will take in one parameter which is query and then I’ll give another variable which is result equal to cursor dot fetch all now this fetchall method will return all the results in the table I’ll write return result next we’ll use the accept block so I’ll write accept error as ER give a colon and I’ll use my print statement just scroll this down I’ll use my formatting F error give a colon followed by a space within single Cotes inside curly pess I’ll give ER and close my double Cotes let’s run it all right so now we are all set now we are going to use our select Clause having whereby then we’ll see how to use Auto by Clause some inbuilt functions we’ll update some records delete some records and do a lot of other stuff so let’s start with our first query so our first query is going to be using the select statement all right so suppose I want to display all the records that we have inserted into our ords table so the way to do is I’ll assign my query to a variable let’s say q1 I’ll give triple quotes within triple quotes I’ll write select star from orders we give a semicolon followed by the triple codes now we’ll establish the connection so let me just go to the top and I’ll copy this line which is to connect to our database I’ll paste it here now we’ll create a variable called results that will store the result of this query and we are going to assign this variable to our function that is read query and this read query will have two parameters the connection and the variable name which is q1 for the query next to display I’m going to use a for Loop I’ll write for results for result in results print I’ll say result now we are done let’s just run this query there you go you can see here we have successfully printed all the rows in our table which is orders you can see we have six records in total now we are going to explore a few more queries so let me just copy this and we are going to edit in the same query I’ll paste it here next let’s say you want to display individual columns from the table and not all the columns so let me let me create the variable Q2 now instead of star I’m going to display only the customer name and let’s see the phone numbers of the customer so I’ll write phone uncore number all right the rest all Remains the Same let me just recheck it and here instead of q1 we’ll put Q2 and let’s run this cell all right you can see here now we have displayed only two columns the First Column is the customer name and then we have the respective phone numbers okay now let me just paste that query again now we are going to see how you can use an inbuilt function that is in our table we have the order date and from the order date we are only going to display the different ear that are present in the order date so to do that I’m going to use the year function I’ll edit this query instead of q1 I’ll make it Q3 and here I’m going to write select here which is my function name from my column which is date ordered from orders and here I’ll change this to Q3 q1 Q2 Q3 are basically query 1 query 2 and query 3 let’s run it there you go so we have successfully extracted the different years present in the order date column now if you want to display the distinct or the unique dates present in the column you can use the dextin keyword in the select statement so the way to do it is I’ll write select distinct give a space the rest of the query Remains the Same and here Q3 I’ll write Q4 I’ll make this as Q4 let’s run it you can see 2018 and 2019 are the unique year values that are present in the order date column okay now moving ahead let’s write our fifth query and this time we are going to explore how you can use the wear Clause so I’ll change this to Q5 before I write my query so let’s say you want to display all the orders that were ordered before 31st of December 2018 so to filter this we are going to use the wear Clause so I’ll write write select star from orders next I’ll write where my date underscore ordered is less than within course I’ll give my date value which is 2018 December 31st so all the items or the products that were ordered before 31st of December 20 18 will be displayed so let’s run it all right you can see here there are three orders in our table which have been ordered before 31st of December now moving ahead we want to display all the orders that were made after 31st of December so here what you can do is I’ll just copy the above query again I’ll copy this line so instead of less than 31st of December 2018 I’ll make it as greater than so every order that was placed after 31st of December will be displayed if you run it so you can see here there are three orders in our table which were ordered after 31st of December 2018 now moving ahead let’s write a seventh query now let’s see how the autoby Clause Works in SQL so you can filter your results based on a particular column or sort it based on a particular column so this is going to be my query 7 I’ll write it from scratch again let’s say you want to display all the columns from the table so I’ll write select star from orders then I’m going to use order by unit price I’ll give a semicolon let’s run this query and see the output now if you see the result here and you mark the unit price column the result has been ordered in ascending order of unit price you see here it starts with the lowest price and then goes on with the highest price towards the end if you want to order it in descending order you can use the keyword Dees C so this will ensure your top or the most expensive products appear at the top and the least expensive products appear at the bottom all right next now let’s see how you can create a data frame from the given table so as you know using jupyter notebook and pandas you can create data frames and work on it very easily so with this table also we can create our own data frame so for that let me create an empty list first I’ll write from DB equal to I’ll assign this as an empty list so we are going to return a list of lists and then create a pandas data frame next I’ll write my for Loop I’ll write for result in results I’ll assign result to list of results so I’m converting the result into a list and then I’m going to append it to the empty variable or the empty list which is from DB do append I’ll append the result to my empty list next we need to pass in the column now that will be part of our data frame so I’ll write columns equal to this column I’ll pass it within a list so I’ll give my first column as order ID then we have the customer name next I have my product name then I have the date on which it was ordered give a comma then we’ll have the quantity column let me write it in the next line next we have the unit price column and finally we have the phone number column so I’ll write within double quotes phone number and this we are going to assign it to a data frame so I’ll be using PD do data frame which is my function to convert a list into a data frame my variable I’m going to pass this from _ DB and I’ll write my next argument is columns equal to my variable name that is columns finally let’s display the data frame which is DF all right so here I’m creating a empty list first and then I am creating a for Loop and I’m appending the results to my empty list here you can see I have created my column list and using pd. data frame I’m converting the list into a data frame if I run this this is append and not append all right you can see we have our data frame ready this is the index column it starts from zero onwards and then we have the different column names okay now let’s see how to use the update command now suppose you want to change the unit price of one of the orders you can use the update command so the way to do it I’ll first create my variable let’s say update and I’ll give three codes or triple codes then I’ll use my update command which is update followed by the table name that is orders next I’ll write set let’s say unitor price if you see this let’s say I want to set the unit price of trousers from $50 to let’s say $45 I want to update this particular record so I’m going to write set unit price column equal to $45 where the order ID equal to 103 so this query will update the third row in our table which is order ID 103 so it will update from $50 to $45 I’ll close the triple quotes and now I’ll use the connection queries again let me just paste it here all right I’ll delete these three lines of code and instead of that I’ll put execute underscore query and this will take into parameters as always which is going to be connection followed by the variable name that is update let’s run it you see here it says mySQL database connection successful query was successful now you can recheck that to do it let me just go to the top and we’ll just copy our first query which is q1 I’ll copy this and I’ll paste it here let me just rename this now this will be Q8 and I’ll change this as well I’ll write select star from orders where my order ID equal to 103 let’s see the unit price of 103 now you can see here instead of 50 now we have updated it to $45 all right now the last command we are going to say is how you can delete a record from the table I’ll write delete command as my comment now to delete a query I’ll first give my variable name which is delete uncore order and I’ll pass in within triple quotes next I’ll write my delete query which is delete from my table name that is orders then I’ll give my we Clause where let’s say I want to delete my order ID 105 let me just go to the top and explain you again so if you see this we want to delete the order ID 105 which was for customer name Maria and she had ordered headphones we want to completely remove this particular record so I have my delete query ready now let me just create my connection and display the results so I’ll go to the top and I’ll copy this connection command which also has the execute query command and I’ll paste it here and I’m going to make a change here instead of update we’ll write delete underscore order everything looks good let’s just run it you can see our query was successful and now if you want to print it let me just show you I’ll just copy this we’ll paste it here I’ll make this as q9 I want to verify if my order ID 105 was deleted or not instead of this statement I’ll write select star from orders and here I’ll change this to q9 if I run this you can see it here you can Mark order ID 105 was deleted and it no more appears in this table all right so this brings us to the end of the demo session on SQL with python let me just scroll you through what we did so first we imported the important libraries MySQL connector then we imported the error function then we imported pandas using PD we learned how to create a server connection to mySQL database we created a new database that is MySQL Python and now we connected to that database we created a function to execute our queries we saw how you can write a create table command then we inserted a few records to our orders table we created a read uncore query command to read the queries and display the results then we started exploring our different SQL commands one by one we saw how to use select query then we selected a few individual columns from our table followed by using a inbuilt function which was ear then we saw how to use the distinct keyword after that we used our wear Clause to filter our table based on specific conditions we saw how to order your results based on a particular column then we saw how you could convert the table into a data frame using pd. dataframe function finally we learned how to use the update command and the delete command postl is a very popular and widely used database in the industries in this tutorial we will learn post SQL or post chis SQL in detail with an extensive demo session so in today’s video we will learn what post chis SQL is and look at the history of postris SQL we will learn the features of postris SQL and jump into performing postris SQL commands on the SQL cell and PG admin so let’s begin by understanding what is post SQL postc SQL is an open-source object relational database management system it stores data in rows with columns has different data attributes according to the DB engines ranking postris SQL is currently ranked fourth in popularity amongst hundreds of databases worldwide it allows you to store process and retrieve data safely it was developed by a worldwide team of volunteers now let’s look at the history of postr sequel so in 1977 onwards the Ingress project was developed at the University of California Berkeley in 1986 the post Chris project was led by Professor Michael Stonebreaker in 1987 the first demo version was released and in 1994 a SQL interpreter was added to postris the first postris SQL release was known as version 6.0 or 6.0 on January 29 1997 and since then postr SQL has continued to be developed by the post SQL Global Development Group a diverse group of companies and many thousands of individual contributors now let’s look at some of the important features of postest SQL so postest SQL is the world’s most advanced open source database and is free to download it is compatible as it supports multiple operating systems such as Windows Linux and Macos it is highly secure robust and reliable postp SQL supports multiple programming interfaces such as C C++ Java and python postp SQL is compatible with various data types it can work with Primitives like integers numeric string and Boolean it supports structured data types such as dat and time array and range it can also work with documents such as Json and XML and finally postris SQL supports multiversion concurrency control or mvcc now with this Theory knowledge let’s look at the post SQL commands that we will be covering in the demo so we will start with the basic commands such as select update and delete we will learn how to filter data using where clause and having clause in SQL we will also look at how to group data using the group by clause and order the result using the order by Clause you will learn how to deal with null values get an idea about the like operator logical operator such as and and or we will also explore some of the popular inbuilt mathematical and string functions finally we’ll see some of the advanced concepts in postris SQL that is to write case statements subqueries and user defined functions so let’s head over to the demo now okay so let’s now start with our demo so first we’ll connect to post SQL using psql cell so here under type here to search I’ll search for psql you can see this is the SQL cell I’ll click on open let me maximize this okay so for Server I’ll just click enter database I’ll click enter port number is already taken which is 5432 I hit enter username is already given and now it is going to ask for password so here I’ll give my password so that I can connect to my post SQL database so it has given us a warning but we have successfully connected to post SQL all right so now to check if everything is fine you can just run a simple command to check the version of post SQL that we have loaded so the command is Select version with two brackets and a semicolon I’ll hit enter okay you can see the version post SQL 13.2 okay now let me show you the command that will help you display all the databases that are already there so if I hit slash L and hit enter it will give me the list of databases that are already there so we have post SQL there’s something called template 0o template 1 and we have a test database as well okay now for our demo I’ll create a new database so first I’ll write create space database and I’ll give my database name as SQL uncore demo I’ll give a semicolon and hit enter you see we have a message here that says create database so we have successfully created our SQL demo database now if you want to connect to that database you can use back/ c space SQL uncore demo there you go it says you are now connected to database SQL demo so here we can now create tables we can perform insert operation select operation update delete alter and much more now I’ll show you how to connect to post SQL using PG admin so when you install the post SQL database you will get the SQL cell and along with that you also have the PG admin so I’ll just search for PG you can see here it has prompted PG admin I’ll click on open this will open on a web browser you can see it has opened on Chrome and this is how the interface of PG admin looks like it is a very basic interface so on the top you can see the files we have object this tools and we have the help section as well and here you have dashboard properties SQL statistics dependencies dependence and here on the left panel you have servers let me just expand this so it will connect to one of the databases all right so if I go back you see when I had run back/ L to display the databases it had shown me post SQL and test now you can see here we have the post SQL database and the test database all right now we also created one more database which was SQL demo so let me show you how to work on this PG admin and the query tool all right so I’ll right click on SQL demo and I’ll select query tool I’ll just show you how to run a few commands on the query tool so let’s say you want to see the version of post SQL that you are using so you can use the same command that we did on psql Cell which is Select version closed with brackets and a semicolon I’ll select this and here you can see we have the execute button so if I hit execute or press F5 it will run that query you can see we have the output at the bottom and it says post SQL 13.2 compiled by visual C++ it has the 64-bit system okay now let me tell you how to perform a few basic operations using postr SQL commands so here let’s say I’ll write select 5 into 3 I’ll give a semicolon select this and hit F5 so this will run the query and it returns me the result that is the product of 5 and three which is 15 similarly let’s edit this let’s say I’ll write 5 + 3 + let’s say 6 I’ll select this and hit F5 to run it it gives me the sum of 5 + 3 + 6 which is 14 now the same task you can do it on this cell as well let me show you how to do it here so let’s say I’ll write select let’s say I want to multiply 7 into let’s say 10 you know the result it should be 70 if I hit enter it gives me 70 now this question mark column question World we’ll deal with this later all right let me go back to my PG admin again let me do one more operation let’s say this time I’ll write select 5 multiplied by and within brackets I’ll write 3 + 4 I’ll give a semicolon so what SQL will do is first it will evaluate the expression that is there inside the bracket that is 3 + 4 which is 7 and then it will multiply 7 with 5 now let me select this and I’ll hit execute so you can see 7 * 5 is 35 all right now we’ll go back to our shell and here I’ll show you how to create a table so we are going to create a table called movies on the cell that is psql cell so here we will learn how you can create a table and then you can enter a few data into that table all right let me just scroll down a bit okay so my create command goes something like this so I’ll write create table followed by the table name that is movies next my movies table will have a few columns let’s say I want the movie ID after the column name we need to give the data type so movie ID I’ll keep it as integer so integer is one of the data types that is provided by postr SQL next my second column the table would be the name of the movie so I’ll write moviecore name so all the variables or the column names should be as per SQL standards so there shouldn’t be any space between the column names so I have used underscore to make it more readable so my movie name will be of type varar or variable character or varing character and I’ll give the size as 40 so that it can hold 40 characters maximum next my third column will have the genre of the movie so I’ll write moviecore joner again joner is of type barar I’ll give the size as let’s say 30 and my final and the last column will have the IMDB ratings so I’ll write IMDb underscore ratings now the ratings will be of type real since it can have floating or decimal point values if I close the bracket I’ll give a semicolon and I’ll hit enter there you go so we have successfully created a table called movies now let me go back to my PG admin all right so here I have my database that is SQL demo I’ll just right click on this and click on refresh now let me go to schemas I’ll just scroll down a bit here under schemas we have something called as tables let me expand this okay so you can see we have a table called movies in the SQL demo database now and here you can check the columns that we have just added so our movies table has movie ID movie name j and readings all right now there is another way to create a table the previous time we created using the SQL cell now I’ll tell you how to create a table using the PG admin so here under tables I’ll right click and I have the option to create a table so I’ll select table okay so it’s asking me to give the name of the table so this time we are going to create a table called students so I’ll write my table name as students all right these will be default as it is now I’ll go to the columns tab so here you can create the number of columns that you want so you can see on the right I have a plus sign I’ll just select this so that I can add a new row so my first column would be let’s say the student role number I’ll write student underscore RO number again the column name should be as per SQL standards the data type I’m going to select is integer all right now if you want you can give these constraints such as not null so that student R number column will not have any null values and I’ll also check primary key which means all the values will be unique for role numbers all right now if you want to add another column you can just click on that plus sign and let’s say this time I want to give the student name as my second column so I’ll write student underscore name student name will be of type let’s say character wearing if you want to give the length you can specify the length as well let’s say 40 I’ll click on the plus sign again to add my final column the final column would be gender so gender I’ll keep this time as type character okay now you can click on save so that will successfully create your students table there you go so here on the left panel you can see earlier we had only one table that was movies and now we have two tables so one would be added that was students so if I expand this under columns you can see we have the three columns here student rule number student name and gender you can also check the constraints it will tell you if you have any constants so you can see it says students rule number there’s one primary key all right all right now let me run a select statement to show the columns that we have in the movies table so I’ll write select star from movies give a semicolon and let me execute this okay so here on the at the bottom you can see we have the movie ID the movie name movie Jor and IMDb readings now the next command we are going to learn is how to delete a table so there is one way by using the SQL command that is drop table followed by the table name let’s say you want to delete students you can write drop table students and that will delete the table from the database this is one of the methods so you just select and run it now the other way is to you just right click on the table name and here you have delete slash drop if I select this you get a prompt are you sure you want to drop table students I’ll select yes so you can see we have successfully deleted our students table all right now let’s perform a few operations and learn a few more commands in post SQL so to do that I’m going to insert a few records to my movies table so for that I’ll use my insert command so I have my insert query written on a notepad I’ll just copy this and I’ll paste it on my query editor okay so let me just scroll down all right so here you can see I have used my insert command so I have written insert into the name of the table that is movies and we have the movie ID the movie name movie Jer and IMDb readings and these are the records or the rows so we have the first record as movie ID 101 the name of the movie is a very popular movie which is vertigo then we have the movie genre that is Mystery it is also a romance movie and then we have the IMDb readings the current IMDb readings that is 8.3 similarly we have sank Redemption we have 12 Angry Men there’s the Matrix seven inter staler and The Lion King so there are total eight records that we are going to insert into our movies table so let me just select this and hit execute okay you can see it has returned successfully eight records now if I run select star from movies you can see the records that are present in the table so I’ll write select star from movies I’ll select this and I’ll execute it there you go at the bottom you

    can see eight rows affected if I scroll this down you have the eight records of information in the movies table all right now if you want to describe the table you can go to the SQL cell and here if you write back SL D and the name of the table that is movies this will describe the table so here you have the column names this has the data type and here you can specify if there are any null values or any con constraints like default constraint or primary key or foreign key and others let me go back to my PG admin okay now first and foremost let me tell you how to update records in a table so suppose you have an existing table and by mistake you have uh entered some wrong values and you want to update those records later you can use the update query for that so I’m going to update my movies table and I’ll set the genre of movie ID 103 which is 12 Angry Men from drama to drama and crime so in our current Table we only have jonre as drama for 12 angry man I’m going to update this column which is the movie genre to drama and crime okay so let me show you how to do it I’ll write update followed by the name of the table that is movies go to the next line I’ll write set then I’ll give the column name which is moviecore Jer equal to I’m going to set it as drama comma crime earlier it was only drama and I’ll give my condition using the where Clause we’ll learn where clause in a bit so I’ll write where moviecore ID is equal to 103 so here our movie ID is the unique identifier so it will first look for movie ID 103 it will locate that movie and it change the genre to drama and crime so now you can see the difference earlier we had 12 Angry Men as drama as the movie genre now if I run this update statement okay you can see we have successfully updated one record now let me run the select statement again okay so here you can see if I scroll down there you go so movie ID 103 movie name 12 Angry Men we have successfully updated the genre as drama comma crime okay now let me tell you how you can delete records from a table so for that you can use the delete command so you’ll write delete from the table name that is movies where let’s say I want to delete the movie ID 108 which is The Lion King so I’ll write where moviecore ID is equal to 108 this is one of the ways to delete this particular movie or you can give let’s say where movie name is is equal to The Lion King let me select this and I’ll hit execute now if I run my select query again you see this time it has returned seven rows and you cannot find movie with movie ID 108 that was The Lion King so we have deleted it all right next we are going to learn about wear clause in post SQL so to learn we Clause I’ll be using the same movie table again let’s say we want to filter only those records for which the IMDB ratings of the movies is greater than 8.7 so this is my updated table now I want to display only those records or those movies whose IMDB ratings is greater than 8.7 so we’ll display 12 angry man which is 9 then we are going to display the Dark Knight which is again 9 and we are also going to display the sank Redemption which has 9.3 the rest of the movies have and am Tob rating less than 8.7 so we are not going to display those all right so let me show you how to write a we Clause so I’ll write select star from movies where I’ll give my column name that is IMDB ratings is greater than I’ll use the greater than symbol then I’ll pass my value that is 8.7 I’ll give a semicolon and let’s run it I’ll hit F5 there you go so we have returned the sank Redemption The Dark Knight and 12 Angry Men because only these movies had IMDB ratings greater than 8.7 okay now let’s see say you want to return only those movies which have IMDB ratings between 8.5 and 9 so for that I’m going to use another operator called between along with the wear Clause so let me show you how to use between with wear Clause I’ll write select star from movies where my IMDB uncore ratings is between I’ll write 8.5 I’ll give an and operator and 9.0 so all the movies that are between 8.5 and 9.0 ratings will be displayed so let’s select this and I’ll run it there you go so we have returned the darkno The Matrix the seven interal and we have the 12 Angry Men so a few of the course that we missed out where I think vertigo which has 8.3 and there’s one more all right now moving ahead let’s say you want to display the movies whose movie genre is action you can see in a table we have a few movies whose genre is action movie so you can do that as well I’ll write select star from movies where the movie J I’m writing this time in one line you can break it into two lines as well I’ll write moviecore Jer which is my column name equal to I’ll give within single codes action now why single code because action is a string hence we need to put it in single codes if I run this there you go so we had one movie in our table whose movie genre action that is The Dark Knight okay now you can also select particular columns from the table by specifying the column names now here in all the examples that we saw just now we are using star now star represents it will select all the columns in the table if you want to select specific columns in the table you can use the column names so you can specify the column names in the select statement let me show you let’s say you want to display the movie name and the movie genre from the table so you can write select moviecore name comma I’ll give the next column as moviecore Jer from my table name that is movies where let’s say the IMDB uncore ratings is less than 9.0 so this time in our result it will only show two columns that is movie name and movie JRE let me run it there you go so these are the movie names and the movie Jers you can see that have an IMDB ratings less than 9.0 all right like how you sh the between operator there is one more operator that you can use with the we Clause that is the in operator so the in operator works like a r clause or an R operator so let’s say I want to select all the columns from my movies table where the IMDB ratings is in 8 .7 or 9.0 if I run this it will display only those records whose IMDB ratings is 8.7 or 9.0 all right so up to now we have looked at how you can work on basic operations in SQL like your mathematical operations you saw how a select statement works we created a few tables then we inserted a few records to our tables we saw how you can delete a table from your database and we have performed a few operations like update delete and we saw how a wear Clause works now it’s time to load a employee CSV file or a CSV data set to post SQL so I’ll tell you how you can do that but first of all before loading or inserting the records we need to create an employee table so let me first go ahead and create a new table called employees in our SQL _ demo database so I’ll write create table my name of the table would be employees next I’m going to give my column names so my first column would be employee ID so the employee ID will be of type integer it is not going to contain any null values so I’ll write not null and I’ll give my constraint as primary key so the employee ID as you know is unique for all the employees in a company so once I write primary key it will ensure that there are no repetition in the employee IDs okay next I’ll have my employee name so my employee name is going to be of type varar and I’ll give my size as 40 okay next we’ll have the email address of the employee again email address would be of type varar and the size is 40 again I’ll give another comma this time we’ll have the gender of the employee gender is again worker of size let’s say 10 okay now let’s include a few more columns we’ll have the Department column so I’ll write department worker let’s say the size is 40 then let’s say we’ll have another column that is called address so the address column will have the country names of the employees address is also our car and finally we have the the salary of the employee salary I’m going to keep it as type real so real will ensure it will have decimal or floating Point values okay so now let me select this create table statement and execute it all right so we have successfully created our table if you want you can check by using select star from employees let me select this and I’ll hit execute all right you can see we have our employee ID as primary key there’s employee name email gender this department address and salary but we don’t have any records for each of these columns now it’s time for us to insert a few records to our employees table now to do that I’m going to use a CSV file so let me show you how the CSV file looks like okay so now I am on my Microsoft Excel sheet and on the top you can see this is my employe data. CSV file here we have the employee ID the employee name email gender this department address and salary now this data was generated using a simulator so this is not validated and you can see it has a few missing values so under email column you have a few employees who don’t have an email ID then you can see on Department also there are some missing values here as well all right so we’ll be importing this this table or the records present in this CSV file onto postr SQL all right so here in the left panel under tables let me right click and first refresh this there you go so initially we had only movies table and now we also have the employees table now what we need to do is I’ll right click again and here you see we have the option to import or export let me click on this and I don’t want to export I need to import so I’ll switch on import all right now it is asking me to give the file location so let me show you how to get the file location so this is my file location actually so my Excel file which was this is present in my e Drive under the data analytics folder I have another folder called postc SQL and within the post SQL folder I have my CSV file that is employe data. CSV so I’ll just select this you can either do it like this or you can browse and do okay now my format is CSP next I’m going to select my headers as yes and then let me go to columns and check if everything is fine all right so I have all my columns here let’s click on okay you can see I have a message here which says import undor export all right so here you can see successfully completed we can verify this by using select star from employees again if I run this all right let me close this there you go it says 150 rows affected which means we have inserted 150 rows of information to our employees table you can see we have the employee ID this are all unique we have the employee name the email we have the address and the salary let me scroll down so that okay you can see we have 150 rows of information that means we have 150 employes in our table okay now we are going to use this employees table and explore some Advanced SQL commands now there is an operator called distinct so see if I write select address from employees this is going to give me 150 address of all the employees there’s some problem here I did a spelling mistake there should be another D if I run this again I’ll query will return 150 rows you can see we have the different country names under address that is Russia we have France there United States we have Germany okay and I think we have Israel as well yeah now suppose you want to display only the unique address or the country names you can use the distinct keyword before the column name so if I write select distinct address from employee it will only display the unique country names present in the address column if I run this see it has return returned us six rows of information so we have Israel Russia Australia United States France and Germany all right now as I said there are a few null values which don’t have any information so you can use the isal operator in SQL to display all the null values that are there suppose I want to display all the employee names where the email ID has a null value so I’ll write select star from employees where email is null this is another way to use your wear Clause if I select and run this there you go so you see here for all these employee names there was no email ID present in the table so it has written us 16 rows of information so around 10% of employees do not have an email ID and if you see a few of them do not have an email ID and also they don’t have a department so if you want to know for those employees which do not have a department you can just replace where department is null instead of where email is null now if I select this okay it has returned us nine rows of information which means around 5% of employees do not have a Department moving ahead now let me show you how the order by Clause Works in SQL now the order buy is used to order your result in a particular format let’s say in ascending or descending order so the way to use is let’s say I want to select all the employ from my table so I’ll write select star from employees order by I want to order the employees based on their salary so I’ll write order by salary let me select and run it okay there is some problem I made a spelling mistake this should be employees let me run it again okay now if you mark the output a result has been ordered in ascending order so all the employees which have salary greater than $445,000 appear at the top and the employees with the highest salaries appear at the bottom so this has been ordered in ascending order which means your SQL or post SQL orders it in ascending order by default now let’s say you want to display the salaries in descending order so that all the top ranking employees in terms of salary appear at the top so you can use the dec keyword which means descending if I run this you can see the difference now so all the employees with the highest salary appear at the top while those with the lowest salaries appear at the bottom so this is how you can use an order by Clause okay so now I want to make a change in my existing table so here if you see under the address column we only have the country names so it would be better if we change the name of the address column to Country so I want to rename a column you can do this using the alter command in postc SQL so let me show you how to rename this column that is address so I’ll write alter table followed by the table name which is employees then I’m going to use rename column address I’ll write two I want to change it to Country if I give a semicolon and hit execute it will change my column name to Country now you can verify this if I run the select statement again there you go earlier it was address column and now we have successfully changed it to Country column okay let me come down now it’s time for us to explore a few more commands so this time I’m going to tell you how an and and an or operator Works in SQL so you can use the and and or operator along with the wear Clause so let’s say I want to s SE the employees who are from France and their salary is less than $80,000 so let me show you how to do it I’ll write select star from employees where I’m going to give two conditions so I’ll use the and clause or the and operator here I’ll write where country is equal to France now Mark here I’m not using address because because we just updated our table and changed the column name from address to Country so I’ll write country equal to France and my next condition would be my salary needs to be less than $80,000 I’ll go a semicolon let me run this all right so it has returned 19 rows of information you can see all my country names of France and the salary is less than $80,000 so this is how you can use or give multiple conditions in a we Clause using the and operator now let’s say you want to use the or operator and let’s say you want to know the employees who are from country Germany or the department should be sales so I’ll write select star from employees where country is equal to Germany and instead of and I’m going to use or their Department should be sales okay now let’s see the output I’ll hit F5 this time to run it all right so we have 23 rows of information now let me scroll to the right you can see either the country is Germany or the department is sales you see one of them in the table so here for the first record the country was Germany the second record the department was sales again sales again for the fourth record the country is Germany so this is how the or condition works so if one of the conditions are true it will return the result it need not be that both the conditions should satisfy now in post SQL there is another feature that is called limit so post SQL limit is an optional clause on the select statement now this is used as a constraint which will restrict the number of rows written by the query suppose you want to display the top five rows in a table you can use the limit operator suppose you want to skip the first five rows of information and then you want to display the next five you can do that using limit and offset so let’s explore how limit and offset works I’ll write select star from employees let’s say I’ll use my order by Clause I’ll write order by salary let’s say in descending and limit it to five this is going to display the top five employees which have the highest salary if I run this there you go you see it has given us five rows of information and these are the top five employes that have the highest salary okay so this is one method of or one way of using the limit Clause now in case you want to skip a number of rows before returning the result you can use offset Clause placed before the limit Clause so I’ll write select star from employees let’s say order by salary descending this time I’m going to use limit 5 and offset three so what this query will do is it will skip the first three rows and then it will print the next five rows if I run this there you go so this is how the result looks like okay now there is another clause which is called Fetch let me show you how that works I’ll copy my previous SQL query I’ll paste it here and here after descending I’m going to write fetch first three row only so my fetch is going to give me the first three rows from the top there you go it has given us the first three rows and you can see the top three employees that have the highest salary since we ordered it in descending order of salary all right you can also use the offset along with the fetch Clause I’ll copy this again and let me paste it here now after descending I’m going to write offset let’s say three rows and fetch first five rows only so what this SQL query is going to do is it will skip the first three rows of information and then it is going to display the next five rows it is going to work exactly the same as we saw for this query let me run it there you go so these are the first five rows of information after excluding the top three rows all right we have another operator that is called as like in post SQL so like is used to do pattern matching so suppose you have a table that has the employee names you forgot the full name of an employee but you remember the few initials so you can use the like operator to get an idea as to which employee name it is now let’s explore some examples to learn how the like operator Works in postris SQL so suppose you want to know the employees whose name starts with a so for that you can use the like operator let me show you how to do it so I want to display the employee name and let’s say I want to know their email IDs from the table name that is employee where since I want to know the employees whose name starts with a so I’ll write employee name like now to use the pattern is within single course I’ll write a and Then followed by percentage now this means the employee name should have an e in the beginning and percentage suggest it can have any other letter following a but in the beginning or the starting should be a if I run this so there is an error here the name of the table is employees and not employee let’s run this again there you go you can see there are 16 employees in our table whose name starts with a you can see this column employee name all of them have a letter A in the beginning okay now let me just copy this command or the query I’ll paste it here let’s say this time you want to know the employees whose name starts with s so instead of a I’ll write s so this means the starting letter should be S and followed by it can have any other letter if I run this so there are 10 employees in the table whose name starts with s okay let’s copy the query again and this time I want to know the employees whose name ends with d now the way to do it is instead of a percentage I’ll write this time percentage D which means at the beginning it can have any letter but the last letter in the string or in the name should be ending with D now let me copy and run this so there are 13 employees in the table whose name ends with a d you can see it here all right now let’s say you want to find the employees whose name contains ish or have ish in their names so the way to do is something like this so I’ll copy this now here instead of a percentage I’ll replace this with percentage ish percentage now this means that in the beginning it can have any letter and towards the end also it can have any letter but this ish should appear within the name let me run and show it to you okay so there is one employee who name contains ish you can see here there’s an ish in the last name of the employee all right now suppose you want to find the employee name which has U as the second letter it can have any letter in the beginning but the second letter of the employee name should have U now the way to do is I’ll copy this and instead of a% I’ll write underscore U followed by percent now this underscore you can think of a blank that can take any one letter so the beginning can start with a B C D or any of the 26 alphabets we have then then it should contain u as the second letter followed by any other letter or letters let me run this okay so there are 10 employees in the table whose name has a u as the second letter you can see these okay now moving ahead let me show you how you can use basic SQL functions or inbuild functions so we’ll explore a few mathematical functions now so let’s say you want to find the total sum of salary for all the employees so for that you can use the sum function that is available in SQL so I’ll write sum and inside the sum function I’ll give my column name that is salary from my table name that is employ let’s see the result this will return one unique value there you go now this is the total salary since the value is very large it has given in terms of e now one thing to note here is if you see the output the column says sum real so this output column is not really readable so SQL has a method which can fix is that is called an alas so since we are doing an operation of summing the salary column we can give an alas to this operation by using the as keyword so if I write sum of salary as let’s say total salary then this becomes my output column you can see the difference if I run this okay you can see now in the output we have the total salary now this is much more readable than the previous one so this is a feature in Excel where you can use or give alas names to your columns or your results now similarly let’s say you want to find the average of salary for all the employees now SQL has a function called AVG which calculates the mean or the average salary if I write AVG and I I can edit my alas name as well let’s see I’ll write mean salary let’s run it you can see the average salary for all the employees it’s around $81,000 okay now there are two more important functions that SQL provides us which is Max and minimum so if I write select maximum or Max which is the function name of salary as let’s say instead of total I’ll write maximum so this will return me the maximum salary of the employee let’s run it and see what is the maximum salary that is present in the salary column all right so we have 1ak 9,616 as highest salary of one of the employees similarly you can use the minan function as well I’ll just write minimum and this will return me the minimum salary of one of the employees in the table I’ll replace the alas name as minimum okay now run it this will give me the minimum salary that is present in our table so it is $4,680 okay now let’s say you you want to find the count of Department in the employees table you can use the count function so if I write select count let’s say I want to know the distinct Department names I can write inside the count function distinct Department as total departments from employees let’s run this this will return me the total number of departments that are there so it gives me there are 12 departments okay now let me show you one more thing here if I write select Department from employees let let’s run this okay so it has returned me 150 rows of information but what I’m going to do is I’ll place my distinct keyword here just before the column name so that I can verify how many departments are there in total there you go so there are 13 departments and one of them is null so moving ahead we’ll replace this null with a department Name by updating a table okay so now let’s update our department column so what we are going to do is wherever the department has a null value we are going to assign a new Department called analytics so earlier we have also learned how to use the update command so I’m going to show it again so we’ll write update followed by the table name that is employees I’m going to set my column that is Department equal to within single codes my name of the department would be analytics where department is I’ll say null so wherever the department has a null value we replace those information with Department that is analytics let’s run this you can see quy returned successfully now let’s say I’ll run this command again and this time you can see the difference there you go so we have 13 rows of information and there is no null department now we have added a new department that is analytics okay now we are going to explore two more crucial commands or Clauses in SQL that is Group by and having so let’s learn how Group by Clause Works in post SQL so the group by statement groups rows that have the same values into summary rows for example you can find the average salary of employees in each country or city or department so the group by Clause is used in collaboration with the select statement to arrange identical data into groups so suppose you want to find the average salary of the employees based on countries you can use the group by Clause so let me show you how to do it I’ll write select I want the countries and the average salary for each country so I’ll use the average function that is AVG and inside the function I’ll pass my column that is salary I’ll give an alas name as let’s say average uncore salary from my table name that is employees next I’m going to use my group by Clause so I’ll write Group by since I want to find the average salary for each country so I’ll write Group by country name let’s give a semicolon and let me run it I’ll use F5 there you go so here on the left you can see the country names we have Israel Russia Australia United States France and Germany and on the right the second column you can see the average salary for each of these countries now you can also order the result in whichever way you want suppose you want to arrange the results based on the average salary so you can use the order by Clause after the group by Clause so I’ll write order by here you can use the alas name that is average salary this is actually average uncore salary and let’s say I want to arrange it in descending order so I’ll write DSC now let’s run this you can mark the difference in the average salary column there you go so as per our result in United States the average salary is the highest and if I scroll down the average salary is the lowest in Germany now let’s see one more example using group buy suppose this time you want to find the maximum salary of male and female employees you can do that too so let me show you how to do it so I’ll write select this time we want to find the maximum salary based on gender so I’ll select my gender column comma and this time I’ll use my Max function since I want to find the maximum salary for male and female employees I’ll give an alas name as Max maximum underscore salary from my table that is employees Group by I’ll write gender okay so let’s run this there you go you can see so one of the female employees had a highest salary of $1 lak1 19,618 while of that of a me was $ 17,6 54 all right now suppose you want to find the count of employees based on each country you can use the count function along with the group by Clause so I’ll write the select statement select since I want to count the employees based on each country so I’ll first select my country column and then I’m going to use the count function I’ll write count e _ ID from my table name that is employees I’m going to group it by country so this query will give me the total number of employees from each country you can see here Israel there are four employees in Australia there are four employees in Russia we have 80 employees in France there were 31 in United States we have 2 7 so on and so forth now let me scroll down okay now it’s time to explore one more Clause a very important Clause that is used in post SQL that is having so the having Clause works like the wear Clause the difference is that wear Clause cannot be used with aggregate functions the having Clause is used with the group by Clause to return those rows that meet a condition so suppose you want to find the countries in which the average salary is greater than $80,000 so you can use the group by clause and the having Clause to get the result so I’ll write my select statement as select country comma I want the average salary so I’ll write AVG of salary I can give an alas name as average salary from employees now I’m going to group it by each country so Group by country colum since I want to find the countries in which the average salary is greater than 80,000 so I’ll use having Clause after the group by Clause I’ll write having average of salary is greater than 880,000 now this condition cannot be specified in the wear Clause so we need a having Clause you cannot use aggregate functions along with wear Clause let me just run it now there you go so we have Russia and United States where the average salary is greater than $80,000 all right now let’s say you want to find the count of employees in each country where there are less than 30 employees so for this I’m going to use the account function first let me select the country column then I’m going to use the count function and in the count function I’m going to pass my employee ID so that we can count the number of employees from my table that is employees now if you want you can use an alias name for this as well but I’m just skipping it for the time being I’ll write Group by country next I’ll write having count of employee ID less than 30 so this will return me the countries in which there are less than 30 employees let’s run it you can see here Israel Australia United States and Germany are the countries in which there are less than 30 employees okay now if you want you can use the order by Clause as well so suppose I’ll write here order by count of employee ID so what this will do is it will arrange my result in ascending order of employe ID count there you can see we have successfully arranged our result in s order of employee IDs okay next we are going to explore one more feature of post SQL that is of using a case statement now in post SQL the case expression is same as IFL statement in any other programming language it allows you to add if else logic to the query to form a powerful query now let me just scroll down and I’ll show you how to use a case statement this is very similar to your eel statement that you use on Excel in C++ in Python and or any other programming language so what I’m going to do is I’m going to write a SQL query that will create a new column and the name of the column would be let’s say salary range so I’m going to divide my salary suppose if the salary is greater than $45,000 and if it’s less than $555,000 in the new column that is salary range we are going to assign a value low salary now if the salary is greater than $55,000 and if it is less than $80,000 we are going to assign a value that is medium salary if the salary is greater than $80,000 we’ll assign a value High salary so all this we are going to do using our case expression in post SQL so I’ll start with my select statement but before that let me show you how to write a comment in post SQL so you can write a comment by giving a Double Dash comments are very helpful because they make your codes or the scripts readable I’ll write case expression in postc SQL similarly if you want you can go to the top and let’s say here you can write with Double Dash having clause okay let’s come down so I’ll write my select statement as select I want the department the country and the salary column I’ll give a comma and I’ll start with my case statement I’ll write case when my salary is greater than 45,000 and my salary is less than 55,000 then the result would be within single codes I’ll write low salary so this is exactly like an if else condition next I’ll write another case when salary is greater than 55,000 and salary is less than let’s say 80,000 then the result would be medium salary and finally I’ll give my last condition that is when salary is greater than 80,000 then the result will be high salary let me write this in a single line then High salary now one thing to remember in postris SQL the codes are insensitive so you can write your select statement in capital in lower case or in sentence case similarly I can write case as small C or you can write as Capital C all right now moving ahead after this I’m going to write end I’ll give an alas name as salary range now this is going to be my new column in the output let me just come down after this we need to give our table name from employees I’ll order it by salary descending okay so what I’m going to do here is I’ll first select Department country and salary column from my employes table and then I’m creating a new column that is salary range and I’m specifying the range so I have three conditions here for low salary for medium salary and high salary so so let’s run this and see the output there you go here you can see we have added a new column known as salary range and we have order our salary in descending order so all the highest salaries appear at the Top If I just scroll down you can see we have medium salaries here and if I scroll down further you can see this low salaries so case statements are really useful when you want to create a new column based on some conditions in the existing table all right now moving ahead we are now going to see how to write subqueries in post SQL so subqueries we write a query inside another query which is also known as nested query so suppose we want to find the employee name Department country and salary of those employees whose salary is greater than the average salary so in such cases you can use subqueries but let me show you how to write a query inside another query first I’ll write the select statement I’m going to select the employee name comma I want the department comma also want to display the country name and the salary from the employees table where my salary should be greater than the average salary so after this bear salary greater than I’m going to use brackets and write my subquery that is Select average salary from employees now let me break it down for you so first we are going to select the average salary from the employees so this particular SQL statement we’ll find the average salary from the table we’ll compare this average salary with salaries of all the employees so whichever employee has the salary greater than the average salary will display their names the department country and their original salary so if you want you can run this statement as well let me select this statement and run it for you you can see we have return the average salary of all the employees which is nearly $81,400 $6 so we want the salaries of the employees to be greater than this average value so let me run this and see how many employees have a salary greater than the average salary there you go so we have around 75 employees whose average salary or whose salary is greater than the average salary all right now moving ahead this time I’m going to tell you how to use some inbuilt functions we learn some inbuilt mathematical functions and string functions that are available in postris SQL so I’ll just give a comment there’s another way to write a comment instead of a Double Dash you can use the forward slash an asteris and inside the asteris you can write let’s say SQL functions and you need to close this so I’ll give another asteris and a forward slash so this is also a comment in postris SQL all right so first of all we’ll explore a few math functions so there is a function called ABS which is used to find the absolute of a value so if I write select abs of let’s say Min – 100 it is going to return me positive 100 or just 100 because as you know the absolute of any value will remove the negative sign involved in that value there you go so our original input was – 100 the absolute of- 100 is + 100 next let’s see another function that is called greatest so the greatest function in post SQL will return the greatest number in a range of numbers so suppose I write select greatest inside the greatest function I’ll pass in a few few numbers let’s say two I’m just randomly passing a few numbers let’s say 4 90 let’s say 56.5 and let’s say 70 I’ll give a semicolon let me run this you will see the greatest function will return the greatest integer value or greatest number that is present in the range of numbers that we have provided so in this case 90 was the largest number or the greatest numbers so we got the result as 90 again you can use an alas for each of these statements now like greatest we also have a function called least which is going to return the least number present in a range of numbers if I run this so the result is two because two is the least number that is present in this selection all right now there’s a function called mod which is going to return the remainder of a division so suppose I write select mod and this takes two parameters let’s say 54 ided 10 as you can guess the remainder is 4 and so is our result you can see it has return the remainder 54 divided by 10 the remainder is 4 all right if I scroll down now let’s see how to use the power function so I’ll write select power let’s say I want to know power 2 comma 3 which is 2 Cube that is 8 let me just run this there you go so the result is 8 you can also check let’s say power of 5 comma 3 it should be 125 all right next you can use the sqrt function that is available in post SQL to find the square root of a number I’ll write sqrt and let’s say I want to find the square root of 100 you can guess the result the output should be 10 if I run this you can see the output here 10 let’s say I want to find the square root of let’s say 144 you can again guess the result it should be 12 let’s verify it okay there is some error let me verify it again there you go it is 12 now there are a few trigonometric functions as well you can use the S function the COS function and the tan function let’s say I want to know the sign of 0 if you have studied High School mathematics you would know the sign of 0 is 0 you can see the result it is0 let’s say you want to know s 90 if I run it you can see the output here 89 all right now there are other functions like ceiling and floor that you can use so let me show you what the ceiling and floor function does I’ll write ceiling let’s say I’ll pass my floating value as 6.45 and let me run it you can see the ceiling function Returns the next highest integer that is 7 in this case since the next highest integer after 6.45 is 7 let’s see what the floor function does and let me run it as you can see the floor function Returns the next lowest integer that is six in this case or the nearest lowest integer to any provided decimal value okay now that we saw how to use mathematical functions there are a few string functions available in postris SQL so let’s explore them as well I’ll write string functions okay scroll down cool there’s a function called character length that gives you the length of a text string suppose I write select give the function as character length and inside this function I’m going to pass in a text let’s say India is a democracy this is my text let me run this okay you can see the result here which is 20 since there are 20 characters in my string that I have provided all right now there’s another function called concat in post SQL so concat is basically used to merge or combine multiple strings so I’ll write select concat within brackets I’ll give the text string now let’s say I want to combine post Crest SQL I’ll give a speed comma I want to merge post SQL is I’ll give another comma and write my final word that is interesting now what we have done is inside the concat function we have passed in separate strings and now using the concard function we want to merge the three strings let’s see what what the result is I’ll run it all right let me just expand this you can see here we have Conca inated the three strings successfully so the output is post SQL is interesting okay now there are functions like left right and mid in post SQL so what the left function does is it will extract the number of characters that you specify from the left of a string let’s say I’ll write select left and I’ll pass in my text string as India a democracy I’ll copy this and I’ll paste it here let’s say I want to extract the first five characters from my string so I’ll give five so what it will do is it will count five characters from left so 1 2 3 4 and 5 if I run this it should ideally print in for me there you go it has printed India for us all right similarly you can use the right function to extract few characters from the right of a string let’s say you want to extract let’s say I’ll give 12 characters from right so from here onwards it will count 12 characters I’ll change left to right now let me select this and run it so you can see here this is the output from the right it has counted 12 characters and returned a democracy okay now there is a function called repeat so the repeat function is going to repeat a particular string the number of times you specify let’s say I want to select and use my repeat function and inside the repeat function I’m going to pass in let’s say India and I want India to be displayed five times I’ll give a semicolon and run it in the output you can see India has been printed five times okay let’s scroll down there is another function a string function in post SQL called as reverse so what reverse function is going to do is it is going to print any string passed as an input in reverse order so if I write select reverse and inside the reverse function I’ll pass in my string that is India is a democracy I’m going to use the same string I’ll copy this and I’ll paste it here I close the codes and the brackets let’s print this you can see it here India is a democracy has been printed in reverse order there you go all right now this time we explored a few inbuilt functions that are already present in post SQL now post SQL also has the feature where you can write your own user defined functions so now we will learn how to write a function of Our Own in postris SQL so let’s create a function to count the total number of email IDs that are present in our employees table so for this we’ll write a function a user defined function so let me give my comment as user defined function okay so let me start by first writing create so this is the syntax to write a function in post SQL so I’ll write create or replace function then I’ll give my function name as count emails and as you know functions have brackets then I’ll write Returns the return type as integer then an alas with dollar symbol I’ll write total emails since I’m going to display the total number of email IDs that are present in my table I’ll close the dollar symbol then I’m going to declare a variable the variable name is going to be total underscore emails this is of type integer I’ll write big and inside begin I’ll write my select statement so I’ll write select I want to count the email IDs that are present so I’ll pass my column name that is email into total emails from my table name that is employees I’ll give a semicolon and then we’ll write return total emails as you know user defined functions often return a value so hence we have mentioned the return statement as well and now I’m going to end my function then the next syntax would be let me just scroll down Okay so here I’ll give my dollar symbol again followed by total underscore emails next I’ll write my language post SQL so the way to mention is PL p g SQL let’s give a semicolon and end it so this is my user defined function function that I have written so I created a function with the function name countor emails and this would return integer as an alas which is total _ emails we declared that variable as an integer then we started with our begin statement that has my select statement where I’m selecting the count of email IDs that are present in the employees table and I’m am putting the value into total _ email so I’ve have used the into keyword and this Returns the result as total _ emails and I have ended let’s run this okay there is some problem there is an typo so this should be integer okay let me run it once again there you go so you’ve successfully created a userdefined function now the final step is to call that function now to call this function I’m going to use my select statement and the function name that is countor emails I’ll give a semicolon let’s execute this there you go so here you can see there are 134 email IDs present in our employees table now one thing to Mark is there are total 150 employees in the table but out of them 134 employees have email IDs the rest of them don’t have so they would ID have null values all right so that brings us to the end of this demo session on postris SQL tutorial let me go to the top we have explored a lot so we started with checking the version of post SQL then we saw how to perform basic mathematical operation that is to add subtract multiply then we saw how to create a table that was movies we inserted a few records to our movies table then we used our select Clause we updated a few values then we deleted one row of information then we learned how to use the wear Clause we learned how to use the between operator we also learned how to use the in Operator Let Me scroll down we created a table called employees and then we learned how the distinct keyword works we also learned how to use isnull with wear Clause we learned about the order by Clause we saw how to alter or rename a column then we explored a few more examples on WE Clause where we learned about and and or operator then we learned how to use limit and offset as well as the fetch operator or the fetch keyword in postr SQL moving further we learned about the like operator in SQL which was used to perform pattern recognition or pattern matching you can say here we saw how to use basic inbuilt post SQL functions like sum average minimum count maximum next we saw how to update a value in a column using post SQL update command we Lo learned how to use Group by then we learned how to use having Clause then we learned how to use case expressions in postc SQL so we saw how case expression is similar to our ifls in any other programming language we explored a few mathematical and string functions and finally we wrote Our Own userdefined function so that brings us to the end of this tutorial on postris SQL in this session we will learn about how to join three or more tables in SQL that’s right so so far we have a fundamental understanding of how to join two tables but in a few situations you might have to extract the data by joining three or more tables right so that’s exactly what we are going to discuss today now without further delay let’s get started now we will jump into the MySQL workbench where we have our query ready so here we will be using three tables employe details employ employe register and employee joining register so we want employee name contact number and joining date joining date is available in joining register contact number is available in employee register and employee name is available in in employee details right so here we are utilizing all three tables and joining them to extract these three columns so here I’m providing the table name and the column name to make sure that the SQL workbench will not get confused which employee name I mean which employee name column should I access which table should I use so to clear that confusion I’m providing the table name so my SQL will use employee details table and from there it will extract the employee name column and contact number to be sure it is present in only one table so it will go to employee register and joining date it is also present in only one table so no need to specify the table name name but to be on safer side if you want to add you can add that’s well and good and it will create an impact to your interviewer considering that you know about the syntaxes so I’ll just follow the normal syntax the way I’m going now and now I’m trying to join it’s the same operation what you use to join two different tables so you’ll just join use the join clause and give the second table name and on what basis so I’m joining these two tables on the primary key employee ID so both tables have the same common employee ID So based on that I’m joining these two tables and then you will use the join Clause once again and give the third table name here and based on which primary key or which common key so this is the one which is common in both the tables and is unique which is the employee ID so I’m using the same one to join the two tables with the third one you can follow the same syntax and join another table to it as well so with this let’s execute this particular query to find our answer so there you go you got the query executed and you have the table over here with employee name contact and joining date let’s quickly get back to my SQL workbench so here let’s say you wanted to create a table and load the data so if the data is minimalistic maybe the data about 10 rows or 15 rows you can manually create a table and insert the elements into your table using such insert commands but this set like mine which is in the Excel spreadsheet and and has about 10,000 rows would you like to you know write 10,000 insert commands no right it would be really timec consuming so for situations like this MySQL workbench has enabled developers to load the data from spreadsheets within a few steps but before we get started let’s check our column headers so here you can see uh it is not compatible with the MySQL workbench or SQL commands right so it has a space and it has a word row and it is a keyword in my SQL right so we don’t want that confusion so for that reason we will try to modify this maybe using an underscore right similarly for the row ID you can eliminate space and use an underscore and when it comes to order ID the same so just let us quickly change all the column headers so that there are SQL compartible there you go so we have replaced all the headers with underscores and made them SQL compatible so let us save it and when you’re saving it just make sure that your Excel file data is also having the uh you know SQL compatible uh name so here we have load CSV to my SQL so here we have the name with space right so let’s try to change that to lowercase Excel data and like right now it is is SQL compatible Now quickly let’s go back to my SQL workbench here we have it now you can just create a new table just right click here or you can also do it from here create a new database and the new schema will be the name of your data set so let’s type it as Excel data or just Excel and apply now this is the schema apply now you have Excel right here just drop down on here you can see the tables right click the tables and here you have the option of uh import data Vis it right just click on that now browse your folders and have it so yeah another notification for you guys so you need to save your Excel spreadsheet in the form of comma separated file right let’s quickly go back and do that open your spreadsheet go to file see as comma separated file save there you go now let’s get back to workbench and now I think you will be able to find it just open next drop table of access make sure you do that to be on the safest side and check all the names here so we have a problem with row ID but that is something which you can fix down the line and before you go to the next step check all the other names as well every other name on the column header is fine just the first one we can just alter the table not a big deal and uh next it should start importing there you go the data file got imported of course it took a little while because it’s 10,000 that’s normal now let’s quickly go to the next step and here you can see 9,987 records imported successfully just click on finish and I think it should be shortly done let’s close the schema go to the query table and and yeah so you can quickly refresh so that you will have the Excel dat over here now let’s use the database that is Excel on it now we are in Excel database now the table we’re looking for is Select star from the data name the data table name is Excel data without a space semicolon just quickly run it and I think we should be shortly able to see all the data sets right over here yeah about the First Column ID we can simply use the alter table um function or query to change the name let’s quickly do that with the table name alter table rename okay what was this can you copy that copy field name rename row ID to so um a small see syntax ER there so I think they should be sorted yeah and now let’s quickly run this and I guess it should be done now let’s quickly run the select command again there you go so we have the row ID order ID uh aut dates ship dates ship in mode customer ID customer name Etc and everything is as per the expectations and that’s how you can load Excel data to mySQL workbench we will learn about the top five interview questions in SQL that you must know to crack your business analytics interviews now without further Ado let’s get started so speaking about the tough five interview questions let’s quickly jump to the workbench of SQL so I’m using my SQL workbench and here we have a database called use simply learn so SLP is the database name so we will be using the use command to get access to that particular database so we are in access to it and now let’s quickly check out tables show tables there you go we have a few tables here book collection book order employee details joining register and employee register so let’s go with the employee details so I’ll just simply shoot a command select star from EMP details so now we have our employee table so we will be using this particular data set to run few queries from our interview questions so getting back to the interview questions so most commonly you will be asked the following interview questions so the first question is you will be asked to find out the names of the employees that start with the vbls so AEI w u so they will ask a question give me the list of names that start with these five letters it can be either a or e or I O U right so what’s the question so here you will be using like operators and not like operators let’s say they want the names with vels so you can just use the like operator and use this particular command select employee name that’s the name of the column from employee register or employee details and then where employee name is like a modulus which means it should start with a and it can have any number of alphabets after that right so let’s quickly also check what do we have in employee register so I think it’s a similar table to employ details that we used before we have the same details here so no not our problem now let’s try to extract the names of the employees W names start with WS right so we will be using the we clause and like operators run the command and there you go so we have three names so if if you able to answer this question they will ask they might ask a similar question with a little modification so this time they might ask you give me the list of names that will not start with vels so you’ll just replace the like operator with not like so either they’ll ask the questions which might ask start with vels or they might ask a question which does not start with vels this is one of the common questions now going to the second question so here also they will give it a Simple Start they will ask to give the details of the employe who has the highest salary or they will ask you to give the highest salary you can simply use the max aggregation and you can get the maximum salary so we have $887,000 and sometimes if you are able to answer this question they will make it a little tricky to you and they will ask give the second highest salary here you can use offset or there are multiple possibilities but let me give you the simplest one where you can have the same query only difference is where salary is less than Max of salary first the subquery will be executed which will extract the maximum salary and the next one is less than so it’ll give you only one R which has a little salary which is Les less than the maximum one right so simply let’s execute the query so we will have the answer so the next highest salary is $78,000 now moving on to the third question so sometimes they will ask you to use the update commands as well so here we have some salary details of our employees in the employee register employee going to do here is let’s say this is the appraisal period and they’re giving you 15% hike to all the employees so you need to update the salary column so what you do is simply uh update table name salary plus salary into the percentage of hike which is 15% so here we adding that particular percentage in the form of decimal numbers which is 0.15 and simply run the command and you have it now you can just simply uh query the same detail which is Select Staff from employee details so you will have the updated salary list here there you go now let’s proceed with the next question that we have in our list which is about select the employee name and salary from a given range right if they ask you give me only the range of employees who ow salary lies between 50,000 to 70,000 so you can use the between operator here and range of numbers that is 50,000 and 70,000 just run this particular code and there you go you have the Dil so there are two employees whose salary lies between 50,000 and 70,000 now the last question is uh they might ask you to extract the details from a certain department so basically this might also turn up to find a difference between having and group by Clause sorry having and wear Clause yeah so this is one of the common interview questions where they will ask the difference between having and wear Clause so when you are implementing Group by in your quer query and you’re also implementing some aggregate functions like count sum Etc minimum maximum in those situations when a group by Claus is involved then you can use having when there is no uh Group by function then you can simply go with the wear Clause so here I’m trying to extract the number of people present in finance department so I’m not grouping by department so I can just use where clause and run this and now in situations where I have to group by I mean you know when I have to implement Group by in those scenarios you can include having clause in place of well so that is the fundamental difference between having and group by and also you got the understanding of group by command here imagine walking into a giant Library this isn’t just any Library it’s huge there are rows and rows of shelf each packed with thousands of books but wait you don’t need to read every book here you’re just looking for specific ones like books about space or stories about superheroes but finding what you need is such a huge uge Library that’s going to be tricky this massive library is like a database a database is a huge collection of information stored neatly ready to be used it holds everything name address grades prices whatever data you can think of but sometimes all that information can be overwhelming you don’t want to shift through everything every time you need something specific right that’s where views comes in in this video we will explore views in Sequel explaining what what they are and how they simplify working with databases we’ll also cover how to create views manage them by updating deleting and listing them and also introduce different types of views like simple complex read only and those with check option we’ll also dive into materialized views which store data for faster queries and by the end you will understand how views can manage data easier and more efficient we will also look into a quiz question to clarify your understanding so what exactly is a view let’s go back to our Library example imagine if you had a Magic Window a special one that only shows you the books about space or superheroes that you are interested in you don’t have to wander through the entire Library anymore you just look through your magic window and it gives you exactly what you need that Magic Window is what a view is in the world of databases a view is a special virtual window into a data that shows you only what you need to see and the best part is it’s not actually stor any new data it’s giving you a filtered look into a huge database think of view as a shortcut making your life a whole lot easier so let us get into the demo part about how to creating a view and the types of views in SQL so let’s start with the demo part that is how do we create a table in my SQL so here as you can see uh I’ve just logged into an online compiler and now we will just learn how we create a table and then we’ll move on to creating views and the types of views so first to create a table just enter this command just WR over here create create table sorry and this just enter the table name it could be something like student details and here you can give the U student ID name we want a student ID name in the first row so we’ll just keep s ID and and the type of the variable is integers we’ll just mention in here and since it’s a primary key you just mention it over your primary key

    next variable can be something like name and for this the type is bar care you can just enter any number here suppose I’ve enter 255 I’m sorry comma next mention the address again it’s Vare address so as you can see we have created this table with student ID name so we have to give you underscore student ID name with primary key inte teer type and the name and the address over here so after we have created this table we want to insert data into the table this is our next step step so to insert data what could be the basic uh command which you can write can be something like insert into student the table name student details over here and just mention what all uh columns which we have attributes we have created which is uh S uncore ID next is name and then we have address over here and then we mention the values so now that we have created table and then we can enter our details over here so these are the values which I have inserted which is hsh Ashish prati tanra sham okay so like this you can enter the values over here and now if I want my records to be displayed here the command which I’m using is Select star from student details so all these the table will be shown here so we’ll just click on this run button over here okay so now you can see this is the Sid name number and the names which we have mentioned over here so as you can see this is the output generated this is the Sid the name and here is the address so as you can see the table is created now and the output is also shown now we will move on to the main step which is creating a view so what exactly is a view a view is like a window that lets you see specific data as I’ve already told you in the intro part so now let’s say we only care about students with S ID less than five okay and instead of running the same query every time we want to create a view so here’s how you can do it you can just simply enter the command so here’s how you can create a view so just mention this U command which is create view detail view as select name comma address from student details so student details is the table here which we have already created before and I want the student ID less than five okay so I want this to be shown here so we’ll just simply click on run over here so as you can see this is the error it’s showing why is it showing because line number 203 view must be the first statement in a query batch so to resolve this we have to ensure that the SQL batch is properly separated by go command and the view creation is syntactically correct all right so we haven’t used the go command here to do that we just simply after we have inserted our records in the table here you just type goo okay and so this is the end of the first batch and now since we have have created a view in a new batch we’ll just mention this uh whatever command we have already given and at the end of the second batch we’ll again write Cod okay and now next I want my query to be shown here so I’ll just write this command for my for generating my output which is Select select star from and the table name okay not that uh student details table name name I want this the view table name to be show which is detail view right this is the table name so just copy it from here just paste it give this semicolon so now you can see a view is created so why have we used go because go ensures that to create view command is executed in a new batch and this will help the SQL Server properly separate commands and avoid conflict all right right and we have also used the select star from details view which will fetch the data from The View and includes only student with student ID less than five which is danj pratik Ashish and hsh okay name and the address is displayed over here so this is our output generated now let’s talk about managing views and updating the view let’s say later on you want to update the view to also include the students age instead of deleting or recreating the view you can use create or replace view to update it so let’s add the age column to the table now so we have to just insert the data for the students here so to add a new column age to the students detail table we need to use this command which is Alter table and then provide the name of the table which is student details add age and the type is integer and give the semicolon over here all right and now we have to insert the age data for the student so to do this we will use the update command and here we will just write this update okay name of the table which is student and here we use set age is equal to 19 where S ID is equal to two no sorry with the S ID is equal to one so in the similar way you have to just update all the table over here so after updating it you can just simply search run here so like this you will just update the student details and set the age accordingly and now the next step is after updating it we have as you can see we have just entered all the age number which we want to be displayed here and we have used the insert to command to insert records into the table with the age values and now in order to select it we will uh give the command which is Select star from and the name of the table which is student details and now we want to end the P we have to use this go command enter so now as you can see we have updated and inserted all the age data for the students and we have selected all the data from student details to display the final result by giving this command which is Select Staff from student details and this is the name shown over here and here is the address and this is the age so we have inserted all the age data and we have also corrected the update statement set age is equal to 19 where Sid is equal to 1 and do not forget to add this go okay now the next thing which we will be talking about is deleting a view in order to delete a view you just simply have to uh give this command which is drop view if exists and then give the name I mean the table name which is details view right and just simply you can uh go to this just run and you can see that our table has been dropped okay so now we have deleted our table just by giving this command now so and do not forget that this command will delete the view but don’t worry the data in the original student details table will not be affected only the view table which we have created is deleted and now next we’ll be talking about listing all the views okay so now in order to list all the views just you have to Simply write this command which is show full tables where table type is equals to v i view so by doing this thing uh this output will give you all the views which we have created in this table the name student ID okay and the uh addresses and also the age so it will give you all the table view table which we have created now let’s move on to the main part which is uh the types of views in SQL now let us first understand what is a simple view so simple View view is Created from a single table it’s straightforward and it doesn’t involve complex Logics like joints or subqueries for example to create a simple table you just simply have to write this command which is create view student names as and then select name from student details okay so if you query this View and then write select star from student names okay so after doing this thing you just simply click on run so after we have written this view simple view which is create view student name as select name from student details and do not forget again to mention this go and then select query the simple view to display student names and Select Staff and student names all right and at last again add this go and here this is the output generated the names all right so by using simple query you can do this thing now let’s move on to the second card which is creating a complex view a complex view involves multiple tables or complex logic let’s say we have another table who has student marks that that stores student marks so let’s say so let’s say we have created this table student marks and uh we have given the details here and again we have inserted the data values student ID marks 1 93 these are the values which we have inserted this is the student ID and these are the marks which we have given all right so now let’s create a view that pulls data from both student details and student marks so now as you can see we have created a complex view by providing all these details and this is the student ID and the marks shown over here all right so now let’s move on to the third part which is readon view so a readon view ensures that no one can modify the data through the view this is useful when you want users to able to see the data but not change it to make the view read only you can use permissions in your SQL databases and this feature depends on on your database engine to create a readon view and SQL Server we cannot directly enforce read only Behavior with the create view statement however you can control access to the View using permissions so here’s you can how you can do it uh so first you can create the view normally you can use revoke insert update and also delete permissions from users for that particular view uring that they can only read the data so now uh this was all for the readon view let’s move on to the fourth type of the view which we are discussing today which is the check option so with the check option is seel which is with the check option I’ll just type here with check option okay this is the fourth type of view which we are talking about with check option and cq4 it ensures that any insert or update operation performed through a view complies with the conditions specified in the where laws of the view this means that you cannot insert or update records through the view that violate the condition of the view itself so let’s go through the creation of a view with the WID check option and provide an example with an explanation and expected output so now as you can see we have the expected output for the valid insertion uh using this command which is with check option and with view creation check option we created a view named a sample view as you can see here that selects student ID and name from the student details table but only where the name is not null all right so as you can see we have clearly mentioned here not null and the width check option ensures that any insert or update through the view must comply with a condition where name is not n and the first insert into sample view inserts so student where stent id6 name which also has a valid name and here is the output generated here all right this is the student ID the name over here and that’s it so now we have learned about this width check option as well now I’ll be talking about a materialized view so what exactly is a materialized view well a materialized view is different from a regular view because it stores the actual data in a database meaning the data is precomputed and doesn’t need to be fetched from tables every time you query it this makes accessing data from a materialized view much faster especially for complex query all right so as you can see we have created the table and we create three tables the order details table and the product details and also the customer details table over here and then we have provide the necessary data also the Second Step was the sample data is inserted into all the three tables the materialized view fast order summary is created to summarize orders joining data from the three tables and Computing the total cost and the next step is the materialized view is queried and because the data is precomputed it returns results very quickly with new data when added to the audit DS table the materialized view is refreshed using refreshed materialized view to include the new data all right I hope you get it why are we using the refreshed option and the next step is the materialized view is deleted using the job materialized table over here we have used this job materialized view fast order summary and in this way you can you know uh create a materialized view so now you might be wondering that what is the difference between the materialized view and the complex View and the simple view I’ll be seeing you that later so first let us now discuss why are views so useful okay so uh why are views so useful by now you might be wondering what’s the big deal with the views and here’s why it’s so useful they make our life easy you don’t have to keep writing complex queries over and over you create a view once and it saves you tons of time we also help you in simplifying data instead of pulling everything from your database use can help you narrow down exactly what you need you also help in improving security want to show only certain parts of the data to certain people use views to control what others can see without letting them touch the raw data you can also rename columns for clarity you can rename confusing columns in the view without changing the original table making it easier for users to understand the data so so let us not discuss the differences between the simple complex and the materialized view so here’s a quick summary of the differences so simple view PS data from a single table no complex logic or joints involved and it doesn’t store data it also the performance is it executes every query every time whereas the complex view it combines data from multiple tables using joints Aggregates or other complex logic and it doesn’t store data executes query every time and talking about a materialized view it stores the result of a query making it faster to retrieve data without running the query again it also stores data and it is much faster as it uses pre computed data so now it’s time for the quiz here’s a quiz question for you what is the key difference between a regular View and a materialized view in SQL the first option is regular view store data but materialized views don’t second option is materialized view stores data but regular views don’t C both regular and materialized view stores data and number D is neither of them store data so if you want to answer them you can just write them in the comment section below and that’s it views are an incredible tool in SQL that can simplify your queries improve security and make your life easier so SQL Server is a powerful relational database management system developed by the Microsoft which is widely used for managing and storing the data its benefits include High scalability robust security features and seamless integration with other Microsoft tools tools and Technologies SQL Server provides efficient data management through advanced features like indexing full text search and inmemory processing it also offers excellent support for large D sets making it ideal for Enterprise applications the built-in business intelligence tools help organization gain valuable insights from their data SQL service High availability and Disaster Recovery features ensure continuous operations with minimal downtime with strong data integrity and transactional support it ensures reliable and consistent data management across all applications that said if these are the type of videos you’d like to watch then hit that like And subscribe buttons and the bell icon to get notified so in this session for today which is SQL over tutorial we will cover the SQL Basics that is how to create a table how to insert data how to retrieve the data from the tables Etc and apart from that we will also go through some of the other fundamentals of SQL basics which include sorting in SQL server and followed by that we will also go through the group bu and OD by sequences in SQL Server next ahead we will also learn another important part which is conditional statements which includes case statements in SQL proceeding ahead we will get into another segment of today’s session which is about joints and SQL where we will be combining two or more tables in SQL Server followed by that we have the next part of today’s session which is all about the having clause in SQL Server next we will proceed with learning the next part which is about the between operator in SQL server and followed by that we will get ahead with pattern matching in SQL Server next we will cover the time and date functions available in SQL server and after that we will proceed with temp which is temporary tables and SQL server and proceeding ahead we have the most important part which is about the Common Table expressions in SQL server and followed by that we have the last part in SQL Server tutorial which is about creating views and executing a query to extract the data present in a view in SQL so far so good so these are the foundational skills in SQL Server that you need to get before becoming a pro in SQL Server so this particular tutorial will discuss the major Foundation skills the fundamental skills the basics of SE server and its operations now without further delay let’s get started with one of the compilers which can help us execute the SQL Server queries so we are on one of the SQL Server compilers available online in case if you are facing any difficulty setting up the SQL Server management studio in your PC then you can come up with this one and we’ve also set a particular tutorial where you can learn how to download and install SQL Server management studio and how to configure your SQL Server management studio and the link to that particular tutorial will be dropped in the description box below make sure to refer that in case if you wanted to execute these same codes in SQL Server management studio right so first we will be dealing with two different data table so we will be dealing with customer data and dealership data so the first table will be about the customer data where we will be having about the order ID audit date delivery date dealership in code product category and car fuel type Etc followed by that we will insert some rows into that particular customer table about 15 to 20 tables and after that we have dealership database where we will be having AIT date state region customer ID customer name primary foreign Etc and we will be inserting about 20 entries into that particular table don’t worry if you have more than 20 entries in case if you have more than 20 entries let’s say about 2,000 entries or 20,000 entries it’s not at all a big deal if you’re working on SQL Server studio right there you can use the wizard to just ingest the data from your Source into the SQL Server right you can use ssis tool to import all that data and you’re good to go you don’t have to manually create the data and you don’t have to manually insert the data just for the sake of learning the basic process of how to create a data table and how to insert the data table you’re going through this particular procedure so far so good so we have also inserted the data in the next data table which is our dealership data and now let’s query the data from our tables and now let’s select the execute data there you go we have the data table right over here and let’s copy this query and paste it to query the data from the customer table as well so instead of dealership we will be writing down customer so if You observe closely I’m using uppercase for us like select and from and sentence case or lower case for the variables the table names Etc so that there’s a difference between the keyword as well as the regular variables there you go we have executed the customer data and here we have it the order ID order date delivery date dat to deliver category and Etc now let’s mention the use cases corre so um let’s use double codes or maybe we can also use hasht along with the pipe symbol here or the slash symbol here and write the use cases and then proceed with executing the codes or queries so the first use case is let’s try to filter customers from specific regions and now let’s close this particular command proceed with writing the query so we will be using select keyword and we want customers from a specific region right so let’s write down the customer name so I think the customer name is not mentioned in the customer data but instead of customer name we have a order ID so let’s extract the order ID not a problem select order ID and dealership name for state and the important part which is about the region and what product did they and what’s the revenue that uh the dealership has extracted out of that particular customer from the table customer next line is about join dealership so we will be using join table dealership the keyword so we have one common keyword in between both the tables which is about the order ID which is equals to order ID so this is not done here since we are clubbing both tables we need to specify the tables here so dealership do order ID and customer. Order ID so that the SQL Server will identify via are trying to map two different tables and uh we are trying to combine and extract the data now we are trying to filter out uh customers from a specific region correct now we will be using we Clause to specify that particular region so let’s go with west region correct since we are using the text format here so it’s better we choose double codes correct now let’s run this query let’s give it a next try ambiguous order ID so um let’s do one thing we will pull customer table name here so that it’s no more ambiguous there you go so the thing is we have order ID in both the tables customer table and dealership table so SQL Server got confused here which particular table you want me to extract order ID from so if you mention customer table or dealership table it will choose a specific table and extract that particular column now we have the order ID dealership and all the members that we selected are from the vest region if you check here now let’s proceed with the Second Use case of today’s session or okay let’s continue with the same here so that it is clearly visible for us now let’s sort you’re using the sort command here products B B on the revenue so it’s like maybe uh highest revenue should be in the top or lowest Revenue should be in the top let’s go with the highest revenue okay sort products based on uh or based by Revenue we will write the command here itself we will go with uh some columns I would like to have product here so I’ll eliminate everything else and the product will be here and I want the revenue as well now I don’t want the revenue I want the total revenue so if you’re looking for total then you will be going with the function or aggregate function which is sum right I want the sum of all the revenues that particular product has earned throughout the years or that particular Financial Year from which table so I have both product and revenue in the customer table itself so I’ll go with customer table itself I don’t want to join anything here I’ll eliminate the join command and uh instead of region or instead of we command I would use the group by command here bu product and it is not done so far we want to order it so we want to keep it in descending order so that the highest grossing product is on the top and the lowest Crossing product is on the bottom right so that we can also make make sure that our inventory is filled with those products which are giving us High Revenue so we will be using or bu total revenue right so uh we can give it an Laos as total revenue all right now we can use this particular term here order by total revenue descending DEC is good enough now this is how you will sld the products now let’s execute this particular query there you go so the car Model T okay yeah so the car model j is giving us the highest revenue next is followed by TM and sng so we are not mentioning specific if you go back to the uh table here we are not mentioning the actual car brands and actual car Nam so that we don’t want any copyrights to be faced so we are just mentioning some random names not to be too specific there now let’s proceed with our next query for the session where we want to group by state and calculate total revenue let’s edit the same comment here don’t worry if you want this uh demo document we will also link that demo document with all edit and view rights so that all the viewers can have a quick glance and try to execute these queries in their own local systems okay now let me type Down group by state and calculate total revenue there you go now let’s try to edit the same query now we want statewise revenue and we want from customer table right we want to join dealership for this particular one because dealership is the one which has some details for it so the state data right here you can see we have inserted State data California Texas so we want we want the state data so it is present in dealership table so we also want to perform a join there no worries let’s edit the same query here so we want instead of product we want state and instead of sum of Revenue uh yeah we want Revenue so we will keep it as it is total revenue as total revenue some of Revenue as total revenue from customer table and we want to perform a join operation so let’s create some space join dealership okay uh let’s copy the name so that we don’t make any confusions here dealership sorry here don’t worry we’ll make some edits down the line dealership on order ID so let’s go with the order ID which is available here Order ID equals to order ID remember the first step we did eliminate the confusions by mentioning the table names dot column name and customer name sorry the customer table name do column name on yeah we did it on dealership do order IDE equals to customer. order ID now we will be performing the group buy operation we don’t want uh the order buy Here Group by state of course in case if you wanted to you know order by the highest crossing state you could have used order by there but so far according to the use case we don’t want that so let’s continue with the same exec tion here click execute and you will be having the answer here so based on the states you have their respective revenues there you go now let’s proceed with the next use case for today’s discussion which is about using the conditional statement like case using case query or clause for custom calculations we’ll perform some customized calculations now let’s say we wanted to find out a product which is uh giving Revenue greater than 10,000 as high Revenue let’s say we have revenues in terms of thousands of dollars and let’s have a benchmark like $10,000 and $10,000 is the minimum Revenue you wanted to extract out of that product and if it is not yielding at least 10,000 for your dealership then that product is not selling much so that you can at least make some space in your dealership so that you can import some products which are giving you highest uh Revenue right so we want to find out those uh products which are giving us revenue between 5,000 to 10,000 as medium revenue and less than 5,000 as low revenue and greater than 10,000 as high Revenue you understood the game right so we have three segments High Revenue medium okay okay type of Revenue Vue and least Revenue product so that you can eliminate the least Revenue products out of your inventory now we want order ID so copy the order ID from here and paste it here so we are looking for order ID and we are also looking for product so uh we don’t want some much revenue here let’s eliminate this one and instead of that let’s add product from we’ll extract this from okay before from uh this this form from statement will be at the last here we will begin with a use case right let’s type case now when a specific product or Revenue okay let’s revenue is greater than $10,000 then let’s not use sentence case let’s use keywords and caps then mention it as high or high Revenue let’s copy paste the same code here when revenue is between between 5,000 and we will be using an and operator here then term it as okay we don’t want alter average revenue or medium revenue and copy paste the same here we remove the alter and revenue is less than okay I think we don’t want to use this instead of this we can just place else right so we will place else it should be termed as low revenue or least let’s go with low Revenue there you go and now from which table you want to extract that I want to extract all this data from customer table so everything will go off apart from that now let’s execute this particular code let’s see if we get any errors incorrect Syntax for case I think we made some mistake here okay we forgot the comma here should have mentioned a comma and yeah so the thing is we by mistake chose the alter from suggestions alter keyword from suggestions so far we missed a comma and Al from suggestions I think it’s everything good to go let’s try to execute and if it faces some issues no problem we’ll try to resolve it in a different way so incorrect we missed to write the end okay we did not end the case okay okay fine fine not a problem end as okay uh let’s term it as uh the entire uh table as Revenue category since we are uh splitting into three categories Revenue categories there you go so this is the way to learn make some mistakes that uh you can learn in a better way for the next time you’ll never make a mistake so far so good so we have all the car models categorized into the uh revenue revenue categories High Revenue low Revenue so far we have all the cars in high Revenue not a bad deal I think all the cards are performing really well maybe if you change the numbers a little bit maybe if we take up one lakh in place of 10,000 then maybe we can get a couple of costs but so far so good this is how the query works now let’s uh switch to our next query next use case where we will be combining data from multiple tables using joh we already did that but still for the sake of uh learning experience we will also perform that particular operation so we will be naming this particular use case as combine data from multiple tables using a join so far you have already have a good experience on how joins work but still we will try to do that now we will use customer table here customer table. order ID and uh we want customer table do product and customer. Revenue and uh let’s also say take some data from dealership so we already know that some data of states is in dealership so we’ll also take the dealership data so uh dealership dot State also take the region dealership. region from customer table let’s eliminate the case statement from customer and we want to join let’s push this to the first line so that we don’t have confusion how and where the query is going on so here I want to join so the second line is all about join dealership so let’s copy this we we are combining dealership with customer on order ID in the same way we will take order ID equals to order ID now which order ID is equals to which order ID the first table customer. order ID is equals to the second table dealership order ID so that SQL Server understands which columns from which tables are being joined here for what reason right so far so good we have uh given the columns that we want to have in our output which are these columns and we are joining two tables based on certain criteria but now maybe we can specifically me mention some more data let’s say we already mentioned some uh query where we wanted data for a specific region let’s try to continue that where region is equals to West there you go let’s close the single code or double code now what happens is it is trying to give us the details of customer order ID product Revenue state region from customer table and we’re going to also execute or extract the details of state and region from the dealership table and we’re trying to join to extract those data with dealership data and we are specifically extracting the data where the region is West let’s execute the data don’t worry if we find any errors in this particular code there you go we have the result so we have all the details from the west region there you go let me expand this so that we have a better view anyways it’s okay now let’s go with the sixth quarium for today’s session where we will be executing a query based on having close in SQL server and we will try to filter out some states only show the states where total revenue is greater than 50,000 just like we discussed before we initially used a case statement with $110,000 at least Revenue but now let’s increase the number to 50,000 and we want those states which are giving us minimum 50,000 Revenue so let’s uh rename the use is here we will try to name it as filter data or groups with having with having Clause okay so we want uh State we have state here and let’s also count as total orders so order ID so customer. order ID will be now count of total orders so the count will be the aggregation function here count total order IDs and we can name it as total orders and uh do we have Revenue yes we have revenue and let’s also remove the product I don’t think we might need a product here and the aggregation will be some aggregation has sum of Revenue and I don’t think we need to specifically mention it here but anyways we’ll keep State first copy State and drop it here we want State count of orders as orders and sum Revenue as total revenue what this does is it’ll give a Clarity right so instead of uh if I don’t alos it what it shows is sum of Revenue and for a generic person it might not be as helpful as a data engineer can right for a data engineer data analyst he can totally understand by just reading the agregation function so we counting the orders here we are getting the sum of Revenue but for a mere person who just wants to see the report the business guy who just wants to see the report for him total orders or uh total revenue is a simplest language that he can understand correct now we are extracting this data from customer and uh we will join dealership again okay because we also want to extract the state right so we did not mention the state here but we can mention the state anyway okay we did mention the state so we since we have the state column for extracting State details will anyway go for the dealership so we are already joined dealership data with customer data and let’s do a group by function here Group by region Group by state actually and now the condition having some of Revenue at least or greater than 50,000 so we will go with the having Clause here and sum of Revenue or you can also use the aliah’s name total revenue greater than $50,000 so let’s execute this query and see if the alas works or not okay I think alas will not work here in case of alas let’s go with the ACT ual term and place it over here and now let’s try to execute this if it works or not okay we mentioned two things here region and the state so we just wanted State there not region I think this should solve the issue 20 rows affected ambiguous column order ID now we will let’s say take customer name and place it here or I think the dealership would be the best because we have the details of orders here no no no customer table has the order details so let’s keep it that way there you go so we have uh so many number of states which have Revenue greater than 50,000 so these are the outputs there you go now let’s proceed with the next query where we will be using the range function which is also known as the between function in SQL Server so let’s name the comment as using the range function let’s not uh capitalize it using the range function named between so between is the keyword right now let’s build a use case let’s identify couple of uh States we will use the same query will not make some major differences here so we we want to identify a couple of States whose revenue is greater than 50,000 but less than one L right this makes a good use case for that for that implementation of bit function we will keep all the uh columns as they are and maybe we can also include a couple of columns maybe product as well and uh we will join two tables now I think we don’t need a group by here but in place of group by and in place of having we will specify where some so to use where Clause I mean to use between Clause having is not the right keyword where is the right keyword so Su of Revenue should be in place of the symbol between you take the suggestions and one lakh yeah this is 1 2 3 4 5 zeros so this is is the right way now let’s try to execute if it works or not if there is some error yeah there is some error an aggregate may not appear where Clause unless it is subsidary okay contain having claes select I think this is the place where we can go with the alas name let’s try that or if areas does not work then we will go with a revenue okay let’s simplify this let’s not go with the join statement here let’s eliminate the join we shall just simplify we don’t want State uh we won’t okay let’s not count this there was no need for counting I think that was one error we will go with order ID I to L we don’t want this and anyways we want to take a look at the the product and dealership name as well and we also want revenue from customer table where revenue is between these numbers let’s try to simplify and run this query think it should work yeah it worked so these are the uh dealerships and products which yield in revenue between 50,000 to 1 lakh right so this is the best way to use it so we had some extra aggregate functions which complicated the query no no problem now let’s go with some pattern matching sometimes uh let’s say we are looking for sales from California something like that or we are looking for some car model correct and we don’t know the full name or we might have a spelling mistake right uh we have California here but let’s say we don’t know the spelling of California but we know the first three or four letters of California right so in those instance what you can do is try to match the pattern that we have in our hand with the pattern which is available in the data table and wherever it finds a match it extracts those rows so this is how the pattern matching works now let’s execute a query for a better understanding let’s keep the same query use okay let’s change uh the use case here using the pattern matching in SQL Server so we will have order ID as it is dealership name as it is and product as it is from customer table where product so let’s copy this and paste it here like or I like I like is uh the opposite so let’s go with like car model let’s check with the car models first so all car models are the same so me maybe if uh we go with the fuel type I think fuel type will help because all the card models have the keyword card model and only thing is an alphabet M Etc so it doesn’t make sense for us to execute bit uh the like operator here so instead of product let’s keep fuel type like hybrid correct let’s go with the hybrid one so we will take only the first four letters let’s imagine we don’t know the full spelling of hybrid so if the M pattern is like and since it’s a text we will use uh single quotes or double quotes if the pattern H hybr matches with the elements or the column present in the customer data it will pull all those uh columns or rules now let’s execute this so there you go okay we one important thing we missed to include the percentage this percentage symbol will make SQL Server understand that the text should have hybr and after that anything is accepted so anything which has a beginning with hybr should be pulled out right now let’s execute once again and see the data there you go you have it correct so remember the symbol percentage right and in case if you did didn’t knew uh the hybrid let’s say it has some ybr in its format right it’s it has some vbr in the format anything before vbr is okay anything after vbr is okay again it will yield the same result hybrid there you go and in case if you wanted to change let’s write the name of petrol I don’t know the spelling of petrol so let’s say p e d so let’s imagine I don’t know the name of petrol so instead of petrol I’m writing eliminating p and I’m writing p e t r and anything after that now let’s run this query and see the output there you go so we have all the vehicles which are of fuel type petrol so this is how you can use pattern matching in SEL server now let’s perform some calculations with dates right so we’ll perform some date and time calculations let’s rename the comment as state and time functions and time and some mathematical math Cals now let’s say you are the owner of dealership and uh let’s say for a specific car you are losing customers initially it was using uh initially it used to perform very good like many customers used to come for that specific car and right now that specific car is receiving less orders and you order to find out what is the reason behind it and after a General survey you come to know that the number of days you took to deliver that car is growing let’s say earlier you used to deliver that car in 2 days but right now you’re taking like two months to deliver that car right so that might be the reason but you wanted to make sure that you have a solid proof that you have the number of days that you’re looking at to show your sales team why is so many number of dayses being taken to deliver a card now for that let’s go with select order ID order date you want order date for it now you can simply copy the order date here and paste it there and you also want the delivery date and copy that and paste it that remember these date and Order date and delivery date are of date data type and now you want to calculate the difference so for that you use a function called Date diff or date diff so the the you know there’s there’s two ways of calling it so if you prefer calling it as date right diff or a you call it as dated if okay so there’s two ways of calling that function so I prefer to call date diff because date difference so date diff comma sorry uh Open Bracket so we want to provide some details here so I want to provide a day I want to count the days right so I want to count of days I’m mentioning day and Order date difference between the order date and the delivery date you can specify that using a comma so I want the difference between these two in case if you want to Alas it you can also do that days to deliver from customer and we don’t want this simply place a semicolon there and now just copy this and execute there you go now you have the uh number of days that you or your sales team is taking to deliver the vehicles so and on an average you’re taking about 10 days to deliver now you can prove this to your sales team and uh let them know this is not good you want to have at least minimum 4 to 5 days or 2 to 3 days to deliver a vehicle if this goes on the say might drop and it might be a little problematic right now let’s proceed with the next use case of today’s session about the temporary tables now why temporary tables so there comes a situation where you have to just run some numbers run some something very uh not too critical but you just wanted to do that so in such scenarios what you can do is you don’t want to harm the original table so what you can do is you can create a temporary table or a copy of that table which is somewhere in the intermediate memory storage and as as soon as you close the studio it fades away and nothing happens to your original data table so that is where the temporary tables come to come into picture now let’s create a simple use case for that particular temporary tables right so we will be selecting order ID and let’s also take product and let’s also take Revenue into temp or yeah it’s enough temp order tables I don’t want that temp order and I don’t want to it and from which table are you taking that I’m taking that from customers you can either choose to keep it in in a new line or you can keep it in the same line but I want to keep it in a new line from customers and where revenue is I said you right you wanted to just explore a few things which is not too mandatory uh but you just want to take a look at it that’s why you take the option of creating U temporary tables and I want to find out which are those uh products which are giving us Revenue greater than 1 to 3 4 five1 lakh dollar right now let’s run this it’s run it’s done but we don’t know where it is so what you can do is you just write up simple select query select stock from your temporary table close the query and run it there you go so far there are no such uh products which are giving us greater than one lakh sales of that single product in valid object name temp order okay there might be some error about this particular query let’s try to reduce the number did we miss anything where revenue is greater than okay this is a number we don’t want semicolon there okay we missed a semicolon here let’s run this execute let’s keep it as 10,000 okay okay so there was no certain product which was above one lakh that was a problem okay so these are the products which are giving us U 10,000 sales at least not a problem now let’s proceed with the next uh important part of today’s session which is about the Common Table Expressions so Remember Common Table expressions are also known as CTE play a very major role in realtime data analytics right so uh let’s have a sample of that let’s create a Common Table expression which is rather simple and uh just learn how technically it works right so the only difference is the CTE start with a keyword word named as withd and after that you can term your uh comment table as some data so or some name I’ll give it give it as sales data as and open a bracket and inside this bracket is where you write your actual query now let’s organize a few things I don’t want the temp order table here and I don’t want temp order here from okay I I want to extract a few columns I want uh maybe State and I maybe want uh I don’t want order ID I want Revenue maybe revenue is good so let’s sum the revenue and uh term it as total revenue from customer and now let’s proceed with a join command where we will be joining dealership data let’s copy the dealership data table name we will be joining based on the order ID that is common so uh maybe order ID copy the order ID is equals to order ID and which order ID are you talking about I’m talking about uh customers order ID and dealership data order ID so we need to mention that on dealership. order ID and customer. Order ID Group by state good since we took State as well we can use a group by function here and this is not the end of uh everything so semicolon may have to wait so this is the first part now using this particular CTE this entire term is CTE so this particular the output of this particular query will be stored in sales data now we will make use of this CT or sales data turn to extract a few more queries so we will be writing another select statement select state from from okay let’s also take the total revenue which we created here let’s take the same term here so that we don’t make a mistake from the CT which we created very recently which happens to be the sales data where total revenue is crossing something about $50,000 and now is the semicolon let’s try to execute this there you go so a few regions or a few States and total revenue Vue which are exceeding $50,000 are there you go what is post SQL postris SQL is an open-source object relational database management system it stores data in rows with columns as different data attributes according to the DB engines ranking post SQL is currently ranked fourth in popularity amongst hundreds of databases worldwide it allows you to store process and retrieve data safely it was developed by a worldwide team of volunteers now let’s look at the history of post Christ sequel so in 1977 onwards the Ingress project was developed at the University of California Berkeley in 1986 the post Chris project was led by Professor Michael Stonebreaker in 1987 the first demo version was released and in 1994 a SQL interpreter was added to postris the first postris sequel release was known as as version 6.0 or 6.0 on January 29 1997 and since then post SQL has continued to be developed by the post SQL Global Development Group a diverse group of companies and many thousands of individual contributors now let’s look at some of the important features of postest SQL so postest SQL is the world’s most advanced open source database and is free to download it is compatible as it supports multiple operating systems such as Windows Linux and Mac OS it is highly secure robust and reliable postp SQL supports multiple programming interfaces such as C C++ Java and python postp SQL is compatible with various data types it can work with Primitives like integers numeric string and Boolean it supports structured data types such as dat and time array and range it can also work with documents such as Json and XML and finally postris SQL supports multiversion concurrency control or mvcc now with this Theory knowledge let’s look at the post SQL commands that we will be covering in the demo so we will start with the basic commands such as select update and delete we will learn how to filter data using wear clause and having clause in SQL we will also look at how to group data using the group by clause and order the result using the order by Clause you will learn how to deal with null values get an idea about the like operator logical operator such as and and or we will also explore some of the popular inbuilt mathematical and string functions finally we’ll see some of the advanced concepts in postris SQL that is to write case statements subqueries and user defined functions so let’s head over to the demo now okay so let’s now start with our demo so first we’ll connect to post SQL using psql cell so here under type here to search I’ll search for psql you you can see this is the SQL cell I’ll click on open let me maximize this okay so for Server I’ll just click enter database I’ll click enter port number is already taken which is 5432 I’ll hit enter username is already given and now it is going to ask for password so here I’ll give my password so that I can connect to my post SQL database so it has given us a warning but we have successfully connected to postr SQL all right so now to check if everything is fine you can just run a simple command to check the version of post SQL that we have loaded so the command is Select version with two brackets and a semicolon I’ll hit enter okay you can see the version post SQL 13.2 okay now let me show you the command that will help you to display all the databases that are already there so if I hit /l and hit enter it will give me the list of databases that are already there so we have post SQL there’s something called template zero template 1 and we have a test database as well okay now for our demo I’ll create a new database so first I’ll write create space database and I’ll give my database name as as SQL demo I’ll give a semicolon and hit enter you see we have a message here that says create database so we have successfully created our SQL demo database now if you want to connect to that database you can use back SL c space SQL demo there you go it says you are now connected to database SQL demo so here here we can now create tables we can perform insert operation select operation update delete alter and much more now I’ll show you how to connect to post SQL using PG admin so when you install the post SQL database you will get the SQL cell and along with that you also have the PG admin so I’ll just search for PG you can see here it has prompted PG admin I’ll click on open this will open on a web browser you can see it has opened on Chrome and this is how the interface of PG admin looks like it is a very basic interface so on the top you can see the files we have object there’s tools and we have the help section as well and here you have dashboard properties SQL statistics dependencies dependence and here on the left panel you have servers let me just expand this so it will connect to one of the databases all right so if I go back you see when I had run back/ L to display the databases it had shown me post SQL and test now you can see here we have the post SQL database and the test database all right now we also created one more database which was SQL demo so let me show you how to work on this PG admin and the query tool all right so I’ll right click on SQL demo and I’ll select query tool I’ll just show you how to run a few commands on the query tool so let’s say you want to see the version of post SQL that you are using so you can use the same command that we did on psql Cell which is Select version closed with brackets and a semicolon I’ll select this and here you can see we have the execute button so if I hit execute or press F5 it will run that query you can see we have the output at the bottom and it says post SQL 13.2 compiled by visual C++ it has the 64-bit system okay now let me tell you how to perform a few basic operations using post SQL commands so here let’s say I’ll write select five into 3 I’ll give a semicolon select this and hit F5 so this will run the query and it returns me the result that is the product of 5 and three which is 15 similarly let’s edit this let’s say I’ll write 5 + 3 + let’s say six I’ll select this and hit F5 to run it it gives me the sum of 5 + 3 + 6 which is 14 now the same task you can do it on this cell as well let me show you how to do it here so let’s say I’ll write select let’s say I want to multiply 7 into let’s say 10 you know the result it should be 70 if I hit enter it gives me 70 now this question mark column question World we’ll deal with this later all right let me go back to my PG admin again let me do one more operation let’s say this time I’ll write select 5 multiplied by and within brackets I’ll write 3 + 4 I’ll give a semicolon so what SQL will do is first it will evaluate the expression that is there inside the bracket that is 3 + 4 which is 7 and then it will multiply 7 with 5 now let me select this and I’ll hit execute so you can see 7 * 5 is 35 all right now we’ll go back to our shell and here I’ll show you how to create a table so we are going to create a table called movies on the cell that is psql cell so here we will learn how you you can create a table and then you can enter a few data into that table all right let me just scroll down a bit okay so my create command goes something like this so I’ll write create table followed by the table name that is movies next my movies table will have a few columns let’s say I want the movie ID after the column name we need to give the data type so movie ID I’ll keep it as integer so integer is one of the data types that is provided by post SQL next my second column the table would be the name of the movie so I’ll write moviecore name so all the variables or the column name should be as per SQL standards so there shouldn’t be any space between the column name so I have used underscore to make it more readable so my movie name will be of type varar or variable character or varing character and I’ll give the size as 40 so that it can hold 40 characters maximum next my third column will have the genre of the movie so I’ll write moviecore Jer again joner is of type barar I’ll give the size as let’s say 30 and my final and the last column we’ll have the IMDB ratings so I’ll write IMDb underscore ratings now the ratings will be of type real since it can have floating or decimal point values if I close the bracket I’ll give a semicolon and I’ll hit enter there you go so we have successfully created a table called movies now let me go back to my PG admin all right so here I have my database that is SQL demo I’ll just right click on this and click on refresh now let me go to schemas I’ll just scroll down a bit here under schemas we have something called as tables let me expand this okay so you can see we have a table called movies in the SQL demo database now and here you can check the columns that we have just added so our movies table has movie ID movie name Jor and ratings all right now there is another way to create a table the previous time we created using the SQL cell now I’ll tell you how to create a table using the PG admin so here under tables I’ll right click and I have the option to create a table so I’ll select table okay so it’s asking me to give the name of the table so this time we are going to create a table called students so I’ll write my table name as students all right these will be default as it is now I’ll go to the columns tab so here you can create the number of columns that you want so you can see on the right I have a plus sign I’ll just select this so that I can add a new row so my first column would be let’s say the student role number I’ll write student uncore RO number again the column name should be as per SQL standards the data type I’m going to select is integer all right now if you want you can give these constraints such as not null so that student role number column will not have any null values and I’ll also check primary key which means all the values will be unique for role numbers all right if you want to add another column you can just click on that plus sign and let’s say this time I want to give the student name as my second column so I’ll write student underscore name student name will be of type let’s say character wearing if you want to give the length you can specify the length as well let’s say 40 I’ll click on the plus sign again to add my final column the final colum would be gender so gender I’ll keep this time as type character okay now you can click on save so that will successfully create your students table there you go so here on the left panel you can see earlier we had only one table that was movies and now we have two tables so one would be added that was students so if I expand this under columns you can see we have the three columns here student rule number student name and gender you can also check the constraints it will tell you if you have any constraints so you can see it says students rule number there’s one primary key all right all right now let me run a select statement to show The Columns that we have in the movies table so I’ll write select star from movies give a semicolon and let me execute this okay so here on the at the bottom you can see we have the movie ID the movie name movie JRE and IMDb readings now the next command we are going to learn is how to delete a table so there is one way by using the SQL command that is drop table followed by the table name let’s say you want to delete students you can write drop table students and that will delete the table from the database this is one of the methods so you just select and run it now the other way is to you just right click on the table name and here you have delete slash drop if I select this you get a prompt are you sure you want to drop table students I’ll select yes so you can see we have successfully deleted our students table all right now let’s perform a few operations and learn a few more commands in post SQL so to do that I’m going to insert a few records to my movies table so for that I’ll use my insert command so I have my insert query written on a notepad I’ll just copy this and I’ll paste it on my query editor okay so let me just scroll down all right so here you can see I have used my insert command so I have written insert into the name of the table that is movies and we have the movie ID the movie name movie Jer and IMDb readings and these are the records or the rows so we have the first record as movie ID 101 the name of the movie is a very popular movie which is vertigo then we have the movie genre that is Mystery it is also a romance movie and then we have the IMDb readings the current IMDb readings that is 8. three similarly we have sank Redemption we have 12 Angry Men there’s the Matrix 7 inter staler and The Lion King so there are total eight records that we are going to insert into our movies table so let me just select this and hit execute okay you can see it has returned successfully eight records now if I run select star from movies you can see the records that are present in the table so I’ll write select star from movies I’ll select this and I’ll execute it there you go at the bottom you can see eight rows affected if I scroll this down you have the eight records of information in the movies table all right now if you want to describe the table you can go to the SQL cell and here if you write back SL D and the name of the table that is movies this will describe the table so here you have the column names this has the data type and here you can specify if there are any null values or any constraints like default constant or primary key or foreign key and others let me go back to my PG admin okay now first and foremost let me tell you how to update records in a table so suppose you have an existing table and by mistake you have entered some wrong values and you want to update those records later you can use the update query for that so I’m going to update my movies table and I’ll set the genre of movie ID 103 which is 12 Angry Men from drama to drama and crime so in our current Table we only have Jon as drama for 12 Angry Men I’m going to update this column which is the movie genre to drama and crime okay so let me show you how to do it I’ll write update followed by the name of the table that is movies go to the next line I’ll write set then I’ll give the column name which is moviecore Jer equal to I’m going to set it as drama comma crime earlier it was only drama and I’ll give my condition using the wear Clause we’ll learn where clause in a bit so I’ll write where moviecore ID is equal to 103 so here our movie ID is the unique identifier so it will first look for movie ID 103 it will locate that movie and it change the genre to drama and crime so now you can see the difference earlier we had 12 Angry Men as drama as the movie genre now if I run this update statement okay you can see we have successfully updated one record now let me run the select statement again okay so here you can see if I scroll down there you go so movie ID 103 movie name 12 Angry Men we have successfully updated the genre as drama comma crime okay now let me tell you how you can delete records from a table so for that you can use the delete command so you’ll write delete from the table name that is movies where let’s say I want to delete the movie ID 108 which is The Lion King so I’ll write where moviecore ID is equal to 108 this is one of the ways to delete this particular movie or you can give let’s say where movie name is equal to The Lion King let me select this and I’ll hit execute now if I run my select query again you see this time it has returned seven rows and and you cannot find movie with movie ID 108 that was The Lion King so we have deleted it all right next we are going to learn about we clause in post SQL so to learn we Clause I’ll be using the same movie table again let’s say we want to filter only

    those records for which the IMDB ratings of the movies is greater than 8.7 so this is my updated table now I want to display only those records or those movies whose IMDB ratings is greater than 8.7 so we’ll display 12 angry man which is 9 then we are going to display The Dark Knight which is again 9 and we are also going to display the sank Redemption which has 9.3 the rest of the movies have and IM to be rating less than 8.7 so we are not going to display those all right right so let me show you how to write a wear Clause so I’ll write select star from movies where I’ll give my column name that is IMDB ratings is greater than I’ll use the greater than symbol then I’ll pass my value that is 8.7 I’ll give a semicolon and let’s run it I’ll hit F5 there you go so we have returned the sashank Redemption The Dark Knight and 12 Angry Men because only these movies had IMDB ratings greater than 8.7 okay now let’s say you want to return only those movies which have IMDB ratings between 8.5 and 9 so for that I’m going to use another operator called between along with the wear Clause so let me show you how to use between with wear clause I’ll write select star from movies where my IMDb underscore ratings is between I’ll write 8.5 I’ll give an and operator and 9.0 so all the movies that are between 8.5 and 9.0 ratings will be displayed so let’s select this and I’ll run it there you go so we have returned the Dark Knight The Matrix the seven interal and we have the 12 Angry Men so a few of the records that we missed out where I think vertigo which has 8.3 and there’s one more all right now moving ahead let’s say you want to display the movies whose movie genner is action you can see in a table we have a few movies whose genre is action movie so you can do that as well I’ll write select star from movies where the movie genre I’m writing this time in one line you can break it into two lines as well I’ll write moviecore Jer which is my column name equal to I’ll give within single quotes action now why single code because action is a string hence we need to put it in single codes if I run this there you go so we had one movie in our table whose movie genre was action that is The Dark Knight okay now you can also select particular columns from the table by specifying the column names now here in all the examples that we saw just now we are using star now star represents it will select all the columns in the table if you want to select specific columns in the table you can use the column names so you can specify the column names in the select statement let me show you let’s say you want to display the movie name and the movie genre from the table so you can write select moviecore name Comm I’ll give the next column as moviecore Jer from my table name that is movies where let’s say the IMDB uncore ratings is less than 9.0 so this time in our result it will only show two columns that is movie name and movie JRE let me run it there you go so these are the movie names and the movie genners you can see that have an IMDB ratings less than 9.0 all right like how you sh the between operator there is one more operator that you can use with the we Clause that is the in operator so the in operator works like a r clause or an or operator so let’s say I want to select all the columns from my movies table where the IMDB ratings is in 8.7 or 9.0 if I run this it will display only those records whose IMDB ratings is 8.7 or 9.0 all right so up to now we have looked at how you can work on basic operations in SQL like your mathematical operations you saw how a select statement works we created a few tables then we inserted a few records to our tables we saw how you can delete a table from your database and we have performed a few operations like update delete and we saw how a wear Clause works now it’s time to load a employee CSV file or a CSV data set to post SQL so I’ll tell you how you can do that but first of all before loading or inserting the records we need to create an employee table so let me first go ahead and create a new table called employees in our SQL demo database so I’ll write create table my name of the table would be employees next I’m going to give my column names so my first column would be employee ID so the employee ID will be of type integer it is not going to contain any null values so I’ll write not null and I’ll give my constraint as primary key so the employee ID as you know is unique for all the employees in a company so once I write primary key will ensure that there are no repetition in the employee IDs okay next I’ll have my employee name so my employee name is going to be of type varar and I’ll give my size as 40 okay next we’ll have the email address of the employee again email address would be of type varar and the size is 40 again I’ll give another comma this time we’ll have the gender of the employee gender is again worker of size let’s say 10 okay now let’s include a few more columns we’ll have the department column so I’ll write Department varar let’s say the size is 40 then let’s say we’ll have an another column that is called address so the address column will have the country names of the employees address is also VAR car and finally we have the salary of the employee salary I’m going to keep it as type real so real will ensure it will have decimal or floating Point values okay so now let me select this create table statement and execute it all right so we have successfully created our table if you want you can check by using select star from employees let me select this and I’ll hit execute all right you can see we have our employee ID as primary key there’s employee name email gender this department address and salary but we don’t have any records for each of these columns now it’s time for us to insert a few records to our employees table now to do that I’m going to use a CSV file so let me show you how the CSV file looks like okay so now I am on my Microsoft Excel sheet and on the top you can see this is my employe data. CSV file here we have the employee ID the employee name email gender this department address and salary now this data was generated using a simulator so this is not validated and you can see it has a few missing values so under email column we have a few employees who don’t have an email ID then you can see under Department also there are some missing values here as well all right so we’ll be importing this table or the records present in this CSV file onto postr SQL all right so here in the left panel under tables let me right click and first refresh this there you go so initially we had only movies table and now we also have the employees table now what we need to do is I’ll right click again and here you see we have the option to import or export let me click on this and I don’t want to export I need to import so I’ll switch on import all right now it is asking me to give the file location so let me show you how to get the file location so this is my file location actually so my Excel file which was this is present in my e Drive under the data analytics folder I have another folder called post SQL and within the postc SQL folder I have my CSV file that is employee data. CSV so I’ll just select this you can either do it like this or you can browse and do okay now my format is CSP next I’m going to select my headers as yes and then let me go to columns and check if everything is fine all right so I have all my columns here let’s click on okay you can see I have a message here which says import undor export all right so here you can see successfully completed we can verify this by using select star from employees again if I run this all right let me close this there you go it says 150 rows affected which means we have inserted 150 rows of information to our employees table you can see we have the employee ID these are all unique we have the employee name the email we have the address and the salary let me scroll down so that okay you can see we have 150 rows of information that means means we have 150 employees in our table okay now we are going to use this employees table and explore some Advanced SQL commands now there is an operator called distinct so say if I write select address from employees this is going to give me 150 address of all the employees there’s some problem here I did a spelling mistake there should be another D if I run this again AL query will return 150 rows you can see we have the different country names under address that is Russia we have France the United States we have Germany okay and I think we have Israel as well yeah now suppose you want to display only the unique address or the country names you can use the distinct keyword before the column name so if I write select distinct address from employee it will only display the unique country names present in the address column if I run this see it has returned us six rows of information so we have Israel Russia Australia United States France and Germany all right now as I said there are a few null values which don’t have any information so you can use the isnull operator in SQL to display all the null values that are there suppose I want to display all the employee names where the email ID has a null value so I’ll write select star from employees where email is null so this is another way to use your wear Clause if I select and run this there you go so you see here for all these employee names there was no email ID present in the table so it has written us 16 rows of information so around 10% of employees do not have an email ID and if you see a few of them do not have an email ID and also they don’t have a department so if you want to know for those employees which do not have a department you can just replace where department is null instead of where email is null now if I select this okay it has written us nine rows of information which means around 5% of employees do not have a department moving ahead now let me show you how the order by Clause Works in SQL now the order buy is used to order your result in a particular format let’s say in a sending or descending order so the way to use is let’s say I want to select all the employees from my table so I’ll write select star from employees order by I want to order the employees based on their salary so I’ll write order by salary let me select and run it okay there is some problem I made a spelling mistake this should be employees let me run it again okay now if you mark the output a result has been ordered in ascending order so all the employees which have salary greater than $445,000 appear at the top and the employees with the highest salaries appear at the bottom so this has been ordered in ascending order which means your SQL or post SQL orders it in ascending order by default now let’s say you want to display the salaries in descending order so that all the top ranking employees in terms of salary appear at the top so you can use the dec keyword which means desending if I run this you can see the difference now so all the employees with the highest salary appear at the top while those with the lowest salaries appear at the bottom so this is how you can use an order by Clause okay so now I want to make a change in my existing table so here if you see under the address column we only have the country names so it would be better if we change the name of the address column to Country so I want to rename a column you can do this using the alter command in post SQL so let me show you how to rename this column that is address so I’ll write alter table followed by the table name which is employees then I’m going to use rename column address I’ll write two I want to change it to Country if I give a semicolon and hit execute it will change my column name to Country now you can verify this if I run the select statement again there you go earlier it was address column and now we have successfully changed it to Country column okay let me come down now it’s time for us to explore a few more commands so so this time I’m going to tell you how an and and an or operator Works in SQL so you can use the and and or operator along with the wear Clause so let’s say I want to select the employees who are from France and their salary is less than $80,000 so let me show you how to do it I’ll write select star from employees where I’m going to give two conditions so I’ll use the and clause or the and operator here I’ll write where country is equal to France now Mark here I’m not using address because we just updated our table and changed the column name from address to Country so I’ll write country equal to France and by next condition would be my salary needs to be less than $80,000 I’ll give a semicolon let me run this all right so it has returned 19 rows of information you can see all my country names are France and the salary is less than $80,000 so this is how you can use or give multiple conditions in a we Clause using the and operator now let’s say you want to use the or operator and let’s say you want to know the employees who are from country Germany or the department should be sales so I’ll write select star from employees where country is equal to Germany and instead of and I’m going to use or their depart M should be sales okay now let’s see the output I’ll hit F5 this time to run it all right so we have 23 row of information now let me scroll to the right you can see either the country is Germany or the department is sales you see one of them in the table so here for the first record the country was Germany the second record the department was sales again sales again for the fourth record the country is Germany so this is how the or condition works so if one of the conditions are true it will return the result it need not be that both the conditions should satisfy now in post SQL there is another feature that is called limit so post SQL limit is an optional clause on the select statement now this is used as a con ST which will restrict the number of rows written by the query suppose you want to display the top five rows in a table you can use the limit operator suppose you want to skip the first five rows of information and then you want to display the next five you can do that using limit and offset so let’s explore how limit and offset works I’ll write select star from employees let’s say I’ll use my order by Clause I’ll write order by salary let’s say in descending and limit it to five this is going to display the top five employees which have the highest salary if I run this there you go you see it has given us five rows of information and these are are the top five employees that have the highest salary okay so this is one method of or one way of using the limit Clause now in case you want to skip a number of rows before returning the result you can use offset Clause placed before the limit Clause so I’ll write select star from employees let’s say order by salary descending this time I’m going to use limit five and offset three so what this query will do is it will skip the first three rows and then it will print the next five rows if I run this there you go so this is how the result looks like okay now there is another class which is called Fetch let me show you how that works I’ll copy my previous SQL query I’ll paste it here and here after descending I’m going to write fetch first three row only so my fetch is going to give me the first three rows from the top there you go it has given us the first three rows and you can see the top three employees that have the highest salary since we ordered it in descending order of salary all right you can also use the offset along with the fetch Clause I’ll copy this again and let me paste it here now after descending I’m going to write offset let’s say three rows and fetch first five rows only so what this SQL query is going to do is it will skip the first three rows of information and then it is going to display the next five rows it is going to work exactly the same as we saw for this query let me run it there you go so these are the first five rows of information after excluding the top three rows all right we have another operator that is called as like in post SQL so like is used to do pattern matching so suppose you have a table that has the employee names you forgot the full name of an employee but you remember the few initials so you can use the like operator to get an idea as to which employee name it is now let’s explore some examples to learn how the like operator Works in post SQL so suppose you want to know the employees whose name starts with a so for that you can use the like operator let me show you how to do it so I want to display the employee name and let’s say I want to know their email IDs from the table name that is employee where since I want to know the employees whose name starts with a so I’ll write employee name like now to use the pattern is within single course I’ll write a and Then followed by percentage now this means the employee name should have an e in the beginning and percentage suggest it can have any other letter following a but in the beginning or the starting should be a if I run this so there is an error here the name of the table is employees and not employee let’s run this again there you go you can see there are 16 employees in our table whose name starts with a you can see this column employee name all of them have a letter A in the beginning okay now let me just copy this command or the query I’ll paste it here let’s say this time you want to know the employees whose name starts with s so instead of a I’ll write s so this means the starting letter should be S and followed by it can have any other letter if I run this so there are 10 employees in the table whose name starts with s okay let’s copy the query again and this time I want to know the employees whose name ends with d now the way to do it is instead of a percentage I’ll write this time percentage D which means at the beginning it can have any letter but the last letter in the string or in the name should be ending with d now let me copy and run this so there are 13 employees in the table whose name ends with a d you can see it here all right now let’s say you want to find the employees whose name contains ish or have ish in their names so the way to do is something like this so I’ll copy this now here instead of a percentage I’ll replace this with percentage ish percentage now this means that in the beginning it can have any letter and towards the end also it can have any letter but this is message should appear within the name let me run and show it to you okay so there is one employee whose name contains ish you can see here there is an ish in the last name of the employee all right now suppose you want to find the employee name which has U as the second letter it can have any letter in the beginning but the second letter of the employee name should have U now the way to do is I’ll copy this and instead of a% I’ll write underscore U followed by percent now this underscore you can think of a blank that can take any one letter so the beginning can start with a B C D or any of the 26 alphabets we have then then it should contain you as the second letter followed by any other letter or letters let me run this okay so there are 10 employees in the table whose name has a u as the second letter you can see these okay now moving ahead let me show you how you can use basic SQL functions or inbuild functions so we’ll explore a few mathematical functions now so let’s say you want to find the total sum of salary for all the employees so for that you can use this sum function that is available in SQL so I’ll write sum and inside the sum function I’ll give my colum name that is salary from my table name that is employees let’s see the result this will return one unique value there you go now this is the total salary since the value is very large it has given in terms of E now one thing to note here is if you see the output the column says sum real so this output column is not really readable so SQL has a method which can fix this that is called an alas so since we are doing an operation of summing the salary column we can give an alas to this operation by using the as keyword so if I write sum of salary as let’s say total salary then this becomes my output column you can see the difference if I run this okay you can see now in the output we have the total salary now this is much more readable than the previous one so this is a feature in Excel where you can use or give alas names to your columns or your results now similarly let’s say you want to find the average of salary for all the employees now SQL has a function called AVG which calculates the mean or the average salary if I write AVG and I can edit my alas name as well let’s see I’ll write mean salary let’s run it you can see the average salary for all the employees it’s around $81,000 okay now there are two more important functions that SQL provides us which is Max and minimum so if I write select maximum or Max which is the function name of salary as let’s say instead of total I’ll write maximum so this will return me the maximum salary of the employee let’s run it and see what is the maximum salary that is present in the salary column all right so we have 9,616 as highest salary of one of the employees similarly you can use the minan function as well I’ll just write minimum and this will return me the minimum salary of one of the employees in the table I’ll replace the alas name as minimum okay now run it this will give me the minimum salary that is present in our table so it is $ 4,685 okay now let’s say you want to find the count of Department in the employees table you can use the count function so if I write select count let’s say I want to know the distinct Department names so I can write inside the count function distinct Department as total departments from employees let’s run this this will return me the total number of departments that are there so it gives me there are departments okay now let me show you one more thing here if I write select Department from employees let’s run this okay so it has returned me 150 rows of information but what I’m going to do is I’ll place my distinct keyword here just before the call name so that I can verify how many departments are there in total there you go so there are 13 departments and one of them is null so moving ahead we’ll replace this null with a department Name by updating a table okay so now let’s update our department column so what we are going to do is wherever the department has a null value we are going to assign a new Department called analytics so earlier we have also learned how to use the update command so I’m going to show it again so we’ll write update followed by the table name that is employees I’m going to set my column that is Department equal to within single codes my name of the department would be Analytics where department is I’ll say null so wherever the department has a null value we’ll replace those information with Department that is analytics let’s run this you can see query returned successfully now let’s say I’ll run this command again and this time you can see the difference there you go so we have 13 rows of information and there is no null department now we have added a new department that is analytics okay now we are going to explore two more crucial commands or Clauses in SQL that is Group by and having so let’s learn how Group by Clause Works in post SQL so the group by statement groups rows that have the same values into summary rules for example you can find the average salary of employees in each country or city or department so the group by Clause is used in collaboration with the select statement to arrange identical data into groups so suppose you want to find the average salary of the employees based on countries you can use the group by Clause so let me show you how to do it I’ll write select I want the countries and the average salary for each country so I’ll use the average function that is AVG and inside the function I’ll pass my column that is salary I’ll give an alas name as let’s say average uncore salary from my table name that is employees next I’m going to use my group by Clause so I’ll write Group by since I want to find the average salary for each country so I’ll write Group by country name let’s give a semicolon and let me run it I’ll use F5 there you go so here on the left you can see the country names we have Israel Russia Australia United States France and Germany and on the right the second column you can see the average salary for each of these countries now you can also order the result in whichever way you want suppose you want to arrange the results based on the average salary so you can use the order by Clause after the group by Clause so I’ll write order by here you can use the alas name that is average salary this is actually average uncore salary and let’s say I want to arrange it in descending order so I’ll write DSC now let’s run this you can mark the difference in the average salary column there you go so as per our result in United States the average salary is the highest and if I scroll down the average salary is the lowest in Germany now let’s see one more example using group buy suppose this time you want to find the maximum salary of male and female employees you can do that too so let me show you how to do it so I’ll write select this time we want to find the max salary based on gender so I’ll select my gender column comma and this time I’ll use my Max function since I want to find the maximum salary for male and female employees I’ll give an alas name as maximum underscore salary from my table that is employees Group by I’ll write gender okay so let’s run this there you go you can see so one of the female employees had a highest salary of $11 19,618 while of that of a me was $ 17,6 54 all right now suppose you want to find the count of employees based on each country you can use the count function along with the group by Clause so so I’ll write the select statement select since I want to count the employees based on each country so I’ll first select my country column and then I’m going to use the count function I’ll write count empore ID from my table name that is employees I’m going to group it by country so this query will give me the total number of employees from each country you can see here Israel there are four employees in Australia there are four employees in Russia we have 80 employees in France there were 31 in United States we have 27 so on and so forth let me scroll down okay now it’s time to explore one more Clause a very important Clause that is used in post SQL that is having so the having Clause works like the wear Clause the difference is that wear Clause cannot be used with aggregate functions the having Clause is used with a group by Clause to return those rows that meet a condition so suppose you want to find the countries in which the average salary is greater than $80,000 so you can use the group by clause and the having Clause to get the result so I’ll write my select statement as select country comma I want the average salary so I’ll write AVG of salary I can give an alas name as average salary from employees now I’m going to group it by each country so Group by country column since I want to find the countries in which the average salary is greater than 80,000 so I’ll use having Clause after the group by Clause I’ll write having average of salary is greater than 880,000 now this condition cannot be specified in the wear Clause so we need a having Clause you cannot use aggregate functions along with wear Clause let me just run it now there you go so we have Russia and United States where the average salary is greater than $80,000 all right now let’s say you want to find the count of employees in each country where there are less than 30 employees so for this I’m going to use the account function first let me select the country column then I’m going to use the count function and in the count function I’m going to pass my employee ID so that we can count the number of employees from my table that is employees now if you want you can use an alas name for this as well but I’m just skipping it for the time being I’ll write Group by country next I’ll write having count of employee ID less than 30 so this will return me the countries in which there are less than 30 employees let’s run it you can see here Israel Australia United States and Germany are the countries in which there are less than 30 employees okay now if you want you can use the order by Clause as well so suppose I’ll write here order by count of employee ID so what this will do is it will arrange my result in ascending order of employee ID count there you can see we have successfully arranged our result in ascending order of employee IDs okay next we are going to explore one more feature of post SQL that is of using a case statement now in post SQL the case expression is same as IFL statement in any other programming language it allows you to add ifls logic to the query to form a powerful query now let me just scroll down and I’ll show you how to use a case statement this is very similar to your eel statement that you use on Excel in C++ in Python and or any other programming language so what I’m going to do is I’m going to write a SQL query that will create a new column and the name of the column would be let’s say salary range so I’m going to divide my salary suppose if the salary is greater than $45,000 and if it’s less than $55,000 in the new column that is salary range we are going to assign a value low salary now if the salary is greater than $55,000 and if it is less than $80,000 we are going to assign a value that is medium salary if the salary is greater than $80,000 we’ll assign a value High salary so all this we are going to do using our case expression in post SQL so I’ll start with my select statement but before that let me show you how to write a comment in post SQL so you can write a comment by giving a Double Dash comments are very helpful because they make your codes or the scripts readable I’ll write case expression in postc SQL similarly if you want you can go to the top and let’s say here you can write with Double Dash having Clause okay let’s come down so I’ll write my select statement as select I want the department the country and the salary column I’ll give a comma and I’ll start with my case statement I’ll write case when my salary is greater than 45,000 and my salary is less than 55,000 then the result would be B within single codes I’ll write low salary so this is exactly like an if else condition next I’ll write another case when salary is greater than 55,000 and salary is less than let’s say 80,000 then then the result would be medium salary and finally I’ll give my last condition that is when salary is greater than 80,000 then the result will be high salary let me write this in a single line then High salary now one thing to remember in post SQL the codes are insensitive so you can write your select statement in capital in lower case or in sentence case similarly I can write case as small C or you can write as capital c all right now moving ahead after this I’m going to write end I’ll give an alas name as salary range now this is going to be my new column in the output let me just come down after this we need to give our table name from employees I’ll order it by salary descending okay so what I’m going to do here is I’ll first select Department country and salary column from my employees table and then I’m creating a new column that is salary range and I’m specifying the range so I have three conditions here for low salary for medium salary and high salary so let’s run this and see the output there you go here you can see we have added a new column known as salary range and we have order our salary in descending order so all the highest salaries appear at the Top If I just scroll down you can see we have medium salaries here and if I scroll down further you can see these low salaries so case statements are really useful when you want to create a new column based on some conditions in the existing table all right now moving ahead we are now going to see how to write subqueries in post SQL so subqueries we write a query inside another query which is also known as nested query so suppose we want to find the employee name Department country and salary of those employees whose salary is greater than the average salary so in such cases you can use subqueries now let me show you how to write a query inside another query first I’ll write the select statement I’m going to select the employee name comma I want the department comma also want to display the country name and the salary from the employees table where my salary should be greater than the average salary so after this be salary greater than I’m going to use brackets and write my subquery that is Select average salary from employees now let me break it down for you so first we are going to select the average salary from the employees so this particular SQL statement will find the average salary from the table we’ll compare this average salary with salaries of all the employees so whichever employee has the salary greater than the average salary will display their names the department country and their original salary so if you want you can run this statement as well let me select this statement and run it for you you can see we have returned the average salary of all the employees which is nearly $81,400 employees whose average salary or whose salary is greater than the average salary all right now moving ahead this time I’m going to tell you how to use some inbuilt functions we’ll learn some inbuilt mathematical functions and string functions that are available in postris SQL so I’ll just give a comment there’s another way to write a comment instead of a Double Dash you can use the forward slash an asteris and inside the asteris you can write let’s say SQL functions and you need to close this so I’ll give another ASX and a forward slash so this is also a comment in postris SQL all right so first of all we’ll explore a few math functions so there is a function called ABS which is used to find the absolute of a value so if I write select abs of let’s say minus 100 it is going to return me positive 100 or just 100 because as you know the absolute of any value will remove the negative sign involved in that value there you go so our original input was – 100 the absolute of- 100 is + 100 next let’s see another function that is called greatest so the greatest function in postcript SQL will return the greatest number in a range of numbers so suppose I write select greatest inside the greatest function I’ll pass in a few numbers let’s say two I’m just randomly passing a few numbers let’s say 4 90 let’s say 56.5 and let’s say 70 I’ll give a semicolon let me run this you will see the greatest function will return the greatest integer value or greatest number that is present in the range of numbers that we have provided so in this case 90 was the largest number or the greatest number so we got the result as 90 again you can use an alas for each of these statements now like greatest we also have a function called least which is going to return the least number present in a range of numbers if I run this so the result is two because two is the least number that is present in this selection all right now there’s a function called mod which is going to return the remainder of a division so suppose I write select mod and this takes two parameters let’s say 54 divided 10 as you can guess the remainder is 4 and so is our result you can see it has return the remainder 54 divided by 10 the remainder is 4 all right if I scroll down now let’s see how to use the power function so I’ll write select power let’s say I want to know power 2 comma 3 which is 2 Cube that is 8 let me just run this there you go so the result is 8 you can also check let’s say power of 5 comma 3 it should be 125 all right next you can use the sqrt function that is available in post SQL to find the square root of a number I’ll write sqrt and let’s say I want to find the square root of 100 you can get guess the result the output should be 10 if I run this you can see the output here 10 let’s say I want to find the square root of let’s say 144 you can again guess the result it should be 12 let’s verify it okay there is some error let me verify it again there you go it is 12 now there are a few trigonometric functions as well you can use the S function the COS function and the tan function let’s say I want to know the sign of 0 if you have studied High School mathematics you would know the sign of 0 is 0 you can see the result it is zero let’s say you want to know s 90 if I run it you can see the output here 89 all right now there are other functions like C and floor that you can use so let me show you what the ceiling and floor function does I’ll write seiling let’s say I’ll pass my floating value as 6.45 and let me run it you can see the ceiling function Returns the next highest integer that is seven in this case since the next highest integer after 6.45 is 7 let’s see what the floor function does and let me run it as you can see the floor function Returns the next lowest integer that is six in this case or the nearest lowest integer to any provided decimal value okay now that we saw how to use mathematical functions there are a few string functions available in postr SQL so let’s explore them as well I’ll write string functions okay we scroll down cool there’s a function called character length that gives you the length of a text string suppose I write select give the function as character length and inside this function I’m going to pass in a text let’s say India is a democracy this is my text let me run this okay you can see the result here which is 20 since there are 20 characters in my string that I have provided all right now there’s another function called concat in po SQL so concat is basically used to merge or combine multiple strings so I’ll write select concat within brackets I’ll give the text string now let’s say I want to combine postest SQL I’ll give a space comma I want to merge post SQL is I’ll give another comma and write my final word that is interesting now what we have done is inside the concat function we have passed in separate strings and now using the concat function we want to merge the three strings let’s see what the result is I’ll run it all right let me just expand this you can see here we have concatenated the three string successfully so the output is post SQL is interesting okay now there are functions like left right and mid in postc SQL so what the left function does is it will extract the number of characters that you specify from the left of a string let’s say I’ll write select left and I’ll pass in my text string as India a democracy I’ll copy this and I’ll paste it here let’s say I want to extract the first five characters from my string so I’ll give five so what it will do is it will count five characters from left so 1 2 3 4 and five if I run this it should ideally print India for me there you go it has printed India for us all right similarly you can use the right function to extract few characters from the right of a string let’s say you want to extract let’s say I’ll give 12 characters from right so from here onwards it will count 12 characters I’ll change left to right now let me select this and run it so you can see here this is the output from the right it has counted 12 characters and returned a democracy okay now there is a function called repeat so the repeat function is going to repeat a particular string the number of times you specify let’s say I want to select and use my repeat function and inside the repeat function I’m going to pass in let’s say India and I want India to be displayed five times I’ll give a semicolon and run it in the output you can see India has been printed five times okay let’s scroll down there is another function a string function in postc equl called as reverse so what reverse function is going to do is it is going to print any string passed as an input in reverse order so if I write select reverse and inside the reverse function I’ll pass in my string that is India is is a democracy I’m going to use the same string I’ll copy this and I’ll paste it here I close the codes and the brackets let’s print this you can see it here India is a democracy has been printed in reverse order there you go all right now this time we explored a few inbuilt functions that are already present in postris SQL now post SQL also has the feature where you can write your own user defined functions so now we will learn how to write a function of Our Own in post SQL so let’s create a function to count the total number of email IDs that are present in our employees table so for this we’ll write a function a user defined function so let me give my comment as user defined function okay so let me start by first writing create so this is the syntax to write a function in post SQL so I’ll write create or replace function then I’ll give my function name as count emails and as you know functions have brackets then I’ll write Returns the return type as integer then an alas with dollar symbol I’ll write total emails since I’m going to display the total number of email IDs that are present in my table I’ll close the dollar symbol then I’m going to declare a variable the variable name is going to be total underscore emails this is of type integer I’ll write begin and inside begin I’ll write my select statement so I’ll write select I want to count the email IDs that are present so I’ll pass my call column name that is email into total emails from my table name that is employees I’ll give a semicolon and then we’ll write return total emails as you know user defined functions often return a value so hence we have mentioned the return statement as well and now I’m going to end my function then the next syntax would be let me just scroll down okay so here I’ll give my dollar symbol again followed by total underscore emails next I’ll write my language as post SQL so the way to mention is PL p g SQL let’s give a semicolon and end it so this is my user defined function that I have written so I created a function with the function name countor emails and this would return integer as an alas which is total _ emails we declared that variable as an integer then we started with a begin statement that has my select statement where I’m selecting the count of email IDs that are present in the employees table and I am putting the value into total _ email so I’ve have used the into keyword and this Returns the result as total _ emails and I have ended let’s run this okay there is some problem there is an typo so this should be integer okay let me run it once again there you go so youve successfully created a user defined function now the final step is to call that function now to call this function I’m going to use my select statement and the function name that is countor emails I’ll give a semicolon let’s execute this there you go so here you can see there are 134 email IDs present in our employees table now one thing to Mark is there are total 150 employees in the table but out of them 134 employees have email IDs the rest of them don’t have so they would ideally have null values all right so that brings us to the end of this demo session on post SQL tutorial let me go to the top we have explored a lot so we started with checking the version of post SQL then we saw how to perform basic mathematical operation that is to add subtract multiply then we saw how to create a table that was movies we inserted a few records to our movies table then we used our select Clause we updated a few values then we deleted one row of information then we learned how to use the we Clause we learned how to use the between operator we also learned how to use the in Operator Let Me scroll down we created a table called employees and then we learned how the distinct keyword works we also learned how to use isnull with wear Clause we learned about the order by Clause we saw how to alter or rename a column then we explored a few more examples on wear Clause we learned about and and R operator then we learned how to use limit and offset as well as the fetch operator or the fetch keyword in postr SQL moving further we learned about the like operator in SQL which was used to perform pattern recognition or pattern matching you can say here we saw how to use basic inbuilt post SQL functions like sum average minimum count maximum next we saw how to update a value in a column using post SQL update command we learned how to use Group by then we learned how to use having Clause then we learned how to use case expressions in post SQL so we saw how case expression is similar to our ifls in any other programming language we explored a few mathematical and string functions and finally we wrote Our Own user defined function so that brings us to the end of this tutorial on postris SQL now if you want to get this SQL file that we have used in the demo you can give your email IDs in the comment section and our team will share this SQL file with you over email so what exactly is a CT you ask now if you are a beginner in sequence let’s say you wanted to Club two different tables or more different tables maybe three or four right so you will be using one keyword which is join right and let’s say you may have to create a query in such a way that you have to Club different tables and you have to extract the results from one table into another and finally create a output table right so this might be sounding a little too complex so basically Al what CTE does is it acts as a temporary table right now you can write a query and save it as a CTE right and that particular resultant table from CTE will not be created but will be in the memory as a temporary data or an intermediate resultant data right now whenever you want to use a join or whenever you want to use the same query inside a bracket or inside something in your query you can just simply use the name of the CT and then the data you require the columns you require and done you will get the data now this might be a little too complicated to understand in just m words now let’s just go through the formal definition of what exactly is a CTE and what it does and then let’s quickly so it’s a little too complicated to understand it just with m words so let’s get started with a practice iCal examples but before that let’s understand a formal definition of what exactly is a CTN SQL there CTE also known as or also called as the Common Table expression or some people also are used to call it as a width expression so the keyword is withth so a comma table expression in SQL is a temporary result set that you can Define within a query as I said it helps to break down the complex queries make the the code more readable and allows you to reuse the result set multiple times within the same query just you need to use the name of the CTE in the places where you want in your query and it reduces the code length as well as the execution time now CTE are defined using the width keyword as we discussed before followed by the CTE name right so for every uh column name or anything in your set you give a name right similarly when you are using CTE in SQL you also need to give a name to the CTE and that particular name will be used in your subquery positions that will reduce the query length and execution time so you should be giving a name and the query that generates the result set the CTE is available only during the execution of that particular query or specific query right so as I said the CTE table the resultant table which is created while you are using the CTE will not be created as a permanent table in the datab base right it will be a temporary or intermediate result which will be active as long as your current query which is using the CTE is active now let’s go to the demonstration mode then we will try to create some simple queries right and and we will understand how exactly a CT can be beneficial in those situations now let’s go to the MySQL workbench this is my my SQL workbench so I have a lot of tables here we have the credit card data set we have the sakila data set SLP data set says Superstar World Etc right so we will be using the Superstar data set uh I mean the database so firstly we need to write in the query which means that I am going to use the superstore database right sorry Superstar so I uh prefer using uh smaller case or lower case for database names and column names and uh uppercase for the keywords for example here use is uppercase and Superstar is the name of the keyword right so uh that is for uh identifying or easy readability which is a keyword and which is a name right so let’s execute this query and have access to the superstore data set and in Superstore data set I have one table called as Excel data now let’s quickly check what we have in Excel data select star from Excel data here we have R the order right ID audit dat ship mode customer everything right so we have region we have uh sales quantity discount profit rate so we have a number of possibilities and number of reports that we can generate but let’s try to keep it simple let’s try to find out unique regions right select unique of regions right or just regions Exel data Group by regions so let’s quickly execute this statement and see the output or maybe we can make some modifications to it right instead of that you might want to use you might want to use distinct function so that you don’t get all 10,000 plus rows so basically uh this particular data set has about 10,000 or more rows in it and it’s not real it’s completely made up report using artificial intelligence so we use chat GPT to create 10,000 rows of data for 30 years maybe from 2000 or 2001 to up to 2030 or 31 right so we don’t want all those 10,000 plus columns sorry rows so let’s use a distinct here and uh try to exit this statement so that we get U five uh of uh the regions what we have so there you go we have um five regions as expected NorthEast Southwest and Central now you can also uh select uh kind of maybe average of sales uh maximum of sales and total sales so so uh this is bringing us somewhere we can you know try to find out regionwise sales right so region wise sales Group by years like 30 years what was the sale happened in the year 2021 sorry 2001 right we begin from 2000 or 2001 to all the way up to 2030 or 2031 right so we can see if there is an increase in the year on-ear sales a decrease in the year on year sales you can identify the best performing eror the worst performing eror right so uh this sounds like a good use case now let’s go to the code where I’ve written it as a CTE and understand the workflow so here I have uh named my CTE as sales CTE so I’m starting it with the keyword with right so with sales CTE as now this is our query right what am I doing I’m extracting so according to the data set we have the date right so the date is year month and date of that particular day right but we want just the year so we’re using the ear function to extract the Year from the date as sales ear region uh sum of sales right we want you to find out the total sales happened in that particular year as total sales from the data set Excel data and appr by a right we wanted it in increasing order so 2000 to all the way up to 230 or 20031 correct so that’s how it is and I’m saving all this as a CTE named as sales CTE now I want to select some parts of that particular CTE so I want to select sales air region total sales from sales CD which is right over here and and order it in form of sales and region right now let’s try to copy this code and run this in our workbench right now let’s Okay let me close this quickly so that we have a complete view of the code right so let’s now select all the code so now we have selected this particular code let’s try to run this and see the output there you go we okay we have the output but there is something wrong we did not get uh the ears right so all the 30 years of data here it is Group by region which is fine okay we don’t want region we want to group it by ear that’s okay and the thing is we need to fix this particular year so maybe there is something wrong with the ud date right so I think uh the database has saved this particular oh okay okay since this is generated by chart jpd maybe the data type of the date is other than data right other than date data type it may be string now we might have to do some type casting to change the data type of the audit date and let’s quickly do that so now we have updated the ear so so what we have done is just uh cast here right so we have changed the string type of date to the normal date which follows by year month and date so this is a simple type casting that you can do and uh rest everything and we’ve also added a where condition so where uh date is not added or date is equals to null then you can just uh ignore that and uh now let’s try to execute this query and we have also removed that region thing right Group by region or order by region so we want that to be ordered according to the uh year which should start with uh 2001 or the first ever year at to the last ever year according to dat set now let’s select the entire CT query and run that and check our outputs so there you go so you have the year on-ear sales from 2001 to all the way up to the year 2030 and 2031 right so that’s how the CTE or common uh table expressions and SQL or the width query in SQL can be used so welcome to the demo part of the SQL project so in this we will do digital music store analysis okay so this SQL Pro is for the beginners so what you will learn from this uh project main thing is like so what’s the objective of this project this particular project so this project is for beginners and we’ll teach you how to analyze the music playlist database and you can examine the data set with SQL and help the store understand its business growth by answering simple questions so as you can see I will show you so I have three set of questions first one is easy okay and the second one is moderate and the third one is advanced level so we have three set of questions easy set moderate and the Advan okay so every set is of three three questions I guess yes in every set there is three three questions so okay in easy one there are five so we have 5 + 3 8 8 + 3 11 we have 11 questions to solve okay from this you will understand how you can you know analyze data with SQL how you can extract something from database how you can store something like this okay so and one more thing I will show you the schema of the particular uh data set which we will you know soon we will will restore so we have the tables in this artist album track media type genre invoice line invoice customer employee ID playlist playlist track and all okay so this is the music playlist database schema so without any further Ado let me create one database so here just right click create database okay here I will write music okay and save so now our database is created okay so if you will go to schema and if you go to tables there is no tables in it means there is no there is database but nothing is there the database is empty so now what I will do just go to your database just right click here you can see the restore option okay restore so format as it is then here file name go to this music store database I will put this database Link in the description box below don’t worry open then restore process started process complete some people will face this uh that the process is failed or something okay so for that what you have to do just go to file then preferences here you have to set the path just binary path okay see I am using the 15th version okay so I have set the path here also and this also but you have to set this path is important okay if you will not set this edv Advanced server path it’s fine but this part is most important okay but for the future reference I have added on the both what you have to do you have to just see where you will find this path just go to this PC then OS then program files here you will find this post G SQL then I’m using C5 15 then bin so you have to copy this path right you have to just copy it and paste it here and then select this one after that just save you won’t find any fail thing okay the process will complete right so now let’s move forward and see the tables okay it’s still empty while just refresh it see now you can see all the you know columns in my tables okay so what I will do for the checking I will run one query here okay let me close it okay I will write here select star from album okay let me run it so now as you can see here my table is working fine everything seems good okay so now what we will do we will solve question one by one okay so the first question let’s see the first question easy one who is the senior most employee based on job title okay who is the senior most okay so I will write here like the first question is who is the Senor most employee based on job title okay so this is our question so we know we have the table name called employer so we will select that table first so I will write here Select Staff from employee so you should know uh which table should to select okay so here as you can see in this question there is you know t uh word employee who is the senior most employee based on the job title most employee means means employees and employee table right so I will run it okay so what I will do I will just select this and run it okay so now you can see there in employer there is employee ID last name first name title report levels bu date higher date and all the details of the particular okay so we will do so there is one more thing you can see the levels okay level one level two so we have to who is the senior most employee based on the job title so what I will do I will write here order by levels and decreasing order okay so first I will do so now you can see the levels are in the descending order from senior to this okay L7 to L L1 so what we want we want only one uh employee name so what I will write here limit is one okay I will copy this and done it okay so now you can see the last name is Madan moan sorry moan Madan this is last name this is first name so Mohan Manan is the senior most employee based on the job de so question first is done so the second question is which countries have the most invoices okay first I will write down the question which country has the have the most have the most invoices okay so for this what we have to do see just first check first we have to check from which table you know we will get the solution so here you can see the word invoices Okay so we have one table invoice and invoice line we have to select it from this okay so I will write here Select Staff from invoice okay so we have customer ID invoice date billing address billing city billing State and everything so here you can see we have the billing country as well okay because we need the country name so we will take this column right so I will write here so I will write select we change it select count star from the select star billing country from invoice Group by billing country so why I’m doing this group by because as you can see uh we have USA multiple times USA USA USA then Canada also and the other countries as well so from this I will get only the one okay I will group them and I will get the one fine so from this we will uh get the count so after this I I will write order by so here I will write see see descending okay let me run it so now you can see the billing this is the billing order okay so or you can see the on voices USA got the 131 and Canada 76 Brazil 61 if I will write here again the limit one what I will get see USA we got the USA so us is the country which have the most invoices okay if you will remove this limit so you will get the other country as well second in Canada third is Brazil and like this okay and the third question is what are the top three values of total invoices okay again we need the same table okay first I will write the question third question is what are are the top three values of total invoices top three value of total invoices okay I know I can just solve this question by the second one but I want to do it from the starting okay so first I will take select stuff from invoice let me run it so first we will sort the data here I will write order by total because the last you know this is a table name okay total and the descending order so first I will select so we need just the top three so first I will do everyone know limit three okay okay so here I have done I have wrote this star that is why it’s giving me the all the values if I want this only this value so I can write select total from invoice order by this okay I will say and to run it so I have this total like 23.75 999 and 19.8 and 19.8 so these are the top three values of total invoices okay so here the fourth question is which city has the best customer we would like to throw a promotional music festival in the city we made the most money write a query that returns one city that has the highest sum of invoice Total return both the city name and some of the all invoice total so let me write the question first okay I’m writing question for you know your better understanding okay question fourth which city has the best customers we would like to throw a party uh promotional promotional music festival in the city we made the most money we made the most money write a query that it does one city that has the highest sum of invoices has sum of invoices total both the city name and sum of all invoices okay so we have this question okay so which city has the best customer we would like to throw a promotional music festival in the city we made the most money write a query that returns one city that has the highest sum of invoice Total return both the city name and the sum of all the invoices okay so first what we will do we will select select stuff from invoice okay sorry we select this okay so first we will select the billing city we have to focus on this and the total in this this two table we have to just focus on okay so here I will write some of total as invoice total comma billing city from invoice so this time we will do group by pilling City because we need the city names uh then I will addite order by invoice total and the descending order seems good select some total as invoice Total Building City from invoice building okay so let me select this so as you can see the highest billing city is parag Prague and the best customer is from the parag city okay so this city has the best customer obviously parag pragu or sorry for the you know mispronunciation okay so this is how we have solved our fourth question as well okay because WR both the city name and the sum of all the inv you know these is the city names and then inv voice total okay moving forward to our fifth question which is again the long one who is the best customer the customer who has spent the most money will be the declared the best customer write a query that Returns the person who has spent the most money okay so I will write here who is the best customer the customer who has spent

    the most money will be declare the best customer so write a query right that returns that Returns the person who has spent most money okay yeah so who is the best customer the customer who has spent the most money will be declared as the best write a query that Returns the person who has spent the most money okay so for this we have to take this customer Data customer table data okay so I will write as select stuff from customer okay I will select this and I will run it okay so this is our know data table data of customer okay so we have the country facts emails state city address last name first name okay so as you can see there is nothing uh like no detail of invoice or the money okay which have spent by the customer so what we will do we will look at our schema so now what we can do if we can’t solve a particular question from with one table we have to you know join the table to the other table so here we have to join customer table to invoice table so in this you can see there is customer ID and here also customer ID so on the basis of customer ID we can join the join both the table and with the help of this total we will sort out the uh that guy okay that customer right so for this I will write here select customer Dot customer ID comma customer Dot first name comma customer dot last name because we need need the full name of that guy comma sum invoice do total as total okay okay let me can P okay I don’t need the search pad right then I will write from customer okay my bad then join invoice on customer Dot customer ID equ alss to invoice do customer ID then I need Group by okay Group by customer Dot customer ID after this uh uh let me order it by the descending order so the most you know spend customer will come up so I will write here order order by total the descending order then limit equals to one fine let me run it let’s see what output should okay okay some error is coming okay sorry okay so as you can see the customer ID is five first name is R the last name is m our m is spent the highest value 14454 0 and two so who is the best customer M our mad sorry my bad our ma right our mother has spent the most money okay so this is how we are done with our easy set of questions now let’s jump into the moderate one okay so let me write the question first for the moderate so I will write here moderate questions so these analytics skill help you in the data analytics to become a data analyst or to become a data scientist okay so the question first is write query to return okay write query to return the email qu to return the email comma first name first name comma last name and genre of all do music list okay then return your list ordered alphabetically by email starting with a okay let yeah so for this okay let me open this first yeah okay fine so first what I will do so now in this question as you can see we need the we have to return the email first name and the last name and the J of all rock music listeners so if you will see select stuff from customer okay let we run this and if I will see there is no column name genre okay if I will show you the schema of this see the genre is here and the customers is here okay we need the first name last name and the email ID and the genre okay and the genre is Will should be Rock okay so what I can do I can connect this genre with track that because here is also track ID and here is also track ID then track ID to invoice line then invoice line to invoice then invoice to customer with the customer ID okay this pattern I have to follow right so for this I will write select just copy this okay just follow the steps select distinct email comma first name comma last name from customer join invo voice on customer Dot customer ID equals to invoice do customer uncore ID then join invoice underscore line on invoice do invoice ID okay then invoice _ ID then where check ID should be in here I will do select track ID okay from track then join then join genre yeah on track dot genre dot ID equ to genre dot genre ID where this is important genre name like rock because we need as you can see right a quy to return this is this and genre of all rock music listeners okay rock right then order by email okay before that let me show you this track okay select star from track okay let me show you this table you can see the name the track ID album ID Media type genre ID okay then the composer this this this bites and the unit price right okay so you know this we have then this customer okay invoice ID we to right fine so now what I will do I will just select this and okay invoice ID okay inv voice it is ambiguous here I have to write invoice line do invoice ID okay let me now run let me run it okay one more join genre on track. genre ID there is entry for table genre but it cannot be referenced from this part of the query okay okay as you can see the have the table name is Jore ID that was the mistake okay one more JRA do name spelling mistake sorry my bad guys no shes it happens okay now you can see we have all the people who love rock music and we have the email then first name then the last name see Adan Mitchell Alexandra Roa a grber like this cam Dan Edward like this okay so there are total 59 people who loves rock music from this particular database okay now question two question two is let’s Okay first let me show you let’s invite the artists who have written the most rock music data set write a query that Returns the artist name and the total track count on the top 10 rock bands okay so let’s invite the artist who have written the most rock music in our data set so write write a query that Returns the art this name and and the total count of track count of top 10 rock band so now what we need here okay let me do this so what we need here so let’s invite the artists who have the written the most rock music first we need the artist okay and the second is rock music then we need track okay and the total count total track count means we will get from the track so here we have track column track uh table and we have the artist so now let’s see the schema part so we have we need genre okay for the you know uh rock music then we have to combine this with the track ID because JN R is there from track ID to album because we need the artist name see artist ID and artist ID so this is how we have to connect the table now so for this I will write here just follow the steps select artist dot artist ID comma artist dot name comma count artist. artist ID as number of songs because we need the total number okay who have written the most rock music number of songs find from track now we have to join album on on album do album ID equals to track dot album ID okay then we have to join the artist with artist ID so join artist column on the basis of artist AR equals to then album to album. artist ID okay so here I have joined the artist to the album colum table okay then I have to join johra to the track table with the track table okay so here I will write join genre on genre do genre ID equ to JRA ID okay sorry track ID track. J okay so here I will write where where genre dot name name like shock okay rock fine then I will Group by my B group by artist do artist ID I need the ID as well then order by order by number of songs the descending then limit I need only 10 rock bands limit will be 10 let me run it okay let me run it okay album okay now let me run it okay now you can see this guy let zeppin AR side is 22 and wrote the most songs 144 then U2 122 d purple 92 then then this this this then this okay so this is how we solved our second question right so now the third question okay return all the track names names that have a song Length longer than the average song Length return return the name and the millisecond of the each track order by the song Length okay so first I will write this question Q3 so return all the track names that have a song Length longer than the the average song length Okay as we return all the track names that have the song Length longer than the average song Length okay then return the name and milliseconds for each track fine after that order by them order by the songs with the longest s listed first okay fine so we have to return all the track names that have song length and the okay first we will find the total length of this songs then we will do the where then we will put the V Clause to find out the particular uh longest song okay so this is this we’ll do in the two you know step first you will find the average strike length Okay so I will write here select select name comma millisecond okay from track where milliseconds here I will write select average from the millisecond okay then I will write here as average track length Okay then here I will write from track after this I will write here order by milliseconds I need in the descending order okay so let me run it so now you can see see first I will uh read it again so return return all the track names that have a song Length longer than the average song Length return the name and the millisecond for each Strat order by the song with the longest song listed first okay so this is the longest song okay so we have all the songs which are the longer than the average song Length right so now moving forward we have jumped into the advanced set of questions okay so now we will do the advanced questions okay so let’s see first find how much amount spent by each customer on artist write a query to return customer name artist name and total spense okay so first we will write down the questions okay then question one question one okay find how much amount spent by each customer on art is just write a query to return customer name comma artist name comma total spend and total spent okay so how to solve this so first find which artist has earned the most according to the invoice lines okay first uh let me show you the schema okay we need the artist name we need the customer name and we need the total spend okay with the invoice line because the quantity should be there okay so first we’ll see how to join these three table artist table customer invoice and invoice line like this okay this is how we will you know join the table fine so now I will tell you the you know steps so first find which artist has earned the most according to the invoice line okay the second now use the artist to find which customer spend the most on the artist so for this query you will uh be need to use the invoice invoice line track customer album and the artist table so just remember this one is tricky because the total spent in the invoice table right let me show you so total spent on the invoice table might not be a single product so that is why I was saying we need the quantity so we need the invoice line table to find out how many each product was purchased then we have to multiply this by the price of each artist okay fine so now so this is the lengthy one I will just you know write it for you and get back to you yeah so this is how you can see okay Group by five I have wrote this you can just you know write it okay like this okay we took artist name then sum of invoice line unit price into invoice line the quantity that I showed you okay we have multiply this total with the quantity okay then we join the table track with invoice album with track artist with album okay so now let’s run it yeah so now you can see this H or queen amount spent 27 the customer ID is this okay then Nicholas scer then 18 okay we have the the everything okay customer name artist name and the total spend this is the customer Name the artist name and the total amount this spent fine so now let’s move forward to the next one which is okay okay yeah so the second one is this we want to find out the most popular music genre for each country we determine the most popular genre as the genre with the highest amount of purchase so write a query that returns each country along with the top genre for countries with the maximum number of purchases shared return all the genres okay so what I will do first I will write the question okay so we okay question two so find how the most popular music music genre for each country okay with the mine determine the most popular genre as the genre with the highest amount of purchase okay then write a query that returns each country along with the top genre for countries where the maximum number of purchase okay so so there are two parts in this question first the most popular music genre and the second is the need of data at the country level okay so we can do it from the two methods okay using CT and the using the recursive method so I will use the using City I will do this city so for that you have to write with popular genre as select count invoice line dot quantity okay as purchases comma customer dot country comma genre do name comma genre dot genre ID okay then here I will write row underscore number number then I will write over Partition by customer. country order by count voice line dot quantity okay into descending order as row number okay so from invoice line okay yeah so here I will join the tables join invoice on invoice do invoice ID equals to invoice line do invoice ID okay then again join customer on customer. customer ID do idore idals to invoice Dot customer ID fine then again we have to join track track on track. track ID equals to invoice uncore line Dot trackcore ID then join genre on genre. JRA ID okay then track do John Ry okay then I will do group by Group by 2 comma 3 comma 4 then I will do order by two then ascending order and then one to descending order okay okay then now I will write select star from popular genre where row number less than greater than one okay now let me run it so now you can see we have okay I will let me read so we have to find the most popular music genre for each country okay so now we have the Contin margentina the most popular is alternative and punk John R is this store number is this okay purchases this then the Australia this rock rock rock rock rock okay certain Rock USA Rock and everything is there right so this is how you can find the most popular music genre for each country okay the last question is the here now the last question is write a query that determines the customer that has spent the most on the music for each country write a query that Returns the country along Ong with the top customer and how much they spend okay for the countries where the top amount of spent is shared right and they provide all the customer who spend this amount okay so for this um this is like a similar to this question okay so there are two parts in this question find the most spent on music for each country and the second is the filter the data for the resp customer it’s very easy okay so okay I will write the solution okay you can check the question from there I’ll write customer with country as as uh I will here select customer do customer ID comma first name comma last name comma billing billing country comma sum should be total as total spending right then I will write zow number same over we have also written here now right the same we have to write here over then Partition by billing country order by by some total descending order as row number okay so after this I will write here from invoice you have to fetch then again the same thing we have to join the table join customer on customer Dot customer ID equals to invoice do customer ID okay then here I will write Group by by 1 comma 2 comma 3 comma 4 comma okay that’s it okay then I will write here order by four ASC ascending order comma five to descending order fine so now I will write here select start from customer with country where row number is one fine so let me run it see we have first name last name billing country total spting R number and the customer ID let me show you the question here write a query that determines okay let me make it okay yeah so write a query that determines the customer that has spent the most on the music so customer we have the customer name for each country write a query that result the country along with this so we have the country name with the top customer how much they spend we have the total spending for the countries where the top amount is shared provide all the customer who has customer who spent this amount okay so we have everything here right we have this Le from Brazil this this this this this okay with the customer so this is how you can solve these questions so till now I can say you have a good data analytics skills so for this I can say this will help you in the interview of data analyst in data science or any SQL okay picture this you are in the interview and the interviewer ask can you write a query to find the top five sales records you freeze for a moment thinking am I ready for this or not don’t worry SQL might sound complicated but it’s actually a super useful tool that lets you interact with databases have you ever wondered how all those apps and websites stores and organize their data well that’s where SQL comes in SQL which stands for structured query language is a universal language for talking to databases it’s super powerful and lets you do things like pull out specific information add new data update existing stuff or even delete things you don’t need it’s basically your magic key to manage huge amounts of information with ease exactly and if you’re aiming for a career in Tech whether it’s a database administrator data analyst or software developer SQL is a must-have skill databases are at the heart of almost every application so knowing SQL can unlock some really exciting opportunities now here’s the exciting part this video is your secret weapon to master SQL interviews we have packed it with 45 carefully chosen SQL interview questions that everything you need to raise those tough questions so we’ll be starting with the basics like how databases work and then diving into advanced query challenges and by the end you’ll be fully prepared to tackle any SQL question thrown at your way so let’s dive in and get you closer to your dream job so let’s get started so now let’s start with a SQL interview question we’ll cover every question starting from basic level to advanced level so now let’s look at our first question which is very basic what is SQL so we all know that SQL stands for structured query language and it is the language which is used talk to databases think of it like giving instructions to a computer system that stores and organizes data for example if you want to find out all the customers who ordered a specific product then SQL can help you do that with a simple command you can also use SQL to add new data like entering a new customer details into database if you want to update someone’s phone number SQL has got you covered or maybe you want to delete old records that are no longer needed SQL can handle that too here’s a quick example if you want to find all the customers in New York you could write something like select star from customers where city is equals to New York so we are using this command to find all the customers in New York remember if you want to find out all the specific data from the table you have to use the Star Command and if you want to add new customer you can just simply write in insert into customers name City and then you can also insert value name which is John or and you can just enter the specific location so SQL works the same way across many popular databases like my SQL post SQL or SQL Server which is why it’s such an important skill for anyone working with data so now let’s look at our second question which is what are the different types of SQL commands so SQL commands are like instructions you give it to a database to tell it what to do there are different types of commands and each one has a specific purpose so let me explain these in simple terms remember if an interviewer asks you such questions simply explain using the proper keywords and uh use proper definitions and you know easy language that’s it so the ddl command we have which stands for data definition language it basically defines the structure of the database for example if you want to create a table or if you want to alter a table or if you want to drop a table then we have DML which stands for data manipulation language it deals with the actual data in the database for example insert update delete all of these things then we have DCL which is data control language it will manage permissions and access control so if you want to manage permission or access control then you have to use this particular type of SQL command which is DCL which is Grant and Revo Grant will provide access rights and ROK is used to remove the access rights we also have TCL which stands for transaction control language it will manage transactions in the databases for example commit commit is used to save changes rback is used to undo changes and save point is used to create intermediate points in a transaction so for instance in a schema with customers table and an order table data definition language commands are used to Def find the table whereas data manipulation commands which is uh select insert and delete it is used to update customer or order data DCL is used to control access and TCL which is transaction control language is used to manage transactions that’s it it was very simple now let’s look at your third question which is what is a primary key in SQL a primary key in SQL is like a unique ID for each record in a table think of it as a way to ensure that no no two rows in a table have the same value remember that no two rows must have the same value it is also a rule that the primary key column can’t have empty or null value so these are the basic criteria for a key to be a primary key for example in a table of customers you have a column called customer ID as the primary key then each customer have a unique customer ID like 1 2 3 and so on this makes it easy to identify Y and retrieve specific customers from database here’s a simple example suppose we have created this table create table customers and we have given the customer ID as primary key we have given name as Vare the city name as well so the primary key will ensure that each customer ID is unique no duplicates are there no customer ID is left blank that is there should be no null values and primary keys are also important when linking tables together for example if you have orders table you can use the customer ID as a reference to connect each order to a specific customer this help maintain data Integrity across the databases now the fourth question is what is a foreign key a foreign key in SQL is like a connection or link between two tables it’s just like a field in one table that refers to the primary key in another table this creates a relationship between the tables and ensures that the data stays consistent for example let’s suppose you have two tables a customer table with a primary key called customer ID and a sales table with a field called customer ID which is a foreign key linking back to the customer ID in the customer table so here’s how it will look like we have created this table and you can see in this example that suppose we have customers and sales table so we have used this customer ID in our customer table as well so here customer ID is the foreign key and in the customer table the customer ID which we had used is the primary key so now let’s move on to our fifth question which is delete and trunk it command what is the difference between delete and truncate commands so delete and truncate commands in SQL both remove the data from a table but then they work in different ways let me break it down for you the delete command so what delete command will do is basically this is used when you want to remove specific rows from a table based on a condition for example if you want to delete all all the customers from a specific City then you have to use this delete command it will allow you to be selective but it’s slower because it logs each row deletion which also makes it possible to roll back the changes if needed if you’re using transactions moving on to trunade command trunk gate will remove all the rows from a table at once without allowing any condition for example if you just want to remove all the rows just in a one go you have to use this truncate command just simp write this query as trunk table suppose the table name is customers is much faster because it doesn’t log individual road deletions and it simply clears the entire table in one go however you can’t roll back a trunk operation in most databases once it’s done so the key differences is delete is for specific row trunk it is for clearing the entire table trunk it is much more faster because it uses fewer system resources delete can be rolled back if used within a transaction trunade usually cannot delete logs each rout deletion and trunade doesn’t so this was all for this trunade and delete commands so anytime if the interviewer asks you such questions just simply explain this now let’s move on to the sixth question which is what is a joint in SQL and what are its types so this is one of the most important question you’ll be getting to know in the interviews you’ll be asked such questions in the interviews so basically a chin and SQL is used to combine a data from two or more tables based on related column like a column key that links them together it’s just like connecting pieces of puzzles join help you see the bigger picture by merging related data for example if you have a customer table and a sales table you can use the join to see which customer placed which order by linking them through a common column such as the customer ID so you all know what a join and SQL and let’s discuss its type so joint types are basically there are four types of joint which is inner joint left joint right joint and full outer joint as well so what inner joint will do is it will combine rows from both tables where there is a match in the common column think of it as the overlapping section in the v diagram only rows that exist in both the tables are included the left join or we can call or the left outer joint it will retrieve all the rows from the left table and the matching rows from the right table remember the left joint will retrieve all the rows from the left table and only the matching rows from the right table if there’s no match the result includes null values for the right tables column think of it as including the entire left Circle in the vent diagram along with any matches in the right Circle right join or the right outer joint is similar to the left joint but it will retrieve all the rows from the right table and matching rows from the left table if there’s no match null values are included for the left table column think of it as including the entire right Circle in the vend diagram along with any matches on the left Circle then we have the full joint full joint will combine rows when there’s a match in the either table if no match is found it includes null or the missing values from the either table think of it as combining both circles in the v diagram everything from both tables are included now let’s move on to the seventh question which is what do you mean by a null value in SQL it’s very easy null value in SQL means that a column has no data it’s missing or unknown it’s not the same as an empty string or the number zero those represent actual value while null represent no value at all for example if you have a table of customers and one of the row doesn’t have a phone number then the phone number column for that row would be none see we have listed this in the table here you can see if you do not have any data just simply write none so the next question is Define a unique key in SQL so unique key in SQL ensures that all values in a column or a combination of columns are unique that is no duplicates are allowed it’s like a having a rule to make sure that no two rows in a table must have the same value in that column for example in a user table the email column can have a unique key to ensure that MO two users can register with the same email address remember the key points unlike a primary key a table can have more than one unique key unique Keys allow null values while primary keys do not so these are very important to remember so if you’re ask a difference between a primary key and a unique key just simply say that unlike primary key a table can have more than one unique key and unique key allows null values while primary key doesn’t so here is a table we have listed below that is create table users and we have given user ID as integer primary key and then we have email Vare as a unique key so here the email column is a unique key so that each email must be different it should not be the same now let’s look at our next question which is what is the database a database is organized way to store and manage data think of it like a digital filling cabinet where information is Neely arranged in tables with rows and column each row represents a record and each each column represents a specific detail about that record for example a database for a library must have a table for books then the rows could represent individual books and the columns could include the book title author and the publication year the main purpose of a database is to make it easy to store manage and quickly retrieve data whenever you need it databases are used in everything from apps and websites to banking system and e-commerce platform now let’s look at our question number 10 which is explain the differences between SQL and no SQL databases so here’s a simple explanation SQL databases are structured which means they can store in tables with rows and column like a spreadsheet they follow predefined schema meaning the structure of a data is fixed and you need to Define it before adding any data these databases are great when you need consistent and reliable data like for banking system or inventory management examples are MySQL Oracle Ms SQL post SQL Etc and SQL databases are also known as rdbms which is relational database management system let’s talk about nosql databases so nosql databases are flexible and do not use stable instead they can handle unstructured or semi structured data so no SQL database is dynamic where data is primarily stored in Json objects key value pair graph nodes Etc they don’t have a specific ific structure the such databases are mostly not preferred for performing complex query operations and the examples include mongod DB couch DB elastic search Etc so now let’s move on to question number 11 which is what is a table and a field in a SQL so a table is like a spreadsheet that stores data in organized way using rows and columns each table contains records and the details for example a table name employees could store information about employees in a company whereas a field is a column in a table and it represents a specific attribute or property of the data for example in the employees table Fields could be employee ID name and department so here’s a simple example of the table you can see here the fields name or we can say column and we also have the records or the rows we can see that so in this table the entire table is called employee each row or record stores information about one employee and each column of field represents specific details like employee ID name and the department now let’s move on to a question number 12 which is describe the select statement well the select statement in SQL is used to retrieve data from a table or multiple tables it’s like asking databases show me this specific information here’s how it works you can specify which columns you can see for example to retrieve all customer names from a customer table you can select name from customer if you want to retrieve all the data just write this query select star from customers remember I told you before in the first question we using start if you want to retrieve all the data from the table and if you want to just retrieve from a particular row or a column just simply write select name from customers the field name you can also apply filters you can use a wear Clause to filter the results for example you can write select name from customers where the city name is New York you can also sort the results use the order by to sort the data for instance to sort customers by the name you can just write select name from customers and then order by name ASC ASC means ascending order so in short the select statement lets you choose what data you want to see now let’s talk about what is a constant in SQL and name a few so if you ask this question just simply answer a constant in SQL is a rule applied to a table that ensures the data stored is accurate and consistent it also help in maintaining data Integrity by restricting what values can be added or modified in a table here are some common constraints primary key we have foreign key then we also have unique key check not null and default so we have already discussed about primary key it ensures that each row in a table has a unique identifier and the column can’t contain null values foreign key links to a column in one table to a primary key in another table to maintain relationship unique key ensures all the value in a column are distinct that is there are no duplicates the check ensures that data meets a specific condition before being inserted or updated not null ensures that a column cannot have null values the constraints are essential for maintaining reliable and valid data in your database now let’s talk about what is normalization in SQL normal I ization in SQL is a process which is used to organize data in a database to make it more efficient and reliable the goal is to reduce R deny which is duplicate data and Ure data consistency this is done by splitting a large table into smaller related tables and then linking them using relationship like primary and foreign key for example imagine a single table that stores customer details and the orders if the same customer places multiple orders then their information like name and address would be repeated for each order now using normalization you would separate this into two tables first we would have customer table which will store customer details like customer ID name and the address and then we have order table which will store order details like order ID customer ID and the order table now by linking these tables using customer ID you can also reduce duplication and ensure that any changes to customer details are updated in just one place now let’s talk about question number 15 which is how do you use the wear Clause it’s very easy so just answer the we Clause within SQL queries serves the purpose of selectively filtering rows according to a specified condition thereby enabling you to fetch exclusive those rows that align with the criteria you define for example select star from employees where department is equals to HR now let’s move on to question number 17 which is difference between Union and Union or so Union is used to merge the contents of two structurally compatible table into a single combined table the difference between union and Union all is that Union will omit duplicate records whereas Union all will include duplicate records very easy Union will omit duplicate records and Union all will include duplicate records the performance of Union all will typically be better than Union since Union requires the server to do the additional work of removing any duplicates so in cases where is certain that there are not any duplicates or we having duplicates is not a problem then we can use Union all it would be recommended for performance so now let’s move on to the question number 18 so here a table is given below and you will have to see what will be the result of a query the query is Select star from Runners where ID not in select winner ID from races so the answer is given the simp data provided the result of this query will be an empty set so the reason for this is as follows if the set is being evaluated by the SQL not in condition contains any value that are null then the outer query here will return an empty set even if there are many Runner IDs that match winner IDs in the races table question number 19 is what are indexes in SQL indexes in SQL are just like having a shortcut to quickly find data in a table instead of searching through every Row one by one an index creates a sorted structure based on one or more columns making data retrieval much more easier for example you can think of an index in a book if you’re looking for a specific topic you can go to the index at the back and find the page number in stad flipping through every page similarly in database an index help the system quickly locate the rows you need so here’s how it works if you often search for customers by the name created an index will speed up those queries you can just write create index idx customer name on customer and then the customer name the database uses the index to find the row so you just have to run a query which is Select star from customers where name is John and then you can use the index to find a row with name is equals to John much faster let’s move on to question number 20 which is explain Group by in SQL the group by clause in SQL Will Group rows with the same values in a column allowing you to apply functions like sum count or average to each group for example in a sales table to find total sales by region you just simply have to write this query which is Select region some amount as total sales from Sales Group by region so the group the sales by region and calculates the total for each it’s a quick way to summarize data by categories so now let’s talk about question number 21 which is what is SQL Alias a SQL Alias is a temporary name you can give it to a table or a column in a query to make it easy to read or work with it’s like giving a nickname to something for clarity for example if you have a column named first name you can use an alias to rename it as first name in the query results you just simply have to write this query as select first name as first name in capital letter last name as last name from employe here the as keyword assign the Alias and the output will show The Columns as first name and last name aliases are also useful for tables so for this you can just write the code AS select e first name from Department table so this shortens table name for easier referencing alyses are not permanent they only exist while the query is running now let’s talk about the question number 22 which is explain orderby in SQL so you can answer this question like the order by clause in SQL is used to sort the result set of a query based on one or more columns you can specify each column sorting order ascending or descending for ascending you have to use ASC and for descending you have to use the ESC okay so just have to Simply write this query as select star from product order by Price DEC now let’s talk about question number 23 which is differences between where and having in SQL the where Clause is employed to restrict individual rows before they are grouped such as when filtering rows prior to a group by operation conversely the having Clause is utilized to filter groups of rows after they have been grouped like filtering groups based on aggregate values the having Clause it cannot be used without the group Clause whereas the where Clause specifies the criteria which individual records must mean the selected query it can be used with the group by Clause question number 24 is what is view in sec one more important question so and SQL view is essentially a virtual table that will derive its data from the outcome of a select query view serve multiple purposes including simplifying intricate queries enhancing data security through an added layer and enabling the presentation of targeted data subsets to users all while keeping the underlying table structur hidden now let’s move on to question number 25 which is what is a store procedure so if you asked this question just simply say a sequel stored procedure comprises of prec compiled SQL statements that can be executed together as a unified entity these procedures are commonly used to encapsulate business logic improve performance and also ensure consistent data manipulation practices that’s it now let’s move on to question number 26 which is one more important question which is what what is triggers in SQL a SQL trigger consists of a predefined sequence of actions that are executed automatically when a particular event occurs such as when an insert or delete operation is performed on a table triggers are employed to ensure data consistency conduct auditing and streamline various tasks so you can use insert trigger update Trigger or delete trigger accordingly now let’s talk about what are the aggregate functions and if you know them name a few it’s very easy to answer aggregate function and SQL perform calculations on a set of values and return a single result at first we have minimum which will get the minimum value from the resultant set then we have the max function which will give you the maximum value from the resultant set the sum will give you the sum of values from the resultant set average will give you the simple average of the resultant set and the count will count of numbers records from the resultant set now let’s talk about question number 28 which is how do you update a value in SQL the update statement serves the purpose of altering pre-existing records within a table it involves specifying the target from the update the specific columns to be modified and the desired new values to be applied for example if you want to update you can use Query like update employees set salary is equals to 6,000 where the department is ID now we’ll be moving on to some intermediate mediate SQL interview question and answers so one of the question is what is a self join and how would you use it I would like to repeat again these join types of question is very important these are often asked in interviews so talking about what is a self joint a self join and squ is a type of join where a table is joined with itself it’s useful for comparing rows with the same table or exploring hierarchal relationship such as finding employees and the managers in an organization so imagine if you have an employee table so you have employee ID name and the manager ID so if you want to find each employee and the manager you can use a self jooin you can just simply write a query as select e name as employee M name as manager from employee left join employees on manager so I’ve already discussed with you before what is the meaning of Left Right and self jooin so here the table joined with itself using manager ID to link each employee to the manager a self joint is helpful for comparing rows in the same table or working with hierarchial data so now let’s move on to question number 30 which is explain different types of joints with example at first we have inner joint the inner joint will gather rows that have matching values in both the tables then we have the right joint it will gather all the rows from the right table and any matching rows from the left table left join will gather all the rows from the left table and any matching rows from the right table and the full joint will gather all rows where there’s a match in either table including unmatched rows from both the tables very easy now let’s move on to question number 31 which is what is subquery and provide it using an example so subquery basically refers to a query that is embedded within another query serving the purpose of fetching information that will subsequently be employed as a condition or value within the encompassing out a query so you can just use this uh query which is Select name from employees where salary is greater than select average from salary from employees now the next question is how do you optimize SQL queries so basically the answer to this question would be something like SQL query optimization involves improving the performance of SQL queries by reducing resource usage and execution time strategies include using appropriate indexes optimizing very structured and avoiding cost operations like fully table scans now let’s talk about question number 33 which is what are correlated subqueries it’s a type of subquery that makes reference to columns from the surrounding outer query this subquery is executed repeatedly once for each row being processed by the outer query and its execution depends on the outcomes of the outer query now we’ll be talking about what is a transaction in SQL and it’s very important one of the most important question asked every time in SQL interview questions so basically a transaction in SQL is a group of one or more SQL commands that are treated as a single unit it ensures that all the operations in the group either succeed completely or fail entirely this guarantees the Integrity of the database imagine you’re transferring money from your bank account to a friend’s account that the bank first deducts the amount from your account account and then it adds the same amount to your friend’s account these two steps together form a transaction if one of these steps fails example the system crashes after deducting money from your account but before adding it to your friend’s account then the entire transaction is rolled back meaning no money is transferred and the database returns to its original state so you can also explain this question with the help of example that would be more you know clear to the interviewer now let’s talk about what are asset properties in SQL so basically asset stands for atomicity consistency isolation and durability and these are Key properties that ensures database transactions are reliable and maintain data Integrity atomicity you can think of it as All or Nothing a transaction is a single unit of work if any part of the transaction fails then the entire transaction is rolled back and no changes are made to the database for example if you’re transferring money between two accounts either both the debit and credit operations happen or neither does the second we’re going to talk about is consistency the database must always be in valid State a transaction takes the database from one valid state to another following all the rules and constraints for example if a transaction adds a record that violates a rule like a duplicate primary key then the transaction fails key keeping the database consistent isolation transactions don’t interfere with each other even if multiple transactions are running at the same time each transaction works as if it’s the only one happening example if you two people are updating the same record then one transaction will wait until the other is complete talking about durability once a transaction is committed it’s permanent even if there’s a power outage or system failure the data is saved and it won’t be lost after you complete an online purchase the transaction is stored securely even if the server crashes immediately after so this was for the asset properties and now we’ll be moving on to our next question which is how to you implement error handling in SQL error handling in SQL is a process to manage and respond to errors that occur during query execution different database system have specific ways to handle errors in SQL server the TR catch block is commonly used the tri block contains the main operation while the catch block handles errors if they occur for instance in a transaction you can use roll back in a catch block to undo changes if something goes wrong similarly in Oracle the exception block within PL SQL is used to handle errors if an error arises the exception block executes rolling back the transaction and the logging the error message by implementing error handling you ensure that operations fail gracefully without corrupting data making the database operations more reliable and secure next question which is describe the data types in SQL SQL supports various types of data types which Define the kind of data a column can hold these are broadly categorized into numeric character data type and binary types so we have numeric data types like integer float then we have character string like Car Bar we also have uni code character string like N N Text then we have binary which includes binary image date and time which includes date and date and time then we also have some miscellaneous data types which is XML and Json so the next question is explain normalization and denormalization often this question is asked in this way also or it could be asked something like explain the difference between normalization and denormalization so to answer this you have to just simply explain what normalization is which I have already discussed before once again I’m seeing you normalization and denormalization are ways to organize data in a database normalization is all about breaking big tables into smaller ones to remove duplicate data and improve accuracy for example instead of repeating customer details in every order you create one table for customers and another for orders linking them with a key denormalization on the other hand is when you combine or duplicate data to make it faster and retrieve for instance you might add customer details directly to the c table so that you don’t need to join tables during a query normalization help you space and maintain consistency while denormalization makes data retrieval quicker depending on what the database needs let’s move on to a next question which is what is a clustered index it’s very easy just simply answer by saying that a cluster index in SQL determines the phys physical order of the data rows in a table each table can have only one clustered index which impacts the table storage structure rows in a table are physically stored in the same order as the clustered index key now we have next question which is how do you prevent SQL injection so talking about this question SQL injection is a security risk where attackers insert harmful code into SQL queries potentially accessing or tampering it with your database to prevent this you can use parameterized queries or repair statements to handle the user input safely you can validate inputs to allow only expected values used store procedures to separate logic from data limit database permission non Escape special characters these steps help you secure that your database is free from SQL injection attacks the next question on the list is explain the concept of database schema in SQL a database schema functions as a conceptual container for housing various database elements such as tables views indexes and procedures its primary purpose is facilitate the organization and segregation of these databases elements while specifying their structure and interconnections next question is how we data Integrity insured in SQL just simply answer by saying that data Integrity in SQL is ensured through various means including constants example primary Keys foreign Keys check constants normalization trans actions and referential integrity constants as well these mechanism prevent invalid or inconsistent data from being stored in the database question number 42 which is what is an SQL injection we have already discussed about how we can protect our data from SQL injections so now let’s discuss what is basically a SQL injection so SQL injection in cyber security attack that involves insertion of malous SQL code into applications in input fields or parameters this unauthorized action enables attackers to illicitly access a database extract confidential information or manipulate the data the next question is how do we create a stored procedure you use the create procedure statement to create a stor procedure in SQL a stor procedure can contain SQL statements parameters and variables so here’s a very simple example you can just simply create by writing this query as create procedure get employ by ID add employee ID integer as begin select star from employees where employee ID is equals to add employee ID and then you have just have to write end that’s it so next question is what is a deadlock in SQL and how it can be prevented one more important question often asked an interview so you have to answer something by saying that a deadlock in SQL happens when two or more transactions are stuck because they are waiting for each other to release resources it’s just like two people trying to go through a narrow door at the same time each refusing to step back and let the other pass transaction a locks table one and weights to access table two transaction B locks table two and weights to access table one this is just a simple example so we can see that both the transactions are waiting for each other neither can proceed creating a deadlock so it’s very simple and how we can prevent this deadlock is by locking hierarchies always access resources in the same order so that transactions don’t block each other timeouts set a time limit for transaction to wait out for the resources you can also use deadlock detection and resolution system to detect Deadlocks and cancel one transaction and let the other proceed now let’s move on to a last question on the list which is difference between in and exist in basically works on list result set it doesn’t work on subqueries creating a virtual table with multiple columns Compares every value in the result list performance is comparatively slow of a large result set of subquery whereas the exist works on Virtual tables it is used with correlated queries exist comparison when matches found and the performance is comparatively fast for larger result set of subquery so guys that’s it for this video on the top 45 SQL interview question asked in SQL interviews ever wondered how seems to know exactly what you want before you do that’s the magic of data analytics imagine you’re shopping for a camera and suddenly Amazon suggests the perfect lens tripod and memory card all before you even think of them it’s not magic but the power of analyzing massive data sets to track what millions of Shoppers like you search for and buy together this helps Amazon create a personalized shopping experience that boosts sales and keeps your coming back from predicting Trends to fine-tuning their stock Talk data analyis is a secret Source behind their seamless shopping experience hey everyone welcome back to Simply n’s YouTube channel today we have got an exciting topic lined up the top 10 data analytics certifications I will be walking you through the expanding scope and financial growth of data analytics worldwide why pursuing a data analytic certification is essential and finally the top 10 data analytics certifications that can supercharge your carrier that can open doors to exciting opportunities let’s Dive In and explore the world of data analytics together now let us explore the expanding scope and the financial growth of data analytics the scope of data analytics is worst promising Financial growth and Rising salaries for data analytics scientists and Engineers as Industries digitalize demand surges and finance for fraud detection healthc care for predictive diagnosis retail for personalized marketing and Manufacturing for productive maintenance Innovations like augmented analytics and realtime processing enhances importance companies like Google Amazon Microsoft and IBM consistently higher analytics experts in India entry level salaries range from 4 to six lakhs with perom with experienced professionals earning 10 to 20 lakhs perom in USA entry level salaries are1 60,000 to1 80,000 with experience roles at do$ 100,000 to1 15,000 plus the future promises greater advancements making data analytics a lucrative field with work potential now let us see why is pursuing a data analytics certification essential pursuing a data analytics certification is crucial as it validates your expertise boost your credibility and lights up your resume in a competitive job market certifications provide you with in demand skills like data visualization statistical analysis and machine learning keeping you current with the industry Trends they can lead you to paying high paying job roles and career growth as employers favor certified Professionals for job data driven positions whether you’re starting or advancing your career or certification showcases your commitments and skills enhancing job prospects in fields like Finance Healthcare retail and Tech as well so all right guys the moment you have been waiting for is here it’s time to reveal the top data analytics certifications by simply learn buckle up and let’s dive into this carrier boosting programs that will set you on the path of success coming to the number one that is a post-graduate program in data analytics boost your career with simply Lars postgraduate program ineda analytics offered in partnership with bir University and in collaboration with IBM this comprehensive 8mon live online course is perfect for professionals from any background and covers crucial skills like data analysis visualization and supervised learning using python R SQL and powerbi the program features master classes by Purdue faculty and IBM experts Hands-On projects with real world data sets from Google Play Store lift and more and exclusive hackathons and AMA sessions receive joint certifications from Padu and simply learn IBM recognized certificates and benefit from carrier Support Services like resum building and job assistance through simply learns job assist no prior experience required just a bachelor’s degree with at least 50% marks is required enroll now to gain industry relevant experience and stand out to the top employers like Google and Amazon to check for the coast Link in the description box and pin comments below now moving on to the number two that is calch postgraduate progr in data science Advance your career with simply learns postgraduate program in data science in collaboration with calch ctme and IBM this comprehensive 11 month live online course covers essential skills and tools including python machine learning data visualization generative AI promt engineering chat juty and more with master classes by Caltech instructors and IBM experts you will G hands-on experience to 25 plus industy Rel projects Capstone projects across three romens and seamless access to integrated Labs on a tees program completion certificate and up to 14 counting education units from CTIC ctme along with the NY recognized IBM certificates enhance your career with job assistance master classes and exclusive hackathons with no prior work experience required this program is suitable for professionals from any background who hold a bachelor’s degree enroll now to become a data science expert and stand out to top employers to check for the course Link in the description box below and pin comments now moving on to the number third that is professional certificate programming data analytics and generative Advance your career with professional certificate program in data analytics and generative AI by simply learn in collaboration with E and ICT Academy IIT goti and IBM this comprehensive 11mon live online program is designed to equip you with cutting a skills in data analytics and generative AI covering essential tools like SQL Excel python W power VI and more learn from distinguished I faculty and IBM experts through interactive master classes Hands-On projects and Capstone experiences gain practical expertise with exposure to jni tools such as chaty and Gemini and earn industry recognized certifications from IVM along with the executive alumni status from I goti enhance your Professional Profile with simply learn job assess resume building and job placement support to get noticed by the top hiring companies enroll now to elevate your career and join network of Industry leaders do check for the co Link in the description box below and pin comments moving on to the number four that is professional certificate course in D s Master data science with a professional certificate course in data science by simply learn in collaboration with ICT Academy I kpur this comprehensive 11 month live online program equips with essential skills and tools such as python power BW chat jity and more benefit from the master classes delivered by distinguished IIT kpur faculty gain practical experience with 25 plus Hands-On projects and access integrated La for real world training with dedicated modules on generative AI prompt engineering and explainable AI you will stay ahead in the rapidly evolving AI landscape ear a prestigious program completion certificate from E and ICT Academy IIT kpur and take advantage of Simply Lars job asset to enhance your Professional Profile and stand out to recruiters apply now to enhance your career in data science and AI do check for the course Link in the description box below and pin comments now moving on to the fifth one that is the postgraduate program in data science supercharge your career with the postgraduate program in data science by simply learn in collaboration with bird University and IBM ranked as the number one data science program by Economic Times this 11 month live online program equips with with the in demand skills including python machine learning deep learning NLP data visualization generative Ai and chargeability benefit from the master classes led by Purdue faculty and IBM experts engageing Hands-On training with 25 plus projects and free Capstone projects and gain access to Industry leading tools such as T flow carers powerbi and more earn dual certificates from perue University online and IBM boosting your Professional Profile and carrier prospects the simply learns job assess receive guidance and resume support to stand out to the top employers applications close on November 8 2024 and enroll now to transform your career in data science and AI to check for the course Link in the description box below and pin comments now moving on to the sixth one that is applied Ai and data science Advance your career with applied Ai and data science program offered by Brown University’s School of Professional studies and collaboration with simply learn this 14 week CPL program empowers you with essential skills in AI generative Ai and data science including handson learning and Industry Rel projects learn from Steam Brown faculty through top not video content and monthly live master classes covering tools and Concepts such as python machine learning neural lent walking and jpt models benefit from a curriculum design to refine your expertise supported by integrated labs and exclusive content on generative AI andn a prestigious certificate of completion from Brown University and a credly badge upon program completion enhance your profile with simply L job asset resumee building support and exclusive I IM job membership to stand out in today’s competitive job market enroll now to gain The Cutting age knowledge and take your carrier in Ai and data science to the next level do check for the course Link in the description box below and pin comments now moving on to the next that is the data analyst elevate your career with simplys data analyst certification rank number one by carrier Karma this comprehensive 11 month program is designed to transform you into a data analytic expert with practical training and SQL R python data visualization and predictive analystics learn through live interactive classes Capstone projects and 20 plus Hands-On projects that ensure Real World Experience G industry recognized certifications from Simply learn and IBM access exclusive master classes and am sessions by IBM experts and receive dedicated job assistance to help you stand out to the top employers like Amazon Microsoft and Google start your journey to becoming a data analytics professional today with simply learns trusted and robust training program to check for the course Link in the description box below and pin comments now moving on to the next one that is data scientist Advance your career with simply learns industry leading data scientist certification program now ranked number one by carer Karma this 11 month course in collaboration with IBM equips you with the essential data science skills including python SQL machine learning generative Ai and W gain practical Real World experience to 25 plus Hands-On projects and a Capstone project benefit from master classes by IBM experts interactive live sessions led by industry professionals and lifetime access to the self placed learning content simply lears job assess program further boost your carer prospects helping you stand out to thep employers like Amazon Microsoft and Google to check for the course Link in the description box below and pin comments now moving on to the second last one that is the professional certificate program in data engineering launch your data engineering career with simply launch professional certificate program in data engineering offered in partnership with P University online this 32e program accuses with the indman skills covering python SQL nosql Big Data AWS Azure and snowflake fundamentals aligned with industry recognized certifications like AWS certified data engineer Microsoft 203 and snow Pro core this course ensures comprehensive learning through live online classes practical projects and a Capstone experience gain access to puru Alumni Association exclusive master classes and simplys job asset for carer support join now to become a certified data engineer and FASTT trck eradio to high impact roles in the field do check for the course Link in the description box below and pin comments now moving on to the last but not Le is Microsoft certified as your data engineer associate dp23 Advanced your carer will simply learns Microsoft certified Azure data engineer associate dp23 training aligned with official certification Master essential Azure skills like data integration transformation and storage while gaining hands-on experience with the key services such as Azure signups analytics data Factory and Azure data braas benefit from live online classes led by Microsoft certified trainers access to official Microsoft handbooks practice lab and comprehensive practice test to help you excellent dp23 exam this course designed for real world application ensures you develop job ready skills and earn a official course completion batch hosted on the Microsoft learn portal enroll now to elevate your data engineering expertise do check for the course Link in the description box below and pin comments so getting a data analytic certification can be a game changer for your growth however choosing the right certification is crucial it’s like finding the perfect key to unlock your potential select the one that best aligns with your career goals and S SK to maximize your journey in data analytics so that’s a WRA so that concludes our SQL full course if you have any doubts or question you can ask them in the comment section below our team of experts will reply you as soon as possible thank you and keep learning with simply staying ahead in your career requires continuous learning and upscaling whether you’re a student aiming to learn today’s top skills or a working professional looking to advance your career we’ve got you covered explore our impressive catalog of certification programs in cuttingedge domains including data science cloud computing cyber security AI machine learning or digital marketing designed in collaboration with leading universities and top corporations and delivered by industry experts choose any of our programs and set yourself on the path to Career Success click the link in the description to know more hi there if you like this video subscribe to the simply learn YouTube channel and click here to watch similar videos to nerd up and get certified click here

    By Amjad Izhar
    Contact: amjad.izhar@gmail.com
    https://amjadizhar.blog

  • Beauty Experts Say You Should Never Make These 50 Common Mistakes

    Beauty Experts Say You Should Never Make These 50 Common Mistakes

    When it comes to beauty, even the smallest mistakes can have lasting consequences. Many people unknowingly sabotage their skincare, haircare, and makeup routines by following outdated advice or skipping essential steps. The result? Premature aging, hair damage, and ineffective products that fail to deliver the desired results. To maintain a radiant and youthful appearance, it’s crucial to learn from the experts and avoid these common beauty blunders.

    Beauty professionals stress that a well-informed approach to self-care makes all the difference. From using the wrong skincare ingredients to applying makeup incorrectly, minor missteps can undermine your efforts. Renowned dermatologist Dr. Whitney Bowe notes, “Your skin is a reflection of your overall health and habits.” This means that understanding proper techniques and choosing high-quality products tailored to your needs is essential for achieving long-term beauty goals.

    By steering clear of these 50 common beauty mistakes, you’ll not only enhance your natural glow but also protect yourself from unnecessary damage. Whether it’s over-exfoliating, neglecting sunscreen, or using the wrong hair treatments, small changes in your routine can lead to significant improvements. Let’s dive into these expert-backed tips to ensure your beauty regimen is working for you—not against you.


    1 – Letting Brassy Tones Mess With Your Blonde Color

    Nothing ruins a gorgeous blonde shade faster than brassy, yellow undertones. Many people assume that simply using a purple shampoo will fix the problem, but the reality is more complex. Brassiness often occurs due to sun exposure, hard water, or the natural fading of hair dye. Celebrity colorist Tracey Cunningham advises incorporating a color-protecting treatment into your routine and limiting heat styling to maintain the integrity of your blonde.

    To keep your blonde looking fresh, opt for a sulfate-free shampoo designed for color-treated hair. Additionally, consider using a blue or violet-toned mask once a week to counteract any unwanted warmth. Hairstylists also recommend rinsing your hair with filtered water or using a showerhead filter to reduce mineral buildup. By implementing these preventive measures, you can keep your blonde locks vibrant and salon-fresh.


    2 – Letting Reddish Tones Mess With Your Brunette Color

    Brunettes often struggle with unwanted red or orange undertones, especially after repeated exposure to heat styling and environmental pollutants. Many people don’t realize that their hair care routine could be exacerbating the issue. Using the wrong shampoo or excessive heat tools can strip cool-toned pigments from brown hair, leaving behind an unflattering reddish hue.

    To maintain the depth and richness of brunette hair, experts suggest incorporating a blue-tinted shampoo to neutralize warmth. Investing in heat protectant sprays and minimizing direct sun exposure can also prevent color shifts. For an extra layer of protection, hairstylists recommend scheduling gloss treatments every few weeks to refresh and enhance your natural or dyed brunette shade.

    3 – Applying Your Body Self-Tanner to Your Face

    Many people make the mistake of using their body self-tanner on their face, leading to clogged pores, breakouts, and an uneven complexion. Body tanners are often formulated with heavier ingredients that can be too harsh for delicate facial skin. Dermatologist Dr. Hadley King warns that “self-tanners designed for the body often contain higher concentrations of DHA, which can lead to excessive dryness and irritation when applied to the face.”

    To achieve a natural, sun-kissed glow without damaging your skin, opt for a self-tanner specifically formulated for facial use. These formulas are typically non-comedogenic and infused with hydrating ingredients like hyaluronic acid and vitamin E. Additionally, applying a lightweight moisturizer before self-tanner can help create a more even finish and prevent patchiness.


    4 – Over-Exfoliating With Physical Scrubs

    Exfoliation is key to a glowing complexion, but too much of a good thing can be harmful. Many people overuse harsh physical scrubs, leading to micro-tears in the skin, increased sensitivity, and premature aging. Board-certified dermatologist Dr. Shereene Idriss explains, “Over-exfoliating disrupts the skin barrier, making it more susceptible to inflammation and irritation.”

    Instead of scrubbing aggressively, switch to a gentler exfoliation routine. Experts recommend using chemical exfoliants, such as glycolic or lactic acid, which dissolve dead skin cells without causing abrasions. If you prefer physical exfoliation, opt for a fine-grain scrub and limit usage to two to three times per week. Protecting your skin barrier ensures a smoother, more radiant complexion in the long run.


    5 – Relying on the SPF in Your Makeup Products

    Many people believe that using foundation or powder with SPF is enough to protect their skin from harmful UV rays, but this is a dangerous misconception. According to the Skin Cancer Foundation, “most cosmetic products with SPF do not provide sufficient coverage unless applied in very thick layers, which is unrealistic.”

    For proper sun protection, always apply a broad-spectrum sunscreen with at least SPF 30 underneath your makeup. Look for lightweight, non-greasy formulas that layer well with other skincare and makeup products. Reapplying sunscreen throughout the day—especially when spending time outdoors—is also essential to prevent sun damage and premature aging.


    6 – Skipping Toning After Cleansing

    Toner is often seen as an optional step, but skipping it can leave your skin unbalanced and vulnerable to irritation. After cleansing, your skin’s pH levels can become disrupted, making it more prone to dryness, oiliness, or breakouts. Skincare expert Dr. Dennis Gross explains, “A well-formulated toner helps restore balance, tighten pores, and enhance the effectiveness of the rest of your skincare routine.”

    To reap the benefits, choose an alcohol-free toner suited to your skin type. Hydrating toners with ingredients like rose water or glycerin help soothe dry skin, while clarifying toners with witch hazel or salicylic acid are ideal for oily and acne-prone skin. Incorporating toner into your routine ensures your skin stays balanced and prepped for serums and moisturizers.


    7 – Layering Setting Powder on Dry Skin

    Using setting powder can help makeup last longer, but when applied to dry skin, it often accentuates fine lines and flakiness. Many people make the mistake of layering powder without properly prepping their skin, leading to a cakey, dull appearance. Makeup artist Bobbi Brown advises, “The key to flawless makeup is hydration—powder should enhance, not highlight dryness.”

    To avoid this issue, start with a well-moisturized base. Apply a hydrating primer before foundation and use a light hand when applying setting powder. Opt for finely milled, translucent powders that set makeup without settling into lines. Additionally, using a damp beauty sponge instead of a brush can help distribute powder more evenly for a natural, smooth finish.

    8 – Over-Cleansing Oily Skin

    Many people with oily skin believe that washing their face multiple times a day will control excess oil, but this can actually have the opposite effect. Over-cleansing strips the skin of its natural oils, triggering the sebaceous glands to produce even more oil as a defense mechanism. Dermatologist Dr. Joshua Zeichner explains, “When you over-cleanse, your skin tries to compensate by producing more oil, leading to breakouts and irritation.”

    To maintain a balanced complexion, use a gentle, sulfate-free cleanser no more than twice daily. Look for ingredients like niacinamide or salicylic acid, which help regulate oil production without over-drying the skin. If your skin feels tight or uncomfortable after cleansing, you may need to switch to a more hydrating formula to support your skin barrier.


    9 – Removing Mascara With Cotton Pads

    Using cotton pads to remove mascara may seem harmless, but it can cause unnecessary tugging on the delicate eye area, leading to premature wrinkles and lash breakage. The friction created by rubbing back and forth can also irritate the skin and leave behind mascara residue. Skincare expert Dr. Dendy Engelman warns, “The eye area is the first place to show signs of aging, so it’s crucial to treat it gently.”

    Instead of cotton pads, opt for a gentle, oil-based makeup remover or micellar water on a reusable microfiber cloth. Apply the remover to closed eyes, let it sit for a few seconds to break down the mascara, then gently wipe away without rubbing. This method protects your lashes and the sensitive skin around your eyes while effectively removing all traces of makeup.


    10 – Skipping Moisturizer on Oily or Acne-Prone Skin

    Many people with oily or acne-prone skin believe that skipping moisturizer will prevent breakouts, but this is a major skincare mistake. When the skin lacks hydration, it compensates by producing even more oil, potentially leading to clogged pores and acne flare-ups. Dermatologist Dr. Whitney Bowe explains, “Moisturizing is essential—even for oily skin—because it helps maintain the skin barrier and prevents overproduction of sebum.”

    To keep your skin hydrated without feeling greasy, choose a lightweight, oil-free moisturizer with ingredients like hyaluronic acid, glycerin, or niacinamide. These components provide hydration while regulating oil production and soothing inflammation. Using the right moisturizer ensures your skin remains balanced, reducing excess shine and breakouts over time.


    11 – Over-Using a Purple Shampoo

    Purple shampoo is a go-to product for blondes looking to neutralize brassy tones, but using it too often can lead to unintended consequences. Overuse can result in dry, brittle hair or even leave a purple tint behind. Celebrity hairstylist Kristin Ess advises, “Purple shampoo should be used strategically—too much can make your hair look dull or even slightly violet.”

    To maintain a bright, healthy blonde, limit purple shampoo use to once or twice a week. On other days, use a hydrating, color-safe shampoo to keep hair nourished and prevent excessive dryness. If brassiness persists, consider a salon-grade toner or gloss treatment to refresh your color without overloading your strands with pigment.


    12 – Applying Makeup Without Prepping Your Skin

    Applying makeup to unprepped skin can lead to an uneven application, cakiness, or patchiness throughout the day. Skipping essential skincare steps, such as cleansing, moisturizing, and priming, can cause foundation and concealer to settle into fine lines and dry patches. Renowned makeup artist Charlotte Tilbury emphasizes, “Flawless makeup starts with great skincare—prepping the skin ensures a smooth, radiant finish.”

    To create the perfect canvas, start with a clean face, followed by a lightweight moisturizer that suits your skin type. Apply a primer to address specific concerns, such as oil control, hydration, or pore filling. Proper skin preparation enhances makeup longevity and ensures a more polished, professional-looking result.


    13 – Getting Pricey Hair Extensions

    High-quality hair extensions can be a great way to add volume and length, but investing in expensive ones without proper maintenance can be a waste of money. Many people assume that once extensions are installed, they require little upkeep, but neglecting care can lead to tangling, breakage, and an unnatural appearance. Hair expert Jen Atkin notes, “Even the best extensions will look bad if they’re not properly maintained—regular conditioning and gentle handling are key.”

    Instead of splurging on costly extensions, consider clip-ins or tape-ins that are easier to maintain. Always use sulfate-free shampoos, detangle gently with a wide-tooth comb, and avoid excessive heat styling. Proper care ensures your extensions blend seamlessly with your natural hair and last longer, making them a worthwhile investment.


    14 – Picking at Your Pimples

    Popping pimples may offer temporary satisfaction, but it often leads to long-term damage such as scarring, hyperpigmentation, and even infections. Squeezing blemishes pushes bacteria deeper into the skin, increasing inflammation and delaying the healing process. Dermatologist Dr. Sandra Lee, better known as Dr. Pimple Popper, warns, “Picking at a pimple is like playing with fire—you’re almost guaranteed to make it worse.”

    Instead of squeezing blemishes, use a spot treatment with benzoyl peroxide, salicylic acid, or tea tree oil to reduce inflammation and speed up healing. Hydrocolloid patches are also an effective way to protect the pimple while drawing out impurities. Practicing patience and proper skincare will prevent unnecessary skin damage.


    15 – Laying Out in the Sun to Tan

    Sunbathing for a golden tan may seem appealing, but prolonged sun exposure significantly increases the risk of premature aging and skin cancer. UV rays break down collagen and elastin, leading to wrinkles, sunspots, and loss of skin elasticity. The American Academy of Dermatology warns, “There’s no such thing as a safe tan—every exposure to UV rays contributes to skin damage.”

    Instead of tanning under the sun, opt for self-tanners or spray tans to achieve a sun-kissed glow without the harmful effects. If you’re spending time outdoors, always wear broad-spectrum SPF 30 or higher, seek shade, and use protective clothing. Keeping your skin safe from UV damage is one of the best ways to maintain a youthful appearance.

    16 – Using the Same Face Towel All Week

    Reusing the same face towel for days may seem harmless, but it can lead to a buildup of bacteria, dirt, and dead skin cells. Each time you dry your face, you’re potentially reintroducing impurities that can clog pores and trigger breakouts. Dermatologist Dr. Mona Gohara explains, “A damp towel is a breeding ground for bacteria, which can exacerbate acne and skin irritation.”

    To maintain clear, healthy skin, switch to a clean towel every couple of days. Consider using soft, microfiber cloths that are gentle on the skin and dry quickly. For an even more hygienic approach, let your face air dry or use disposable facial tissues to pat dry, reducing bacterial contamination.


    17 – Reserving Lip Balm for Daytime Use Only

    Many people apply lip balm only during the day, neglecting their lips at night. However, lips lose moisture while you sleep, leading to dryness and cracking. Skincare expert Dr. Debra Jaliman states, “Your lips don’t have oil glands, so they need extra hydration overnight to stay smooth and healthy.”

    To keep your lips soft, apply a nourishing lip mask or balm before bed. Look for formulas containing shea butter, ceramides, or hyaluronic acid for deep hydration. Regular nighttime application will ensure your lips remain plump and protected, even in harsh weather conditions.


    18 – Sleeping on a Cotton Pillowcase

    Cotton pillowcases absorb oils, bacteria, and product residue, which can lead to skin irritation and hair frizz. The friction from cotton fabric can also contribute to premature wrinkles and moisture loss. Skincare expert Dr. Howard Sobel explains, “Sleeping on a cotton pillowcase can create creases on the skin that, over time, turn into permanent wrinkles.”

    Switching to a silk or satin pillowcase can reduce friction, prevent hair breakage, and help retain skin moisture. Silk’s smooth texture allows your skin to glide effortlessly, reducing the risk of fine lines. This small change in your sleep routine can make a big difference in the overall health of your skin and hair.


    19 – Attempting to Treat Body Acne With a Traditional Scrub

    Many people assume that using a physical scrub will help clear body acne, but aggressive exfoliation can worsen irritation and inflammation. Scrubbing can cause microtears in the skin, spreading bacteria and making breakouts more severe. Dermatologist Dr. Angela Lamb advises, “Instead of scrubbing, use a chemical exfoliant like salicylic acid or benzoyl peroxide to treat body acne effectively.”

    For best results, opt for a body wash with acne-fighting ingredients like glycolic acid or tea tree oil. Follow up with a lightweight, non-comedogenic moisturizer to keep your skin balanced. Gentle, consistent care is the key to treating body acne without causing further damage.


    20 – Wasting Money on Expensive Acne Treatments

    Expensive acne products may promise miraculous results, but price doesn’t always equate to effectiveness. Many high-end treatments contain the same active ingredients as affordable alternatives. Skincare expert Dr. Sandra Lee notes, “It’s not about the brand or price—it’s about the ingredients that actually work.”

    Instead of splurging on luxury products, look for dermatologist-recommended ingredients like salicylic acid, benzoyl peroxide, and retinoids. Over-the-counter treatments from reputable brands can be just as effective as high-end options. Investing in a solid skincare routine rather than overpriced products will yield better long-term results.


    21 – Not Taking Care of Your Cuticles

    Ignoring cuticle care can lead to dryness, hangnails, and infections. Many people pick at their cuticles or neglect them entirely, weakening the nail bed. Celebrity nail artist Deborah Lippmann explains, “Your cuticles protect your nails from bacteria—trimming them too much or leaving them dry can cause long-term damage.”

    To keep cuticles healthy, apply cuticle oil daily and gently push them back instead of cutting them. Using a hydrating hand cream can also prevent peeling and cracking. Proper cuticle care not only keeps nails looking polished but also supports their overall strength and growth.


    22 – Tying Your Hair Back With a Tight Elastic

    Constantly pulling your hair back into a tight ponytail or bun can lead to breakage and traction alopecia—a form of hair loss caused by prolonged tension on the scalp. Trichologist Anabel Kingsley warns, “Repeatedly wearing tight hairstyles weakens hair follicles and can result in permanent hair thinning.”

    Opt for silk scrunchies or spiral hair ties, which are gentler on the hair. Switching up your hairstyle and avoiding excessive tension will protect your strands from unnecessary damage. If you must wear your hair up, keep it loose and alternate styles to reduce stress on the scalp.


    23 – Forgetting to Apply Sunscreen to Your Lips

    Many people apply sunscreen to their face but forget their lips, leaving them vulnerable to sunburn and premature aging. The delicate skin on the lips lacks melanin, making it more susceptible to UV damage. Dermatologist Dr. Elizabeth Hale states, “Lip cancer is more common than people realize—using SPF lip balm daily is a simple yet essential step.”

    To protect your lips, use a lip balm with SPF 30 or higher and reapply throughout the day. Look for formulas with nourishing ingredients like shea butter and antioxidants to provide extra hydration and protection. Keeping your lips shielded from the sun will prevent discoloration, dryness, and long-term damage.


    24 – Washing Your Hair With Hard Water

    Hard water contains minerals like calcium and magnesium, which can build up on the scalp and hair, leading to dryness, dullness, and breakage. Over time, these minerals create a film that prevents moisture from penetrating the hair shaft. Celebrity hairstylist Kristin Ess explains, “Hard water can strip hair color and leave it looking lifeless—using a water filter or clarifying shampoo helps remove buildup.”

    If you live in an area with hard water, invest in a shower filter to reduce mineral deposits. Using a clarifying shampoo once a week and following up with a deep conditioner can help restore hydration and shine. Regular maintenance will keep your hair looking vibrant and healthy despite the effects of hard water.


    25 – Not Protecting Your Hair When You Use Hot Tools

    Frequent heat styling without protection can cause severe hair damage, leading to split ends and weakened strands. Heat tools strip moisture from the hair, making it more prone to breakage. Hairstylist Jen Atkin emphasizes, “Using heat without protection is like sunbathing without sunscreen—it’s a guaranteed way to damage your hair.”

    Before using any hot tools, always apply a heat protectant spray or serum. Opt for lower heat settings and avoid excessive use of straighteners and curling irons. Incorporating heat-free styling techniques, like braids or rollers, can help preserve your hair’s health while still achieving beautiful styles.

    26 – Using Cotton Rounds to Apply Toner

    Cotton rounds may seem like a convenient way to apply toner, but they absorb too much product, leading to unnecessary waste. Additionally, the rough texture can irritate sensitive skin, especially when applying active ingredients like glycolic acid or salicylic acid. Skincare expert Dr. Shereene Idriss advises, “Switching to hands or reusable applicators ensures your skin gets the full benefit of your toner without unnecessary friction.”

    Instead of cotton rounds, try patting toner directly onto your skin with clean hands or using a reusable, soft microfiber pad. This method enhances absorption and ensures you’re not wasting valuable skincare products. Plus, it’s a more eco-friendly approach that reduces disposable waste.


    27 – Not Cleaning Your Makeup Brushes Enough

    Dirty makeup brushes harbor bacteria, oil, and old product buildup, which can lead to breakouts and skin infections. Many people go weeks or even months without washing their brushes, unknowingly exposing their skin to harmful microbes. Dermatologist Dr. Ava Shamban warns, “Unwashed brushes can contribute to acne, irritation, and even eye infections if not cleaned regularly.”

    To keep your brushes hygienic, wash them at least once a week using a gentle brush cleanser or mild shampoo. Rinse thoroughly and let them air dry on a clean towel. Regular cleaning not only protects your skin but also extends the lifespan of your brushes, ensuring flawless makeup application.


    28 – Not Cleaning Your Facial Ice Roller

    Facial ice rollers are great for reducing puffiness and soothing inflammation, but they can quickly become a breeding ground for bacteria if not cleaned properly. Many people store their rollers in the freezer without washing them after each use, increasing the risk of transferring germs onto their skin. Dr. Whitney Bowe emphasizes, “Any skincare tool that touches your face should be cleaned regularly to prevent bacterial buildup.”

    To maintain hygiene, clean your ice roller after every use with a gentle soap or disinfectant wipe. Store it in a clean container or zip-lock bag in the freezer to avoid contamination. Keeping your tools clean ensures they remain effective and safe for daily use.


    29 – Steaming Acne-Prone Skin

    While facial steaming can feel relaxing, it’s not always beneficial for acne-prone skin. The heat can dilate blood vessels and increase inflammation, making breakouts worse rather than better. Dermatologist Dr. Ranella Hirsch explains, “Steaming can actually exacerbate acne by increasing redness and swelling, especially for those with sensitive skin.”

    Instead of steaming, opt for gentle exfoliation with chemical exfoliants like AHAs or BHAs to unclog pores. If you enjoy steaming, limit it to once a week and follow with a soothing mask to minimize irritation. Moderation is key to preventing unnecessary skin flare-ups.


    30 – Dermaplaning With a Mini Razor

    Dermaplaning removes peach fuzz and dead skin cells, but using a mini razor at home without proper technique can lead to nicks, irritation, and even infections. Many people use dull blades or apply too much pressure, damaging their skin barrier. Aesthetician Kerry Benjamin warns, “DIY dermaplaning can be risky if not done correctly—professional treatments are safer and more effective.”

    If you choose to dermaplane at home, use a sterilized, single-use razor and glide it gently at a 45-degree angle. Follow up with a hydrating serum to soothe the skin. However, for the best results, consider getting professional dermaplaning treatments that ensure safety and effectiveness.


    31 – Washing Your Hair Too Often

    Daily hair washing may seem like a good hygiene practice, but over-washing strips the scalp of its natural oils, leading to dryness and increased oil production. This cycle can cause hair to become brittle or excessively greasy. Hair expert Philip Kingsley explains, “Washing too frequently disrupts the scalp’s natural balance, making it harder to maintain healthy hair.”

    Try washing your hair every two to three days, or even less if you have dry or curly hair. Use dry shampoo between washes to absorb excess oil and refresh your scalp. Finding the right balance will keep your hair nourished while preventing unnecessary damage.


    32 – Applying a Shimmery Highlighter to Your Skin

    Shimmery highlighter can add a radiant glow, but overuse or incorrect placement can emphasize fine lines, texture, and pores. Many people apply too much product, making their skin look oily rather than luminous. Celebrity makeup artist Bobbi Brown advises, “A little highlighter goes a long way—strategic placement is key to achieving a natural glow.”

    For a flattering look, apply a light dusting of highlighter to the high points of your face, such as the cheekbones and brow bones. Choose a finely milled formula that blends seamlessly into the skin. Avoid glittery or chunky formulas that can appear unnatural under different lighting conditions.


    33 – Using Powder to Touch Up Oily Skin

    Reapplying powder throughout the day may seem like a quick fix for oily skin, but it can lead to a cakey, heavy finish. Layering powder on top of oil buildup can also clog pores and cause breakouts. Skincare expert Dr. Dennis Gross recommends, “Instead of piling on powder, use blotting papers to absorb excess oil without disrupting your makeup.”

    If you need to refresh your makeup, opt for a mattifying setting spray or a light dusting of translucent powder. Applying powder only to specific areas, like the T-zone, will help control shine without overloading the skin with product.


    34 – Relying on Poor Lighting While Doing Your Makeup

    Applying makeup in dim or artificial lighting can lead to mismatched foundation, unblended contour, or overly heavy application. Many people don’t realize how different their makeup looks in natural light until they step outside. Makeup artist Lisa Eldridge emphasizes, “Good lighting is essential for achieving a seamless, natural-looking makeup application.”

    To avoid makeup mishaps, apply your makeup near a window with plenty of natural light. If that’s not possible, invest in a well-lit vanity mirror with adjustable LED settings. Proper lighting ensures your makeup looks flawless in all settings.


    35 – Layering on Self-Tanner Without Exfoliating First

    Skipping exfoliation before applying self-tanner can result in an uneven, streaky application. Dead skin cells cause the tanner to cling to dry patches, creating dark spots and an unnatural finish. Tanning expert Jules Von Hep explains, “Exfoliating beforehand ensures an even canvas, allowing the tan to develop smoothly.”

    Before self-tanning, use a gentle body scrub or exfoliating mitt to slough off dead skin. Focus on rough areas like elbows, knees, and ankles. Applying a lightweight moisturizer beforehand can also help prevent patchiness, leading to a more natural-looking tan.


    36 – Always Buying Full-Size Mascaras

    Mascara has a short shelf life, and using an old tube can lead to eye infections or irritation. Many people invest in full-size mascaras only to have them dry out before they’re fully used. Ophthalmologist Dr. Diane Hilal-Campo warns, “Mascara should be replaced every three months to prevent bacterial buildup that can cause eye issues.”

    Instead of buying full-size mascaras, consider purchasing travel-size versions. These are more affordable, allow you to try different formulas, and reduce product waste. Regularly replacing mascara ensures a fresh, clump-free application while keeping your eyes safe.

    37 – Loading Your Hair Up With Product to Add Volume

    Applying too much volumizing product can weigh hair down rather than lift it. Many people mistakenly think that more mousse, spray, or dry shampoo will create lasting volume, but overuse can lead to buildup, making hair feel greasy and lifeless. Hairstylist Jen Atkin advises, “Less is more when it comes to volumizing products—layering lightly creates movement without stiffness.”

    For best results, start with a small amount of product and focus on the roots. Blow-drying with a round brush or using velcro rollers can also boost volume without excessive product use. Regular clarifying treatments help remove buildup, keeping your hair bouncy and fresh.


    38 – Faking Fuller Lips With a Capsaicin-Infused Gloss

    Capsaicin, the active ingredient in chili peppers, is often found in plumping lip glosses to create a temporary swelling effect. However, these formulas can cause irritation, redness, and long-term dryness. Dermatologist Dr. Whitney Bowe warns, “Frequent use of capsaicin-based plumpers can lead to lip sensitivity and dehydration over time.”

    For a safer, more natural approach, try exfoliating your lips to enhance their fullness or use hydrating lip masks. Opt for peptides or hyaluronic acid-infused lip treatments that provide a plumping effect without irritation. Overlining with a lip liner can also create the illusion of fuller lips without discomfort.


    39 – Using Dry Shampoo That Quite Literally Dries Your Hair Out

    Dry shampoo is a lifesaver on busy days, but excessive use can strip the scalp of natural oils and cause buildup. Many aerosol formulas contain alcohol, which can dry out both the scalp and hair, leading to breakage. Trichologist Bridgette Hill explains, “Overuse of dry shampoo can clog hair follicles, causing scalp issues and dull strands.”

    To prevent damage, limit dry shampoo use to once or twice a week. Opt for formulas with nourishing ingredients like rice starch or oat milk, which absorb oil without dehydrating the scalp. Regularly washing your hair and massaging the scalp ensures a healthy balance of natural oils.


    40 – Only Flossing When You See Food Between Your Teeth

    Flossing isn’t just about removing visible food particles—it’s essential for gum health and preventing cavities. Skipping daily flossing allows plaque buildup, which can lead to gum disease and bad breath. Dr. Mark Burhenne, author of The 8-Hour Sleep Paradox, states, “The bacteria trapped between your teeth don’t just affect your mouth—they contribute to systemic inflammation in the body.”

    Make flossing a daily habit, even if you don’t see food stuck between your teeth. Water flossers or interdental brushes are great alternatives for those who find traditional floss difficult to use. Consistent oral care leads to healthier gums and a fresher smile.


    41 – Applying Lipstick on Dry, Flaky Lips

    Lipstick on chapped lips can accentuate dryness and create an uneven texture. Many people skip proper lip prep, leading to a patchy or cracked lipstick finish. Makeup artist Charlotte Tilbury emphasizes, “A well-prepped lip is the secret to a flawless lipstick application.”

    Before applying lipstick, exfoliate your lips with a gentle scrub or a soft toothbrush. Follow up with a hydrating lip balm and let it absorb before applying color. Choosing creamy or hydrating lipstick formulas prevents further dryness and keeps lips looking smooth.


    42 – Going to Bed Without Removing All Your Eye Makeup

    Leaving eye makeup on overnight can clog lash follicles, leading to irritation, infections, and even lash loss. Mascara and eyeliner residue can also contribute to under-eye puffiness and dark circles. Ophthalmologist Dr. Rupa Wong warns, “Sleeping in eye makeup increases the risk of developing styes and conjunctivitis.”

    Use a gentle, oil-based remover to dissolve stubborn eye makeup without rubbing. Double cleansing ensures every trace is removed while keeping the delicate eye area hydrated. Proper makeup removal prevents premature aging and keeps your lashes and eyes healthy.


    43 – Letting Pricey Skin Care Products Go to Waste

    Many people invest in expensive skincare but fail to store or use them correctly, leading to wasted product and reduced effectiveness. Exposure to heat, air, and sunlight can degrade active ingredients, making them less potent. Dermatologist Dr. Loretta Ciraldo advises, “Proper storage extends the life of skincare products—keeping them in a cool, dark place ensures maximum efficacy.”

    To avoid waste, use products consistently and within their recommended shelf life. Opt for airtight containers and store sensitive formulas, like vitamin C serums and retinoids, away from direct sunlight. Being mindful of skincare storage preserves its benefits and saves money in the long run.


    44 – Tolerating Dry, Cracked Heels

    Ignoring dry heels can lead to painful cracks, infections, and discomfort when walking. Many people rely on occasional moisturizing, which isn’t enough to repair severe dryness. Podiatrist Dr. Miguel Cunha explains, “Regular exfoliation and deep hydration are key to preventing cracked heels.”

    To keep heels soft, use a foot scrub or pumice stone weekly and apply a thick, emollient-rich moisturizer before bed. Wearing moisture-locking socks overnight enhances absorption, ensuring lasting hydration. Consistent care prevents painful cracks and keeps feet looking and feeling smooth.


    45 – Using a Giant Cotton Bath Towel to Dry Your Hair

    Regular bath towels create friction that can cause frizz, breakage, and moisture loss in the hair. Cotton fibers are rough on delicate strands, especially when aggressively rubbing the hair dry. Hairstylist Kristin Ess states, “Switching to a microfiber towel or a cotton T-shirt reduces friction and keeps hair smooth.”

    Instead of rubbing your hair, gently squeeze out excess water with a microfiber towel. Letting hair air dry partially before using heat tools also minimizes damage. A small change in your drying routine can improve hair health and texture over time.


    46 – Always Getting Gel Manicures

    Gel manicures provide long-lasting shine but can weaken nails over time due to the repeated use of harsh chemicals and UV exposure. Frequent gel removal can cause nail thinning and brittleness. Dr. Dana Stern, a nail health expert, warns, “Overuse of gel polish can lead to dehydration and long-term damage to the nail plate.”

    To maintain nail health, take breaks between gel manicures and apply strengthening treatments. Using cuticle oil daily and opting for regular polish occasionally helps prevent excessive nail weakening. Prioritizing nail care ensures both beauty and strength in the long run.


    47 – Using the Wrong Makeup Brush

    Applying makeup with the wrong brush can result in uneven blending, streaky foundation, or patchy eyeshadow. Different brushes serve specific purposes, and using the incorrect one can make application harder than it needs to be. Makeup artist Wayne Goss emphasizes, “Investing in the right tools makes a huge difference in how makeup sits on the skin.”

    Choose high-quality, well-shaped brushes that match the product you’re using—fluffy brushes for blending powders, dense brushes for foundation, and angled brushes for precision work. Keeping brushes clean also ensures smoother application and prevents breakouts.


    48 – Thinking That Brushing & Mouthwash Will Stop Bad Breath

    Brushing and using mouthwash alone don’t always eliminate bad breath, especially if the root cause is bacteria on the tongue or digestive issues. Many people neglect tongue cleaning, which allows odor-causing bacteria to thrive. Dentist Dr. Richard Price states, “The tongue harbors more bacteria than any other part of the mouth—scraping it daily is essential for fresh breath.”

    Use a tongue scraper or the back of your toothbrush to remove buildup each morning. Staying hydrated and consuming fiber-rich foods can also help balance oral bacteria. Comprehensive oral hygiene ensures long-lasting freshness beyond just brushing and rinsing.


    49 – Using Mouthwash That Contains Alcohol

    Alcohol-based mouthwashes can dry out the mouth, leading to bad breath and irritation rather than true oral health benefits. They kill both harmful and beneficial bacteria, disrupting the mouth’s natural balance. Dr. Mark Wolff, a dental expert, explains, “Non-alcoholic mouthwashes are just as effective at killing bacteria without causing dryness.”

    Opt for mouthwashes with fluoride, xylitol, or essential oils to support oral health without harsh effects. Hydration and saliva production naturally combat bacteria, so drinking plenty of water is also crucial for maintaining fresh breath.


    50 – Relying on a Regular Manual Toothbrush

    While manual toothbrushes can effectively clean teeth, they often don’t remove plaque as efficiently as electric ones. Studies show that electric toothbrushes reduce plaque buildup and gum disease more effectively. The American Dental Association states, “Powered toothbrushes with oscillating bristles provide superior cleaning and are especially beneficial for those with dexterity issues.”

    Switching to an electric toothbrush ensures a deeper clean with minimal effort. Look for models with timers and pressure sensors to improve your brushing technique and maintain optimal oral health.


    Conclusion

    Beauty mistakes can be subtle, yet their effects accumulate over time, leading to unnecessary damage to your skin, hair, and overall health. By making small adjustments to your routine—whether it’s switching to a silk pillowcase, using a gentler exfoliant, or applying SPF to often-forgotten areas—you can maintain long-term beauty and wellness. As beauty expert Caroline Hirons puts it, “Good skincare isn’t about trends—it’s about consistency and knowledge.”

    Prioritizing expert-backed habits will ensure you look and feel your best for years to come.

    By Amjad Izhar
    Contact: amjad.izhar@gmail.com
    https://amjadizhar.blog

  • Age of Jihad Islamic State and The Great War for the Middle East

    Age of Jihad Islamic State and The Great War for the Middle East

    Patrick Cockburn’s The Age of Jihad examines the tumultuous state of the Middle East following the collapse of the Ottoman Empire. The book focuses on the destabilizing impact of the 2003 US invasion of Iraq, arguing that it exacerbated existing sectarian tensions and created a power vacuum exploited by various groups. Cockburn traces the evolution of conflicts in Iraq, Syria, Libya, and Afghanistan, highlighting the role of foreign intervention, sectarian violence, and the rise of militant Islamism. He analyzes the human cost of these wars, depicting the suffering of civilians caught in the crossfire and the lasting consequences of political instability and violence. The book concludes by considering the long-term implications of these conflicts on the region and the world.

    The Age of Jihad: A Study Guide

    Short Answer Quiz

    1. According to the author, what is at the heart of the book’s analysis of the Middle East and why?
    2. What is significant about the 1975 Algiers Agreement involving Saddam Hussein?
    3. How did the sanctions imposed on Iraq after the Gulf War affect its population?
    4. What did the author observe about the distribution of power in Afghanistan?
    5. How did the author describe the state of the Iraqi Army’s command structure along sectarian lines?
    6. What was the significance of al-Mutanabbi Street in Baghdad, and what did it symbolize about Iraqi society after sanctions?
    7. What is the meaning of the term “hawasimi” in the context of post-invasion Iraq?
    8. How did the author characterize the methods used by guerrillas in Iraq against U.S. forces?
    9. What specific details does the author use to illustrate the difficulties of life in Mosul under ISIS?
    10. What is “Somalianisation” and why is it described as an ominous trend?

    Quiz Answer Key

    1. The invasion and occupation of Iraq by the U.S. is central because it destroyed Iraq as a united country, leading to a state of permanent conflict among its three main communities (Shia, Sunni, and Kurds) which has had a destabilizing effect on the entire region.
    2. The 1975 Algiers Agreement temporarily ended the Kurdish rebellion, as Saddam Hussein made a deal with the Shah of Iran, who, with U.S. backing, betrayed his former Kurdish allies.
    3. Sanctions caused immense suffering and unnecessary hardship to ordinary Iraqis, without causing the demise of Saddam Hussein’s rule. They led to severe shortages of essential goods, limited access to healthcare, and a decline in the standard of living.
    4. Power in Afghanistan is highly fragmented, with villages acting like independent republics. The author highlights that a foreign peacekeeping force must maintain strict neutrality to be successful.
    5. The Iraqi Army was deeply sectarian, with Shia soldiers never meeting Sunni private soldiers, and Shia soldiers not reaching the rank of officer. This highlights the existing social stratification within Iraq’s military.
    6. Al-Mutanabbi Street was the center of the book trade in Baghdad, and it displayed how the educated class sold off their personal libraries due to the economic hardships caused by sanctions. The books’ underlined and translated words reveal an attempt to connect with English literature.
    7. “Hawasimi,” meaning “finalists,” is a sarcastic reference to those who have gained from the collapse and occupation of Iraq. The term is often applied to new police recruits, and it points to the distrust and opportunism present during this era.
    8. Guerrillas used roadside bombs, which were difficult to detect because they were often camouflaged within garbage and detonate with command wires, car door openers, or mobile phones. They also created booby traps specifically designed to target bomb-defusing sappers.
    9. Mosul under ISIS is described as a city experiencing severe shortages of food, fuel, water, and electricity. Living conditions were likened to the “Stone Age,” with no mobiles, TV, cars, or consistent lighting. Public punishments were also common.
    10. “Somalianisation” refers to a permanent state of chaos and warfare stemming from a failed state. This term is used to describe the trends of destabilization and rebellion across various countries in the Middle East from 2001 onward.

    Essay Questions

    1. Analyze the role of external actors, particularly the United States and its allies, in the destabilization of Iraq and Afghanistan, according to Cockburn’s analysis.
    2. Discuss the factors contributing to the rise of sectarian conflict in the Middle East, as presented in Cockburn’s work, and assess the impact of these conflicts on the populations of affected countries.
    3. How does Cockburn characterize the leadership of Saddam Hussein, and what does his trajectory reveal about the nature of power in the Middle East?
    4. Evaluate the effectiveness and unintended consequences of sanctions, as described in the book, using specific examples from the author’s observations in Iraq.
    5. Explore the significance of the concept of a caliphate and its implications for the Middle East and beyond, according to the text’s perspective on the rise of ISIS.

    Glossary of Key Terms

    • Algiers Agreement: A 1975 agreement between Iraq and Iran that temporarily ended the Kurdish rebellion, where Saddam Hussein made a deal with the Shah of Iran, who, with U.S. backing, betrayed his former Kurdish allies.
    • Baath Party: A political party that held power in Iraq under Saddam Hussein, noted for its nationalist ideology and authoritarian rule.
    • Caliphate: An Islamic state led by a religious and political successor to the prophet Muhammad, historically embodying religious and political unity.
    • Fedayeen: Fighters loyal to the former Baathist regime of Saddam Hussein.
    • Green Zone: A heavily fortified and secured area in Baghdad, housing the Iraqi government and international embassies, symbolizing the divide between the occupation forces and Iraqi society.
    • Guerrilla Warfare: Unconventional warfare using tactics such as ambushes and sabotage, employed by non-state actors, including insurgents and rebels.
    • Hawasimi: An Iraqi term for those who have profited from the chaos and occupation, highlighting the corruption and opportunism of post-invasion Iraq.
    • Jihad: A religious duty of Muslims; can refer to the inner struggle to follow Islam or an external struggle to defend Islam.
    • Kafir: An Arabic term meaning “disbeliever,” often used by extremist groups to label those considered non-believers of Islam.
    • Kurdish Peshmerga: The military forces of the autonomous Kurdistan region, known for their effectiveness in fighting against ISIS.
    • Mehdi Army: A Shia militia group in Iraq loyal to Muqtada al-Sadr, known for its involvement in sectarian violence and resistance against the U.S.-led occupation.
    • Sanctions: Economic penalties or restrictions imposed on a country, in this case used by the United Nations against Iraq, impacting daily life and infrastructure.
    • Sectarianism: Divisions and conflicts based on religious or ethnic affiliations, most prominent in the Middle East among Sunni, Shia, and Kurdish populations.
    • Sharia: Islamic law derived from the Quran and the teachings of the prophet Muhammad, used as the legal and moral code by some groups, such as ISIS.
    • Somalianisation: A term used to describe a state of permanent chaos and warfare resulting from a failed state, applicable to various unstable countries in the Middle East and Africa.
    • Sunni Triangle: A region in Iraq primarily inhabited by Sunni Arabs, often associated with resistance against the U.S. occupation and the Shia-dominated government.
    • Sykes-Picot Agreement: A secret 1916 agreement between Britain and France dividing up the Middle East after the collapse of the Ottoman Empire, leading to many borders and conflicts in the region.
    • Taliban: A fundamentalist Islamic political and military organization that ruled Afghanistan and is known for its extremist ideology and strict enforcement of religious laws.
    • Valmara: Italian-made antipersonnel landmines, which were widely dispersed in Iraq and caused many casualties.
    • Wahhabism: A puritanical, fundamentalist movement within Sunni Islam originating in Saudi Arabia, often associated with intolerance and extremism.

    Middle East and Afghanistan Conflicts: 2001-2015

    Briefing Document: Key Insights from the Sources

    This briefing document consolidates key information from the provided sources, focusing on the conflicts and political situations in the Middle East and Afghanistan from 2001 to 2015.

    1. The Complexities of War Reporting and Analysis

    • Challenges of Generalization: The sources caution against oversimplifying complex historical situations, emphasizing the danger of drawing parallels without full command of details [1]. This highlights the need for nuanced analysis rather than broad generalizations.
    • Journalistic Limitations: War reporters face criticism from two extremes: being seen as “hotel journalists” or “war junkies” [2]. There’s also a tension between the need to cover actual fighting and the need to explain the underlying causes of the conflict. Journalists in the field are often contradicted by pundits and “talking heads” in their home offices, who may not have direct experience [3].
    • Eyewitness Credibility: The “first draft of history” provided by journalists can be more credible than later interpretations, as it has not been “through the blender of received wisdom and academic interpretation” [3].

    2. Afghanistan: The Taliban, Northern Alliance, and US Intervention

    • Taliban’s Resurgence: The Taliban were not truly defeated initially, allowing them to make a significant comeback [2]. The initial reporting on the war may have missed this crucial long-term implication.
    • Northern Alliance: The Northern Alliance, an Afghan opposition group, was initially isolated but gained importance after 9/11 when the US needed allies on the ground [4, 5]. The Northern Alliance controlled areas like the Panjshir valley [4].
    • US reliance on allies: The US needed anti-Taliban allies on the ground in Afghanistan, and the first to move was General Dostum [5].
    • Journalist Access: Journalists faced difficulties entering Afghanistan [6]. Some were able to gain access through the Northern Alliance, using an old Russian helicopter [6].

    3. Iraq: Sanctions, the US Invasion, and the Rise of Insurgency

    • Impact of Sanctions: UN sanctions imposed on Iraq in 1990 led to devastating consequences for the Iraqi people, including shortages of medicine and supplies [7, 8].
    • Misguided Expectations: Some Iraqi expatriates gave the US false information before the invasion, including the expectation that US forces would be greeted with flowers and sweets [9].
    • US Misunderstandings: US military and civil leaders often misunderstood Iraqi culture and politics [10, 11]. Some US commanders seemed to get their ideas about the Arab world from Hollywood [10].
    • Insurgency and IEDs: Insurgents became increasingly confident, using improvised explosive devices (IEDs). US soldiers were not prepared for this type of warfare, having been trained for conventional warfare [12].
    • Propaganda and Zarqawi: The US exaggerated the role of Abu Musab al-Zarqawi to explain the insurgency, though many Iraqis questioned if he even existed [13, 14]. This propaganda may have led the US to underestimate the broader Sunni resistance to the occupation [14].
    • Civilian Casualties: US air power led to civilian casualties, increasing support for the insurgents [15].
    • Loss of Control: The US struggled to control the provinces, with insurgents controlling Baquba [16]. There was also a lack of coordination and information sharing between different US commanders and offices [10, 17].
    • Violence and Sectarianism: The conflict in Iraq intensified existing sectarian divisions between Shia and Sunni populations [18, 19].

    4. Libya: The Fall of Gaddafi and Post-Conflict Chaos

    • Rebel Infighting: The rebels fighting against Gaddafi were a mix of militias, some of whom were prone to paranoia [20]. There was also a lack of confidence in the new military leadership that was supported by Western powers [20].
    • NATO bombing: There were cases of “friendly fire” by NATO forces, which caused anger among the rebels [21].
    • Treatment of Black Africans: Libyan rebels were hostile to black Africans, and many were arrested because of their skin color [22].
    • Torture and Human Rights Abuses: Both pro and anti-Gaddafi forces used torture [23, 24]. There was a lack of transparency regarding these human rights abuses and the UK was criticized for their involvement [25].

    5. Other Conflicts and Human Rights Issues

    • Yemen: The US and Britain supported an unpopular and corrupt government in Yemen, which allowed al-Qaeda to gain strength [26].
    • Bahrain: Security forces were accused of torturing protesters and dissidents [27, 28]. The government also punished people for expressing sympathy for the protesters [29].

    6. Rise of ISIS

    • Early Warnings: In 2014, the author noted that ISIS’s growing strength in Iraq was the most important development in the region, though this observation was not widely shared by Syrian experts [1, 30].
    • ISIS tactics: ISIS launched diversionary attacks with small groups before striking suddenly at a single target [30].
    • Hashid Shaabi Weaknesses: The Shia militia, the Hashid Shaabi, was enthusiastic but poorly trained [31].

    7. Saudi Arabia and the Sunni-Shia Divide

    • Dual Policy: Saudi Arabia encouraged anti-Shia militancy abroad, but suppressed these groups at home [32].
    • Financial Support for Terror Groups: Saudi Arabia has been a critical financial support base for al-Qaeda, the Taliban, and other terrorist groups [32].
    • Proxy War: Saudi Arabia, Turkey, and the UAE promoted a proxy Sunni-Shia war in Syria, supporting extremist groups like al-Nusra and al-Qaeda [33].

    8. The Impact of US Policies

    • Lack of Control: The US failed to impose its control in both Iraq and Afghanistan, leaving behind very different political and military landscapes [34].
    • Unintended Consequences: The US’s actions in the region had numerous unintended consequences, including strengthening groups they opposed [26, 34].

    This briefing document highlights the complex and often contradictory nature of the conflicts discussed in the provided sources. The document also emphasizes the significance of understanding the local contexts, cultural sensitivities, and the long-term implications of interventionist policies.

    Middle East & Afghanistan Conflicts: 2001-2015

    Frequently Asked Questions (FAQ) Based on the Sources

    This FAQ addresses common questions arising from the provided sources regarding the conflicts and political situations in the Middle East and Afghanistan between 2001 and 2015.

    1. What were the main challenges faced by journalists covering these conflicts?

    • Journalists often faced a credibility gap, with those in the field sometimes contradicted by pundits and “talking heads” who lacked direct experience [1].
    • There was a tension between the need to cover the fighting and explaining the root causes of the conflicts [1].
    • Access to conflict zones was often difficult [2]. In Afghanistan, journalists had to use unconventional methods to get into the country, such as an old Russian helicopter [2].
    • Some journalists were criticized for being either “hotel journalists” or “war junkies,” highlighting the challenges of maintaining objectivity and focus in a conflict zone [1].

    2. How did the Taliban regain power in Afghanistan after their initial defeat?

    • The Taliban were not completely defeated initially, allowing them to regroup and make a significant comeback [1].
    • The US underestimated the Taliban’s long-term resilience [1].
    • The Taliban was able to exploit the existing political and social landscape [3].
    • The Afghan opposition felt abandoned and alone [4].

    3. What were the consequences of the UN sanctions on Iraq?

    • The sanctions led to severe shortages of food, medicine, and other essential supplies [5, 6].
    • Ordinary Iraqis suffered greatly, with many falling ill or dying due to lack of medical care [5].
    • The “oil-for-food” program, intended to alleviate the crisis, failed to make a measurable difference [6].

    4. Why did the US invasion of Iraq face so much resistance?

    • The US had misguided expectations and were given false information by some Iraqi expatriates who predicted that US forces would be welcomed with flowers and sweets [7].
    • The US military and Paul Bremer provoked confrontations with both the Shia and Sunni Arabs, who made up 80% of the population [8].
    • The US occupation forces were seen as an unwelcome foreign presence [9].
    • The US dissolved the Iraqi army which resulted in many unemployed soldiers who were willing to fight [10].
    • The US military was not prepared for guerrilla warfare and underestimated the Iraqi insurgency [11].

    5. What role did sectarianism play in the conflicts?

    • Existing sectarian divisions between Shia and Sunni populations were intensified by the conflicts in Iraq [9].
    • The Sunni Arabs felt they were being made second-class citizens which destabilized Iraq [12].
    • In Bahrain, the Shia majority felt excluded from jobs in security forces [13].
    • In Syria, Saudi Arabia encouraged anti-Shia militancy, which contributed to the proxy war [14].

    6. How did ISIS gain power and influence?

    • ISIS replaced al-Qaeda as the most extreme jihadi group [15].
    • ISIS was effective in guerrilla warfare [15].
    • ISIS gained support through propaganda and providing services, education and sermons [16].
    • ISIS imposed its cultural agenda in areas under its control [17].
    • Many people joined ISIS for economic reasons [17].
    • ISIS used chilling videos to intimidate their enemies [15].

    7. What were some of the common human rights abuses reported in these conflicts?

    • Torture was widespread, often used to extract confessions [18, 19].
    • Common methods included beatings, electric shocks, and suspension in contorted positions [18].
    • There were reports of rape in prisons [19].
    • Arbitrary arrests and detention without trial were also common [20].
    • Civilians were often killed in airstrikes [21].
    • People were punished for expressing sympathy for protestors [22].
    • Many people were forced to flee their homes and become refugees [23].

    8. What was the impact of US policies in the region?

    • The US failed to impose control in both Iraq and Afghanistan [1].
    • US actions often had unintended consequences, such as strengthening groups they opposed [1].
    • The US was accused of making mistakes and misunderstanding the culture and politics in the region [24, 25].
    • The US was criticized for their re-election strategy that prioritized political goals over the needs of the Iraqi people [25].

    9. What role did foreign fighters play in these conflicts?

    • Many foreign fighters joined ISIS, often from Tunisia [26].
    • Some foreign fighters were motivated by religious beliefs, while others were driven by economic reasons [17].
    • There was concern that Western intelligence operatives were worried about the influence of al-Qaeda and asked fighters why they were growing a beard [14].

    This FAQ is intended to provide a comprehensive overview of the key themes and issues covered in the sources. The conflicts discussed are complex, and these answers provide only a starting point for deeper exploration.

    Middle East Conflicts: 2001-2015

    Okay, here’s a timeline of key events based on the sources, focusing on the conflicts in Afghanistan, Iraq, Libya, and other relevant events in the Middle East from 2001 to 2015:

    Afghanistan

    • 2001:The US and its allies launch military operations in Afghanistan following the 9/11 attacks, targeting the Taliban [1].
    • The Northern Alliance, supported by US airstrikes, makes significant gains against the Taliban [2, 3].
    • The Taliban retreat from Kabul to Kandahar, and their forces begin to break up [2].
    • November 23: The Northern Alliance takes control of Kabul and prepares for talks with other Afghan leaders [3].
    • 2002: The initial military operations against the Taliban are largely reported as a military victory [2].
    • 2009-2012: The Taliban make a comeback in Afghanistan [4].

    Iraq

    • 1990-2003: Iraq is under UN sanctions, leading to severe humanitarian crises and a weakened state [4, 5].
    • 2003:March: The US and its allies invade Iraq [6].
    • April 28: US military checkpoint north of Kirkuk is disorganized [7].
    • April: US forces enter Baghdad [6, 8].
    • The US dissolves the Iraqi army [9].
    • June: The US establishes the Coalition Provisional Authority (CPA) to govern Iraq [9].
    • June: A US administrator disbands the 400,000-strong Iraqi army [9].
    • June: Grand Ayatollah al-Sistani issues a fatwa saying those who frame Iraq’s new constitution must be elected rather than selected by the US and the defunct Iraq Governing Council [10].
    • 2004:April 6: US Marines fight their way into Fallujah after the killing of four American civilian contractors [11].
    • June: Sovereignty is formally handed back to a US-nominated Iraqi government [12].
    • US military deaths in Iraq are very high: 848 soldiers killed and 8,002 wounded [13].
    • 2005:US military deaths in Iraq remain high: 846 killed and 5,946 wounded [13].
    • 2006:US military deaths in Iraq continue: 821 killed and 6,372 wounded [13].
    • April: Nouri al-Maliki replaces Ibrahim al-Jaafari as Prime Minister [14].
    • July: Abu Musab al-Zarqawi is killed [15].
    • 2007-2010: US forces begin to draw down in Iraq [4].
    • 2008:March: Nouri al-Maliki makes a brief visit outside the Green Zone to demonstrate the improved security situation [16].
    • August: The Iraqi government rejects a draft security agreement with the US which would have preserved indefinitely the US right to conduct military operations inside the country [17].
    • December: The Iraqi parliament votes in favor of a security agreement with the US to withdraw troops by 2011 [18].
    • 2009:June: US military forces withdraw from Iraqi cities [19].
    • 2010: US forces continue to withdraw, and US interest in Iraq wanes [20].
    • 2012: Sunni protests against the Maliki government begin in western Iraq [21].
    • 2013:March: Sunni demonstrations continue in Iraq against Nouri al-Maliki [21].
    • December: ISIS gains power and is considered the most successful leader in the Middle East [22].
    • 2014:
    • January: ISIS seizes Fallujah [23].
    • June: ISIS captures Mosul [6, 20].

    Libya

    • 2011:February: Protests against Gaddafi begin, spreading from Tunisia and Egypt [24].
    • April: The conflict escalates, with rebel forces and pro-Gaddafi forces engaged in fighting [25].
    • September: Rebel military control increases [26].
    • The Gaddafi regime is overthrown and Gaddafi is killed [27, 28].
    • Libyans find they have lost a functioning state and are at the mercy of predatory militiamen [27].
    • 2012-2014: Libya descends into chaos and violence, becoming a fragmented state with competing militias [29].
    • 2015 Libya, Syria and Yemen are being ravaged by warfare [28].

    Other Middle East Conflicts and Events

    • 2009-2015: The conflict in Yemen intensifies [29].
    • 2011:April: The author travels to Cairo, debating whether to go to Benghazi or Bahrain [30].
    • March: The ruling Sunni al-Khalifa monarchy in Bahrain, backed by Saudi troops, crushes mass protests by the Shia majority [30].
    • June: Poet Ayat al-Gormezi is sentenced to one year in prison in Bahrain [31].
    • 2011-2013: The Syrian civil war intensifies [29].
    • The Arab Spring uprisings begin and spread across the Middle East and North Africa [32].
    • Many authoritarian regimes are challenged by popular protests [32].
    • There are some successful transitions of power, but most countries experience political instability and violence [28, 33].

    General Trends

    • Sectarianism: Sectarian tensions between Sunni and Shia communities are exacerbated by regional conflicts [34].
    • Rise of Extremism: The rise of groups like ISIS demonstrates a shift towards more extreme forms of jihadism [5].
    • Western Intervention: Western military interventions often have unintended consequences and exacerbate instability [8, 35].
    • Human Rights Abuses: Torture, arbitrary arrests, and killings are widespread across the region [36-38].
    • Journalism: Eyewitness reporting by journalists is valuable, but war coverage can be deceptive, particularly when it focuses solely on military victories [2, 20, 39].

    This timeline highlights the complex and interconnected nature of the conflicts in the Middle East and Afghanistan from 2001 to 2015. It also underscores how the consequences of these events continue to shape the region today.

    The Iraq War: Miscalculations and Devastation

    The Iraq War, initiated by the US and its allies in 2003, is a central focus of the sources, which detail its profound and destabilizing consequences [1]. The invasion, though intended to remove Saddam Hussein, had far-reaching effects that continue to shape the region [2].

    Key aspects of the Iraq War discussed in the sources:

    • The Invasion and Its Aftermath: The invasion is described as a revolutionary act that ended centuries of Sunni Arab rule in Iraq [2]. The US dissolved the Iraqi army and security services, which were the main instruments of Sunni control over the Shia and Kurdish populations [2]. This action created a power vacuum and led to the rise of sectarian conflict [1]. The initial military campaign was swift, but the subsequent occupation was fraught with problems [3, 4].
    • Sectarian Divisions: The war exacerbated existing tensions between Iraq’s three main communities—Shia, Sunni, and Kurds—leading to a state of permanent confrontation [1]. The US was not fully aware of the deep divisions between Sunni and Shia Muslims [5]. This lack of understanding significantly hampered their efforts to establish a stable government [6]. The war resulted in Baghdad becoming a largely Shia city, with Sunnis fleeing or living in enclaves [7].
    • Sanctions and Their Impact: The sources highlight that pre-war sanctions had already severely damaged Iraq, creating conditions where Iraqis were more likely to engage in violence or embrace religious extremism [8]. UN sanctions are cited as a significant factor that weakened Iraq and made its population more prone to extremism [8, 9].
    • US Miscalculations and Failures: The US military and political leaders made several miscalculations. They had unrealistic expectations and received faulty advice from Iraqi expatriates who believed that US forces would be welcomed [10]. The US also underestimated the depth of Iraqi nationalism, sectarian divisions, and the potential for resistance [6]. The failure to establish a stable, representative government is a recurring theme [11-13].
    • The Rise of Resistance: The occupation faced increasing resistance from various groups, including former members of Saddam’s security forces and Islamic militants [14]. Attacks on US and British troops became more frequent and lethal, and the conflict became increasingly complex [14]. The US struggled to contain the insurgency [15].
    • The Role of the US Occupation: The US occupation was plagued by a lack of political planning [3]. It failed to address the needs of the Iraqi people, and even charged thirsty villagers for bottles of water [3]. The US was also criticized for discouraging Iraqi involvement and ignoring the needs of the local population [5].
    • Guerrilla Warfare: The sources detail the evolution of the resistance to the US occupation into a more organized and deadly guerrilla war, with bombings and ambushes becoming more sophisticated [14, 16]. The US military’s inability to effectively counter this resistance is a key factor in the war’s growing complexity [17].
    • Iraqi Perspectives: The sources highlight the views of ordinary Iraqis, who initially had mixed reactions to the invasion but grew increasingly disillusioned [9, 16, 18]. Many Iraqis felt that the US was not committed to their liberation and was more interested in its own political goals [13]. They saw the US as occupiers rather than liberators, and this perception fueled resentment and resistance [16].
    • Political and Social Instability: The war caused significant political and social instability in Iraq. The country was left deeply divided along sectarian lines, and the struggle for power among different groups led to continuous violence [1]. The government was seen by many Iraqis as a puppet of the US [19].
    • The Impact of the “Surge”: The US troop surge was meant to increase security, but it had limited long-term impact [20, 21]. The violence continued despite the increase in troop numbers.
    • The US Withdrawal: The US eventually withdrew its forces, but the Iraqi government was left with limited control over the country, and the conflicts continued [22, 23]. The US is seen to have largely provoked the civil war that raged across central Iraq [24].
    • Civil War and Sectarian Violence: The war led to a civil war and widespread sectarian violence between Shia and Sunni, including bombings, assassinations and forced displacement of communities [23-26].
    • The Rise of ISIS: The chaos and instability created by the Iraq war provided fertile ground for the rise of ISIS [27, 28]. ISIS gained power by exploiting existing sectarian tensions and capitalizing on the lack of a strong central government [29].
    • Long-Term Consequences: The sources suggest that the Iraq War did not achieve its goals of creating a peaceful and prosperous country, and that the conflict had long-term consequences [30]. The war deepened the divisions within Iraq and created a vacuum that has been filled by sectarianism and extremism [31, 32]. The war also had a negative impact on the image of the US in the Middle East and around the world [13].

    The sources portray the Iraq War as a deeply flawed endeavor with devastating consequences. They show a pattern of miscalculations, poor planning, and a failure to understand the complexities of the region.

    The Islamic State: Rise, Ideology, and Impact

    The Islamic State, also known as ISIS, ISIL, or Daesh, is a central focus of the sources, which detail its rise, ideology, and impact in the Middle East. The sources emphasize that the group’s emergence is a consequence of the chaos and instability created by the Iraq War and other regional conflicts [1].

    Origins and Rise:

    • Emergence from Instability: ISIS emerged from the chaos following the 2003 US-led invasion of Iraq, capitalizing on the power vacuum and sectarian tensions [1]. The group’s rise is linked to the broader conflicts in the Middle East, particularly in Iraq and Syria [2].
    • Exploitation of Sectarianism: ISIS gained traction by exploiting the deep-seated sectarian divisions between Sunni and Shia Muslims, particularly the alienation of the Sunni community in Iraq [2, 3]. The group presented itself as a protector of Sunni Muslims against Shia-dominated governments [3].
    • Evolution from Al-Qaeda: ISIS is described as having taken over from the al-Qaeda organization founded by Osama bin Laden as the most powerful and effective extreme jihadi group in the world [4]. However, it is also described as more violent and sectarian than al-Qaeda [4].
    • Rapid Growth: Under the leadership of Abu Bakr al-Baghdadi, ISIS grew swiftly in strength, becoming highly organized and controlled from the center [2]. By 2014, ISIS controlled a vast territory in western Iraq and eastern Syria [4].
    • Declaration of a Caliphate: In June 2014, ISIS declared itself a caliphate, a move with the potential to convulse many Islamic countries [5]. This declaration appealed to millions of young Sunni men who felt marginalized by the existing political and economic order [5].

    Territorial Control and Expansion:

    • Control of Key Cities: ISIS captured major cities like Fallujah, Mosul, Ramadi, and Palmyra, demonstrating their military capabilities [1, 4, 6, 7]. The capture of Mosul was described as an “earthquake” in the politics of Iraq and Syria [3].
    • Expansion of Territory: ISIS expanded rapidly, seizing large territories in both Iraq and Syria, and by 2015 the territory it controlled was larger than Great Britain [5, 8].
    • Strategic Importance of Territory: ISIS established control over oil and gas fields, providing it with a steady income. Control of crucial roads also helped to support the new state [8].

    Ideology and Practices:

    • Extreme Interpretation of Islam: ISIS enforces a strict and intolerant variant of Islam that is rejected by most Muslims, imposing it on all aspects of life, from women’s dress codes to the regulation of businesses [9]. The group’s ideology is a radical version of Wahhabism that includes extreme violence [10].
    • Brutal Tactics: ISIS is known for its brutality, which includes mass executions, beheadings, amputations, and floggings [11]. They are known to kill Shia Muslims and Christians [4]. The group’s propaganda films often show the execution of non-Sunni Muslims [2].
    • Enforcement of Strict Rules: ISIS imposes strict rules regarding clothing, social behavior, and religious practice. For example, women are required to wear the niqab and are not allowed to leave the house without a male relative [11, 12].
    • Propaganda and Recruitment: ISIS uses sophisticated propaganda to attract recruits, often exploiting economic grievances and feelings of marginalization [13, 14]. They offer jobs and salaries to those who join them [14, 15].

    Impact and Consequences:

    • Sectarian Conflict: ISIS is a major catalyst for sectarian violence, with its attacks targeting Shia Muslims and other minorities, thereby deepening the divide between communities [16-18].
    • Human Rights Abuses: ISIS is responsible for widespread human rights abuses, including the persecution of religious and ethnic minorities like Christians and Yazidis, and the enslavement of Yazidi women [11, 17, 19, 20].
    • Displacement: ISIS’s brutal practices have led to the mass displacement of communities within the region [21]. Many people have fled from areas under their control, seeking safety in other regions [14, 21].
    • Destabilization of the Region: The rise of ISIS has destabilized the Middle East, exacerbating existing conflicts and creating new ones, while also drawing countries like Turkey and Saudi Arabia into the conflict [8, 22, 23].
    • Challenge to Existing States: ISIS seeks to replace existing nation-states with a caliphate that transcends national borders [5, 22]. It has challenged the legitimacy of Muslim rulers throughout the world [22].

    Responses to ISIS:

    • International Coalition: The US has formed a coalition of 60 countries to oppose ISIS, but the effectiveness of this coalition has been questioned [24].
    • Military Operations: US-led air strikes have been conducted against ISIS targets, though their effectiveness is debated in the sources [25-28]. The US struggles to find reliable local partners on the ground [25, 26].
    • Complex Alliances: The fight against ISIS is complicated by conflicting interests and alliances, as some countries, like Turkey, have focused on fighting Kurdish groups rather than ISIS itself [23]. Some of the countries that are supposedly fighting ISIS had previously supported the same jihadis in Syria and Iraq [24].
    • Local Resistance: There is some local resistance to ISIS in the areas it controls, but people are often too terrified of retaliation to act openly against the group [21, 29, 30].

    Challenges in Defeating ISIS:

    • Distrust and Division: The distrust and division between the various groups opposing ISIS make it difficult to form a united front [30, 31].
    • Local Support: Even though many fear ISIS, the group has some local support in Sunni communities [14, 32].
    • Organizational Strength: ISIS’s efficient organization and ruthless tactics make it a difficult enemy to dislodge [19, 33].
    • Lack of Clear Strategy: There is no clear strategy for dealing with ISIS beyond military action, as political and social factors are not effectively addressed [25].

    In summary, the Islamic State is portrayed as a highly dangerous and complex organization that has emerged from the chaos of the Iraq War and other regional conflicts. Its extreme ideology, brutal tactics, and ability to exploit sectarian tensions have made it a major destabilizing force in the Middle East. The sources make clear that ISIS is not simply a terrorist group but a proto-state with significant resources and a clear vision for the future.

    Middle East in Crisis

    The Middle East is presented in the sources as a region undergoing a period of intense conflict and instability, with several interconnected issues contributing to the current state of affairs [1]. The sources emphasize that the current conflicts are not isolated events, but rather part of a larger pattern of instability that has been developing over the last century [2].

    Key Themes and Issues:

    • Widespread Conflict and Instability: The region is engulfed in armed conflicts ranging from full-scale wars to general breakdowns of security [1]. Central governments have collapsed, are weak, or face powerful insurgencies [1]. Civil wars are tearing apart countries like Iraq, Syria, and Yemen, with little prospect of them coming together again as unified states [1].
    • Historical Context: The sources note that the region has never been truly stable since the fall of the Ottoman Empire, experiencing foreign invasions, Arab-Israeli wars, military coups, and conflicts between different groups [2]. The current era of civil wars is a major theme [3].
    • Sectarian and Ethnic Divisions: Sectarian and ethnic struggles play a central, though not exclusive, role in the crises in Iraq, Syria, Turkey, Afghanistan, and Yemen [3]. These divisions, particularly between Sunni and Shia Muslims, have been exacerbated by regional conflicts and interventions [2]. The sources highlight how these divisions have become more militarized and deeper, with each conflict reinforcing the others, preventing solutions to individual issues [4].
    • The Impact of the Iraq War: The 2003 US-led invasion of Iraq is described as an “earthquake” whose aftershocks are still being felt [5]. It energized existing conflicts and confrontations, and it also deepened the divisions within Iraq [5].
    • The Rise of ISIS: The chaos and instability created by the Iraq War provided fertile ground for the rise of ISIS, which has further destabilized the region [5]. ISIS is not just a terrorist group but also a proto-state with significant resources and a clear vision for the future [6].
    • The Role of External Powers: The sources emphasize the role of external powers, including the US, Russia, Iran, and Saudi Arabia, in exacerbating conflicts and shaping the region’s political landscape [4, 7]. The involvement of these powers often complicates the resolution of conflicts and leads to a “cat’s cradle of conflicting interests” [7]. The US, Britain, France, and the Sunni monarchies are seen as not wanting the war to end until they can declare victory [8].
    • The Sunni-Shia Conflict: A major theme is the growing confrontation between Sunni and Shia, and between Saudi Arabia and its allies and Iran with its allies [4]. The sources indicate that this conflict is becoming more militarized and that it prevents solutions to individual issues [4].
    • The “End of Sykes-Picot”: The sources mention the “end of Sykes-Picot” as a shorthand for the collapse of the old order established after World War I, with the implication that new boundaries and political arrangements may emerge [9, 10]. The reference is to the agreement of 1916 that divided up the spoils between Britain and France, but the sources note that this agreement ignored the wishes or existence of local inhabitants [9, 10].
    • The Kurdish Question: The Kurds, who were left without a state after the Ottoman collapse, are now seeking independence in Iraq and greater autonomy in Syria [9]. This ambition is a significant factor in the current political landscape [9].
    • Cross-Infection of Conflicts: The crises and wars in the region tend to cross-infect each other, with Iraq serving as a crucible for many of the troubles now affecting other Islamic countries [11]. The conflicts are interconnected, with events in one country impacting its neighbors [11]. For example, the uprising in Syria encouraged their neighbors in Iraq, and the revolts in the two countries are running in parallel [12].
    • The Vulnerability of States: There is a growing feeling across the Middle East that the future of entire states is in doubt, which is a sentiment that hasn’t been felt since the carve-up of the Ottoman Empire after World War I [9].
    • The Impact on Civilians: The sources emphasize the human cost of these conflicts, with millions of people displaced, in need of aid, and facing the threat of violence [2, 13]. Life has never been so dangerous and uncertain for the region’s inhabitants [2].

    Specific Regional Issues:

    • Iraq: The country is disintegrating under the pressure of a mounting political, social, and economic crisis [14]. The conflict between Shia, Sunni, and Kurds is deepening to a point just short of civil war [14]. The Iraqi government’s authority extends only a few miles north and west of Baghdad [15]. The sources detail how the US failed to establish a stable government after the invasion [16, 17].
    • Syria: The country is in a state of civil war, with sectarian violence and the rise of jihadist groups like ISIS and Jabhat al-Nusra [18-20]. The conflict has become a proxy war between regional and international powers [7]. The war in Syria is spreading to neighboring countries [19]. The sources detail the increasing radicalization of the conflict and the displacement of millions of Syrians [2].
    • Yemen: The country is being crushed by Saudi air strikes and a tight economic blockade [13]. The conflict has been framed in sectarian terms, with the Houthis, a Zaidi Shia rebel movement, pitted against a Saudi-led Sunni coalition [21]. This conflict has exacerbated the Sunni-Shia divide in the region and has led to a humanitarian disaster [13].
    • Libya: The country has been reduced to a state of violence approaching that of Syria, Iraq, and Afghanistan, and that intervention by western powers has been a disaster [13]. The country is fragmented, with different militias vying for power [13].
    • Bahrain: The country has seen mass protests by the Shia majority demanding democratic reform, which were crushed by the ruling Sunni monarchy with Saudi support [22]. The sources describe the Bahrain government as targeting the Shia community and deepening its sense of alienation [23].
    • Turkey: The country is facing spillover violence from the Syrian conflict, and has also seen a renewal of the Turkish-Kurdish civil war [1, 24].

    Long-Term Trends:

    • The failure of Western Interventions: The sources emphasize that the interventions by Western powers in the Middle East have largely failed, and that they have often exacerbated the existing conflicts [8, 13].
    • Shifting Power Dynamics: The sources note that the vast wealth of the oil states in the Gulf has turned into political power, with Sunni absolute monarchies now holding the leadership of the Arab world [5].
    • The Spread of Sectarianism: The sources highlight the increasing spread of sectarianism as a major destabilizing factor in the region, which is being fueled by both local and external actors [4].

    In conclusion, the Middle East is portrayed as a region in a state of profound crisis, with multiple interconnected conflicts, deep-seated sectarian and ethnic divisions, and the involvement of numerous external powers. The sources suggest that there is no easy path to peace and stability in the region, and that the long-term consequences of the current conflicts are likely to be severe. The region is undergoing a transformation whose ultimate outcome remains uncertain, but which is sure to shape global politics for the foreseeable future.

    Regime Change in the Middle East

    Regime change is a recurring theme in the sources, often associated with the destabilization of countries, the rise of sectarian conflict, and the unintended consequences of foreign intervention. The sources discuss regime change in the context of specific countries and the broader Middle East.

    General Observations on Regime Change:

    • Destabilizing Force: Regime change is frequently depicted as a destabilizing force in the region [1-3]. The removal of existing authoritarian governments has often led to power vacuums, civil wars, and the rise of extremist groups [3-5].
    • Unintended Consequences: The sources suggest that regime change often produces unintended and negative consequences. For example, the removal of Saddam Hussein in Iraq did not lead to a stable democracy, but rather to sectarian violence and the rise of ISIS [6, 7]. Similarly, the intervention in Libya led to a fragmented state with various militias vying for power [8].
    • External Influence: Regime change is often driven or influenced by external powers, such as the United States and its allies [6, 9, 10]. However, these interventions have been criticized for their lack of understanding of local dynamics and their failure to establish lasting stability [2, 5, 7, 9, 10].
    • Rise of Extremism: Regime change has created power vacuums that have been exploited by extremist groups, such as ISIS, who then challenge the new order [1, 11, 12].
    • Failure of Western Interventions: The sources suggest that Western interventions aimed at regime change have largely failed, and often exacerbated existing conflicts [9, 10, 13, 14].

    Regime Change in Specific Countries:

    • Iraq: The 2003 US-led invasion of Iraq resulted in the overthrow of Saddam Hussein’s regime [6]. However, this did not lead to a stable, democratic government. Instead, it created a power vacuum, which was filled with sectarian violence, a Sunni insurgency, and the rise of ISIS [9-11, 15]. The sources highlight the lack of a viable Iraqi opposition ready to take over [16]. The US was unable to create a government that was seen as legitimate by the majority of Iraqis [9, 10, 16]. The US preference for a Sunni dominated government was at odds with the Shia majority [7, 10].
    • Libya: The 2011 uprising against Muammar Gaddafi, supported by NATO intervention, led to his overthrow and death [17, 18]. However, the country descended into chaos, with various militias vying for control and the government unable to assert its authority [8, 19]. The sources point out that the opposition to Gaddafi was dependent on external support and lacked a clear program beyond his removal [17, 18, 20].
    • Syria: The sources show that the conflict in Syria started as a popular uprising against the government, but it quickly became a sectarian conflict [12]. The White House has stated that its top priority is regime change in Syria, but the sources note that this is a recipe for a long and drawn out conflict [21]. The rebels have not been able to overthrow the government [22].
    • Yemen: The sources describe the possibility of regime change in Yemen as a result of the Arab Spring protests [23, 24]. However, the country is facing the possibility of a civil war, and a vacuum of power [23, 25].

    Impact on Regional Stability:

    • Sectarian Conflict: Regime change has often exacerbated sectarian tensions. In Iraq, the overthrow of Saddam Hussein led to increased conflict between Sunni and Shia communities [3, 7, 9, 10]. In Syria, the uprising against the Assad regime has taken on a sectarian character [12].
    • Rise of Extremist Groups: The sources emphasize that the chaos created by regime change provides an opportunity for extremist groups to gain power and influence [1, 11].
    • Regional Power Struggles: Regime change has also intensified regional power struggles [7, 9, 10]. Countries like Iran and Saudi Arabia have been vying for influence in the region, and have taken sides in conflicts such as the one in Syria [26].
    • End of Old Order: Regime change is presented as a part of the “end of Sykes-Picot,” the old order established after World War I [27]. This suggests that the region is undergoing a fundamental transformation that could lead to new boundaries and political arrangements.

    Challenges and Future Considerations:

    • Lack of Viable Alternatives: The sources note a lack of viable, organized, and widely supported alternatives to the existing regimes [16]. In many cases, the opposition groups are weak, fragmented, and dependent on foreign powers [17, 20].
    • Difficulty in Building Stable Governments: Even when regime change is achieved, building stable and legitimate governments is extremely difficult. The sources highlight the challenges of establishing a power-sharing agreement and a government that is supported by the population [3, 10].
    • Need for Local Solutions: The sources imply that sustainable solutions to the conflicts in the Middle East must come from within the region and must address the underlying issues of sectarianism, inequality, and lack of political representation [3, 4, 10].

    In conclusion, the sources portray regime change as a complex and often counterproductive process that has significantly destabilized the Middle East. The removal of existing regimes has frequently led to unforeseen consequences, including civil wars, sectarian violence, and the rise of extremist groups. The sources suggest that external interventions aimed at regime change have often failed, and that lasting peace and stability in the region require locally-driven solutions that address the underlying causes of conflict.

    The Arab Spring: A Complex Revolution

    The Arab Spring is presented in the sources as a complex series of events with both democratic aspirations and significant unintended consequences [1, 2]. It is described as a period of widespread popular protests in the Middle East and North Africa, beginning in 2011, that aimed to overthrow long-standing authoritarian regimes [3, 4]. However, the sources also emphasize that the term “Arab Spring” is misleading, as it overstates the progressive nature of these events [1, 2].

    Initial Motivations and Goals:

    • Desire for Democracy: Millions of people across the region sought an end to corrupt and brutal police states, and hoped to establish honest, accountable, law-bound governments [1].
    • Demand for Civil Rights: Protesters called for free elections and an end to discrimination [1].
    • Rejection of Authoritarianism: The uprisings were a direct challenge to the existing political order, where power was concentrated in the hands of a small, often corrupt elite [5].

    Complications and Challenges:

    • Sectarian Divisions: The sources emphasize that demands for democracy had different implications in various countries [1, 6]. In Bahrain, for example, democratic reforms would lead to the Shia majority taking power from the Sunni minority [1]. In Syria, the opposite would be true, with the Sunni majority replacing the ruling Alawite minority [1].
    • Militant Islamism: The sources note that militant Islamism was always a part of the Arab Spring, and that it was not a purely progressive revolution that was later hijacked [4].
    • External Influence: Some of the protests were influenced or manipulated by neighboring countries and foreign powers [7, 8].
    • Militarization of Dissent: When peaceful protests were met with violence, the dissent became militarized, leading to civil wars and chaos [4].

    Outcomes and Consequences:

    • Mixed Results: The Arab Spring did not result in a uniform outcome. While it led to the overthrow of some leaders, it did not produce stable democracies in most cases [9].
    • Authoritarian Resurgence: In several countries, such as Egypt and Bahrain, more repressive governments took power [9, 10].
    • Civil Wars: Libya, Syria, and Yemen were ravaged by warfare [9]. The sources note that Libya, previously peaceful, descended into violence approaching the levels seen in Syria and Iraq [11].
    • Increased Oppression: The clampdown on opposition grew ever more severe in many countries [12].
    • Rise of Extremist Groups: The power vacuums created by the uprisings were often filled by extremist groups such as ISIS [7, 13].
    • Disillusionment: Many people in the region felt deceived, and the term “Arab Spring” was replaced by “Arab Autumn” or “Arab Winter” in many media outlets [3].

    Specific Country Examples:

    • Libya: The uprising against Gaddafi was initially praised in the West, but the country descended into chaos after his removal [14]. The opposition was dependent on NATO and did not have the strength to fill the power vacuum [9, 15].
    • Syria: The protests against the Assad regime quickly turned into a civil war. The conflict became a proxy war, with regional and international powers backing different sides [16].
    • Bahrain: The Sunni monarchy, backed by Saudi troops, crushed mass protests by the Shia majority [17, 18]. The government brought in foreign Sunni to strengthen the security forces [18].
    • Yemen: The largely peaceful transfer of power from President Ali Abdullah Saleh was initially seen as a positive result of the Arab Spring, but the country was later torn apart by civil war [19].
    • Egypt: Despite the mass protests in Tahrir Square, the protesters never seized state power, and the country ended up under an even more repressive police state [10].

    Role of Media:

    • Initial Support for Protests: Foreign journalists and satellite television stations such as Al Jazeera Arabic played a role in publicizing the uprisings [20].
    • Government Restrictions on Media: In response, governments restricted journalists by denying visas, expelling correspondents, or even arresting them [20].
    • Misleading Portrayals: The Western media often portrayed the uprisings as “bourgeois” revolutions led by secular, pro-Western individuals, which was deceptive [7]. The sources note that the media was also credulous in broadcasting claims about government atrocities while dismissing government denials [14].

    Overall Assessment:

    • Not a Uniform Movement: The Arab Spring was not a single, unified movement, but a series of interconnected uprisings with diverse goals and outcomes [4].
    • Failure to Achieve Lasting Change: While the uprisings initially sparked hope for democracy, they ultimately failed to create lasting democratic change in most of the countries affected [9].
    • Exacerbation of Existing Conflicts: The Arab Spring exacerbated sectarian and political tensions, leading to violent conflict and instability [12].

    In conclusion, the Arab Spring was a complex and multifaceted series of events that initially held great promise for democratic change, but ultimately resulted in a mix of outcomes, including increased authoritarianism, civil wars, and the rise of extremist groups [9]. The sources highlight the importance of understanding local contexts and the unintended consequences of foreign intervention when assessing these events. The Arab Spring is not a singular event, but rather a collection of uprisings with different goals and outcomes, the effects of which are still being felt in the Middle East [4, 13].

    By Amjad Izhar
    Contact: amjad.izhar@gmail.com
    https://amjadizhar.blog

  • Al Riyadh Newspaper, April 6, 2025: Partnerships, Economic Developments, Art Exhibitions, Sudan, Lebanon, Syria, Infrastructure Projects

    Al Riyadh Newspaper, April 6, 2025: Partnerships, Economic Developments, Art Exhibitions, Sudan, Lebanon, Syria, Infrastructure Projects

    Multiple articles from Al-Riyadh newspaper cover a range of topics. Recent events in Saudi Arabia are highlighted, including partnerships, economic developments, and cultural initiatives like Ramadan events and art exhibitions. Regional issues are also addressed, such as the ongoing conflicts in Sudan and Gaza, as well as diplomatic efforts in Lebanon and Syria. Furthermore, the publication discusses sports, business regulations, infrastructure projects, and social topics relevant to the Kingdom. These articles collectively offer insights into current affairs and the Kingdom’s multifaceted activities.

    01
    تحت رعاية خادم الحرمين الشريفين.. تكريم الفائزات بجائزة الأميرة نورة للتميُّز النسائي في دورتها السابعة الأربعاء المقبل

    Understanding the Source Material: A Study Guide

    Quiz: Short Answer Questions

    1. What is the significance of the real estate procedures recently directed by the Crown Prince Muhammad bin Salman?
    2. According to Ambassador Al-Sheikh, what was the main goal of the Saudi-Georgian Business Forum held in Tbilisi?
    3. What potential positive impact could the announced US tariffs have on the Saudi stock market, according to Mohammad Al-Hazmi?
    4. What were the key issues discussed during the meeting between Lebanese officials and US envoy Morgan Ortagus?
    5. What is the primary architectural style being used in the renovation of the Al-Mashqi Mosque in Asir?
    6. What are the main strategic objectives behind the project to rehabilitate historical mosques in Saudi Arabia?
    7. What is the King Salman Humanitarian Aid and Relief Centre doing to support Sudan, as mentioned in the excerpts?
    8. What is the main goal of Saudi Arabia’s efforts to become a global hub for esports, as highlighted in the report?
    9. According to Dr. Nouf Al-Ghamdi, what are some of the expected economic consequences of the US tariff increases?
    10. What was the primary focus of the royal decree concerning real estate regulations north of Riyadh, as mentioned in Dr. Saud Al-Murshid’s article?
    01
    ولي العهد والرئيس الإيراني يبحثان تطورات الأحداث في المنطقة

    Quiz: Answer Key

    1. The real estate procedures aim to elevate the capital and other cities economically in line with the Kingdom’s Vision 2030, fulfill citizens’ needs, and create a balance between supply and demand in the real estate sector.
    2. The main goal of the forum was to strengthen the Saudi-Georgian partnership and investment, especially in light of Saudi Arabia’s Vision 2030, and to introduce representatives of each country’s business environment.
    3. The US tariffs could potentially increase the attractiveness of the Saudi stock market due to concerns related to the tariffs’ impact, leading to an inflow of migrating capital and improved liquidity in the Saudi financial market.
    4. The key issues discussed included the situation in southern Lebanon, the work of the international monitoring committee, the Israeli withdrawal, and the overall situation in the south, as well as measures to prevent any chaos or smuggling across the Lebanese-Syrian borders.
    5. The primary architectural style being used in the renovation of the Al-Mashqi Mosque is the traditional Sarat style, characterized by its unique design and the use of natural materials from the Sarat mountains.
    6. The main strategic objectives include rehabilitating historical mosques, restoring their architectural authenticity, highlighting their historical and cultural significance, and benefiting from their original architectural features in modern mosque designs.
    7. The King Salman Humanitarian Aid and Relief Centre is distributing food baskets to those most in need in Sudan, as part of a project to support food security in the country for the year 2025.
    8. The main goal is to establish Saudi Arabia as a leading global center for esports by providing a stimulating environment for players and developers, investing in strong infrastructure, and hosting major international competitions.
    9. Dr. Al-Ghamdi suggests the US tariff increases could lead to higher production and import costs, potentially passed on to consumers, contributing to a new inflationary wave and causing capital flight from US assets.
    10. The primary focus of the royal decree was to reorganize the real estate market, achieve balance, address the rise in land prices and rents, streamline relevant regulations, and ultimately create a more stable and sustainable real estate market for citizens.
    01
    لبنان: لقاءات إيجابية بين عون وسلام والمبعوثة الأميركية

    Essay Format Questions

    1. Analyze the interconnectedness of Saudi Arabia’s Vision 2030 with the various initiatives and events highlighted in the provided news excerpts, such as real estate development, international partnerships, and cultural projects.
    2. Discuss the potential implications of increasing global economic and political uncertainties, as suggested by the reports on US tariffs and regional conflicts, on Saudi Arabia’s economic diversification and investment strategies.
    3. Evaluate the significance of Saudi Arabia’s growing engagement in international partnerships and forums, using the Saudi-Georgian relationship as a primary example, and consider the benefits and challenges of such collaborations.
    4. Examine the role of cultural and heritage preservation, as seen in the restoration of historical mosques and the promotion of Saudi arts and culture, within the broader context of Saudi Arabia’s national identity and its Vision 2030 goals.
    5. Assess the multifaceted humanitarian efforts undertaken by Saudi Arabia, as exemplified by the work of the King Salman Humanitarian Aid and Relief Centre and its engagement in regional stability efforts, and discuss their impact on the Kingdom’s international standing.
    01
    السفير آل الشيخ: بعثات المملكة في الخارج تمثل الوجه الحقيقي لوطن رائد في مختلف المجالات

    Glossary of Key Terms

    • Vision 2030: The Kingdom of Saudi Arabia’s ambitious strategic framework launched to diversify its economy, develop public service sectors such as health and education, and position the country as a global hub.
    • Real Estate Procedures: Official actions and regulations related to the buying, selling, and development of land and properties, often implemented to stabilize the market and meet housing needs.
    • Supply and Demand: Basic economic principle referring to the amount of a commodity, product, or service available (supply) and the desire of buyers for it (demand), which influences prices.
    • Tariffs: Taxes imposed by a government on goods or services imported from other countries, often used to protect domestic industries or as a tool in international trade relations.
    • Stock Market Liquidity: The ease with which assets, such as stocks, can be bought or sold without significantly affecting their price; high liquidity generally indicates a healthy market.
    • International Monitoring Committee: A body composed of representatives from different countries or international organizations tasked with observing and reporting on specific situations, often related to peace agreements or border issues.
    • Architectural Authenticity: The genuine character of a building or structure in terms of its original design, materials, and construction techniques, often a focus in restoration projects.
    • Humanitarian Aid: Assistance provided to people in need, often during or after crises such as natural disasters or conflicts, aimed at alleviating suffering and meeting basic needs.
    • Esports Hub: A central location or region that fosters and supports electronic sports through infrastructure, events, talent development, and investment.
    • Inflationary Wave: A period of sustained increase in the general price level of goods and services in an economy, leading to a decrease in the purchasing power of money.
    • Capital Flight: The movement of large amounts of money out of a country due to economic or political instability, or in response to policy changes like tariffs.
    • Real Estate Market Stability: A condition in the property sector characterized by consistent prices, balanced supply and demand, and a lack of extreme fluctuations, fostering confidence among buyers and sellers.
    • Cultural Heritage Preservation: Efforts to protect and maintain historical, artistic, and cultural artifacts, sites, and traditions for future generations.
    • International Partnerships: Collaborative relationships between two or more countries, often involving economic, political, or cultural cooperation to achieve mutual goals.
    • Humanitarian Efforts: Actions undertaken to alleviate human suffering and improve the well-being of individuals and communities, often in response to crises or chronic needs.
    01
    مانشستر سيتي يتعادل سلبيا مع مانشستر يونايتد بالدوري الإنجليزي

    Briefing Document: Analysis of “alriyadh.com” Newspaper Excerpts (April 6, 2025)

    This briefing document summarizes the main themes and important ideas and facts presented in the provided excerpts from the April 6, 2025 issue of the Saudi Arabian newspaper “Al Riyadh.” The excerpts cover a diverse range of topics, including regional politics, economic development initiatives, cultural events, international relations, and social issues within the Kingdom and beyond.

    01
    غدًا تنطلق النسخة الأولى من منتدى الاستثمار الرياضي

    Main Themes:

    • Saudi Arabia’s Vision 2030 and Economic Diversification: Several articles highlight the ongoing efforts to achieve the goals of Vision 2030, particularly in economic diversification and improving the quality of life for citizens.
    • Strengthening International Partnerships and Investment: The newspaper emphasizes Saudi Arabia’s active engagement in building and enhancing partnerships with other nations, focusing on economic and investment cooperation. Georgia is presented as a key partner in this regard.
    • Regional Political Developments and Conflicts: The excerpts touch upon various ongoing regional conflicts and political situations, including the situation in southern Lebanon, the conflict in Sudan (Darfur), and Israeli actions in Gaza and Syria.
    • Cultural and Social Developments within Saudi Arabia: The newspaper covers various cultural initiatives, events, and social programs aimed at promoting national heritage, arts, and empowering different segments of society.
    • Global Economic Trends and Their Impact: The potential impact of US tariffs on the Saudi stock market is discussed, along with broader global economic shifts.
    01
    وزير المالية يزور الكراج وبرنامج NTDP

    Key Ideas and Facts:

    1. Saudi Arabia’s Vision 2030 and Economic Development:

    • Real Estate Sector Boost: Crown Prince Mohammed bin Salman directed initiatives to boost the real estate sector, aiming to balance supply and demand and provide housing for citizens. This is seen as aligning with the goals of Vision 2030.
    • Quote: “…الإجراءات العقارية التي وجه بها سمو ولي العهد الأمر محمد بن سلمان بن عبدالعزيز، تستهدف من أجل تعزيز القطاع الخاص، وتوفير منتجات عقارية للمواطن والأداة والطلب، وخلق التوازن بين العرض…”
    • Saudi Stock Market Attractiveness: The potential imposition of US tariffs is discussed as a factor that could increase the attractiveness of the Saudi stock market due to investors seeking stable alternatives.
    • Quote (Mohammed Al-Hazmi): “وقال من المحتمل أن يسهم تدفق رؤوس الأموال المهاجرة إلى أسواق الأسهم السعودية وعودتها، نتيجة للمخاوف المتعلقة بتأثرات تطبيق التعرفة الجمركية، في تعزيز النمو في السوق المالية السعودية بشكل ملحوظ.”
    • Regulation of the Real Estate Market: The Real Estate General Authority is actively monitoring media and social media to regulate the market and prevent exploitation.
    • Quote (Dr. Saud Al-Muraished): “…واتخاذ كل ما من شأنه أن يحقق سوقًا عقارية متوازنة وأكثر استقرارًا واستدامة…”
    • Riyadh as an Events Hub: Riyadh is developing into a major center for events, fostering social cohesion and celebrating national occasions like Eid.
    • Quote (Fahd bin Saad Al-Quthami): “حينما تصنع الرياض البهجة لا تكتفي بالتفاصيل، إما أن تدهشك بتلبية التوقعات، وليالي العيد كانت شاهدة على تحّول مدروسًا يعكس توجهًا استراتيجيًا نحو تعزيز التلاحم الاجتماعي…”
    01
    الخريجي يتسلّم شارة منتدى الاستثمار الرياضي نيابة عن وزير الخارجية

    2. Strengthening International Partnerships and Investment (Focus on Georgia):

    • Enhanced Saudi-Georgian Relations: The Saudi Ambassador to Georgia noted the “ascending” relations between the two countries, highlighting multiple meetings and forums aimed at strengthening partnership and investment.
    • Quote (Ambassador Al-Sheikh): “نوه سفير خادم الحرمين الشريفين لدى جورجيا والسفير المقيم لدى أرمينيا الشيخ آل عبد الرحمن بن سلمان بالعلاقات السعودية – الجورجية.”
    • Tbilisi Silk Road Forum: The forum served as a platform to enhance cooperation, with significant participation from international partners and the signing of agreements, including the establishment of a Saudi-Georgian Business Council.
    • Quote (Ambassador Al-Sheikh): “وكان هدف المنتدى تعزيز الشراكة بين المملكة وجمهورية جورجيا، فقد تم اغتنام فرص التكامل والاستثمار وتوقيع المنتدى وصاحب السعادة اتفاقية إنشاء المجلس الأعمال السعودي – الجورجي…”
    • Saudi-Georgian Investment Forum (Tbilisi, February 2024): This forum, attended by the Saudi Minister of Investment and the Georgian Vice Prime Minister, aimed to promote investment opportunities and highlighted the shared strategic goal of linking transportation and logistics sectors with Europe.
    • Quote (Minister of Investment Khalid Al-Falih): “وأبان معالي الفالح في وقته أن المملكة وجمهورية جورجيا تتشاركان في نفس الهدف الاستراتيجي وهو ربط قطاع النقل والخدمات اللوجستية بآسيا بأوروبا حيث يحمل القطاع إمكانات كبيرة…”
    • Growth in Trade Exchange: The volume of trade exchange between Saudi Arabia and Georgia reached approximately 162 million Saudi Riyals in 2023, with Saudi exports constituting 31% and Georgian imports 69%. Both countries aim to increase this volume.
    • Saudi-Georgian Coordination Council: A memorandum of understanding was signed to establish a “Saudi-Georgian Coordination Council.”
    01
    خطيب المسجد الحرام: مواسم الخير لا تنقضي وأعمال البر لا تنقطع

    3. Regional Political Developments and Conflicts:

    • Lebanon: US Deputy Assistant Secretary Morgan Ortagus met with Lebanese officials, including President Aoun and Prime Minister Salam, to discuss the situation in southern Lebanon, the role of the international monitoring committee, and Israeli violations. The implementation of UN Resolution 1701, aimed at establishing state control and disarming non-state actors, was also discussed.
    • Quote (Lebanese Presidency Statement): “وأفاد بيان الرئاسة اللبنانية بأن «أجواء بناءة» سادت اللقاء الذي عقد في القصر الجمهوري في بعبدا بين عون وأورتاغوس، مضيفًا أنهما بحثا «ملفات الجنوب اللبناني، وعمل لجنة المراقبة الدولية، والانسحاب الإسرائيلي والوضع في الجنوب».”
    • Sudan (Darfur): The World Food Programme suspended aid in Darfur following the killing of aid workers in ongoing battles. Thousands fled Khartoum due to the conflict, and many countries evacuated their citizens. The UN had previously warned of the distribution of arms to civilians and the potential for ethnic clashes.
    • Quote: “في 16 أبريل، أعلن برنامج الأغذية العالمي التابع للأمم المتحدة بعد مساعداته، تعليق مقتل عدد من عمال الإغاثة في المعارك الدائرة في دارفور (غرب) عند الحدود مع تشاد.”
    • Gaza: Israeli military operations continued in Rafah, Gaza, with renewed airstrikes. Health authorities reported a rising number of casualties and difficulties in reaching those under the rubble.
    • Syria: Syria accused Israel of “deliberately destabilizing” the country following a series of airstrikes targeting military sites. The Syrian Observatory for Human Rights reported casualties. The government also responded to a report by Amnesty International regarding mass killings of Alawite civilians.
    01
    «التعريفات الجمركية الجديدة» هزة عنيفة دافعة لهجرة رؤوس الأموال الأميركية

    4. Cultural and Social Developments within Saudi Arabia:

    • “In the Love of Khalid Al-Faisal” Exhibition: An exhibition was held in Jeddah as part of the Jeddah Season 2025, honoring Prince Khalid bin Faisal bin Abdulaziz.
    • Hail Events During Eid Al-Fitr: Hail witnessed over 550,000 visitors to its parks and recreational areas during Eid Al-Fitr, enjoying various cultural and entertainment activities.
    • Development of Al-Mashqi Mosque in Asir: The Al-Mashqi mosque, one of the oldest historical mosques in the Asir region, is being restored in the traditional Sarat style as part of the Prince Mohammed bin Salman Project for the Development of Historical Mosques.
    • Quote: “يبرز مسجد المشقي في قرية المشقي الواقعة شرق جنوب مدينة أبها بنحو 32 كلم، بصفته أحد أقدم المساجد التاريخية في منطقة عسير الذي بني في أول عام هجري، بين عامي 73-75هـ، ليشمله مشروع الأمير محمد بن سلمان لتطوير المساجد التاريخية في مرحلته الثانية…”
    • King Salman Humanitarian Aid and Relief Centre: The center distributed food baskets to those in need in Sudan and Syrian refugees in Lebanon, highlighting Saudi Arabia’s ongoing humanitarian efforts.
    • Quote: “وزّع مركز الملك سلمان للإغاثة والأعمال الإنسانية 2.000 سلة غذائية الأكثر احتياجًا للأسر المحلية والنازحة في ولاية عطبرة نهر النيل بجمهورية السودان، استفاد منها 12.001 فرد…”
    • Saudi Internal Auditors Ranked Among Top Globally: The Saudi Association for Internal Auditors’ progress reflects positively on the profession in the Kingdom, placing it among the top 10 professional associations globally according to the International Institute of Internal Auditors.
    • Quote: “انعكس التقدم هذا بأن السعودية للمراجعين الداخليين، لتصبح ضمن تقييم وفق عالميًا، مهنية جمعيات 10 أفضل الداخليين، مما يؤكد للمراجعين الدولي المعهد في المملكة إليها وصلت التي المرموقة المكانة في مستمرة الجمعية أن مؤكدًا القطاع، هذا المشهد في المملكة حضور لترسيخ جهودها المهني الدولي…”
    • Growth of E-Sports in Saudi Arabia: The Kingdom is striving to become a global hub for e-sports, with significant investments and successful Saudi teams achieving international recognition.
    • Quote: “في ظل التوجهات المستقبلية التي تعتمد على الابتكار والتطور التكنولوجي، أصبحت الرياضات الإلكترونية من أبرز المجالات الريادية في المملكة العربية السعودية.”
    • Empowerment of People with Disabilities: The education administration in Al-Ahsa is investing in programs to empower students with disabilities, enabling their participation in various fields, including industry.
    • Quote: “أخذت رؤية المملكة 2030 الطموحة على عاتقها الأخذ بيد جل أبناء الوطن وتمكينهم ليكونوا منتجين، ليسهموا في مستقبل هذا الوطن العظيم وفق قدرته، ومنح ذوي الإعاقة فرصًا ليكونوا جزءًا فعالًا وسط مجتمع حيوي…”
    01
    اكتشافات أثرية جديدة بمعبد الرامسيوم بمحافظة الأقصر جنوب مصر
    • “Ela’a” Academy for Lifelong Learning: The Royal Commission for AlUla launched “Ela’a,” the first academy of its kind in Saudi Arabia to adopt the concept of lifelong learning, aiming to empower the local community and develop human capital in line with Vision 2030.
    • Quote: “أطلقت الهيئة الملكية لمحافظة العلا أكاديمية العلا للتعلم مدى الحياة )إعلاء(، وهي الأولى من نوعها التي تتبنى مفهوم التعلم مدى الحياة في المملكة ضمن مساعيها لتنمية القدرات البشرية بما يحقق مستهدفات رؤية 2030…”
    • Cultural Scene in March: The Ministry of Culture and its specialized bodies implemented various cultural programs and initiatives in March, reflecting a growing cultural movement in the Kingdom. This included “Ramadan Season” events, participation in the “Ahmed Mater: Aeriel” exhibition in Shanghai, the launch of the third edition of the Playwriting Competition, and Saudi Arabia’s participation in the London International Book Fair 2025.
    • Quote: “شهد شهر مارس الفائت زخمًا ثقافيًا نشطًا في المملكة العربية السعودية، حيث نفذت وزارة الثقافة وهيئاتها المتخصصة سلسلة من البرامج والمبادرات الثقافية النوعية، التي تعكس تنامي الحراك الثقافي المحلي السعودي وتعزز حضوره العالمي، في ظل رؤية المملكة 2030 التي تضع الثقافة في قلب التنمية.”
    • King Salman Global Academy for the Arabic Language: The academy continues its efforts to promote the Arabic language globally, launching the “Arabic Language Month in Spain” program and preparing for its fourth annual conference focusing on the digital environment and the lexicographical industry.
    • Quote (Dr. Saleh bin Abdullah Al-Washmi): “يواصل مجمع الملك سلمان العالمي للغة العربية جهوده الهادفة إلى تعزيز مكانة اللغة العربية عالميًا، وتنفيذ برامجه النوعية محليًا ودوليًا، في سياق دعم انتشارها علميًا وثقافيًا.”
    • Saudi Film Festival Announces Lineup: The Saudi Film Festival, organized by the Cinema Association in partnership with Ithra, announced the list of participating films in its 11th edition.
    01
    ولاء باحفظ الله» في لجنة تحكيم مسابقة الأفلام الروائية الطويلة بمهرجان أفلام السعودية

    5. Global Economic Trends and Their Impact:

    • Potential Impact of US Tariffs: The article discusses the potential for US tariffs to negatively impact US imports and potentially lead to a trade war. However, it also suggests that this could make the Saudi stock market more attractive to investors seeking stable havens.
    • Quote (Dr. Nouf Al-Ghamdi): “ولفتت الغامدي إلى انعكاس هذه التطورات سلبًا على ثقة المستثمرين، حيث تراجعت مؤشرات الثقة بالاقتصاد الأمريكي إلى أدنى مستوياتها منذ أزمة 2008، وفقًا لبيانات «كونفرنس بورد».”
    • Growing Boycott Movement Against US Goods: In response to potential tariffs, a growing movement to boycott American goods is emerging in affected countries, utilizing social media to organize and share information on alternative products and brands.
    • Quote: “ردًا على رسوم ترمب.. تنامي حركة مقاطعة البضائع الأميركية في الدول المتضررة”

    Overall Significance:

    These excerpts from “Al Riyadh” provide a snapshot of Saudi Arabia’s multifaceted development and its active role in the regional and global landscape. The strong emphasis on Vision 2030 initiatives, particularly in economic diversification, infrastructure development, and cultural enrichment, is evident. The Kingdom’s commitment to fostering international partnerships, especially in the economic sphere, is highlighted through the focus on Saudi-Georgian relations. At the same time, the newspaper acknowledges and reports on the complex and often challenging political and humanitarian situations in the wider Middle East and Africa. The coverage of cultural and social programs underscores the Kingdom’s efforts to empower its citizens and promote its heritage and arts. Finally, the discussion of global economic trends and their potential impact on Saudi Arabia demonstrates an awareness of the interconnected nature of the world economy.

    01
    برشلونة يهدر فرصة تعزيز صدارته للدوري بتعادله مع بيتيس

    Saudi Arabia: Vision 2030 and Key Developments

    Frequently Asked Questions (FAQ)

    1. What are the key objectives of Saudi Arabia’s Vision 2030, as highlighted in these articles? Saudi Arabia’s Vision 2030, as emphasized in these sources, aims at diversifying the Kingdom’s economy away from oil dependency, enhancing the quality of life for its citizens, and establishing Saudi Arabia as a global leader in various sectors. This includes developing non-oil sectors like tourism, technology (especially e-sports), and real estate, fostering international partnerships and investments, promoting cultural exchange, and empowering its citizens through education and job creation. The vision also focuses on preserving the Kingdom’s cultural and historical heritage while embracing modernity and openness.

    2. How are Saudi Arabia and Georgia strengthening their bilateral relations, particularly in economic and investment sectors? Saudi Arabia and Georgia are actively enhancing their partnership through increased diplomatic engagement, business forums, and the signing of numerous agreements and memoranda of understanding (MoUs). Key initiatives include the establishment of a joint Saudi-Georgian Business Council to boost mutual investments, facilitate trade, and explore opportunities in sectors such as transportation, energy, and tourism. The two countries have also focused on streamlining trade processes, avoiding double taxation, and promoting direct air links to foster economic and people-to-people connections, aligning with Saudi Vision 2030’s goals for international collaboration and investment attraction.

    3. What is the significance of the recent real estate regulations issued in Saudi Arabia, and what are they intended to achieve? The recent real estate regulations in Saudi Arabia, spearheaded by Crown Prince Mohammed bin Salman, aim to reorganize and stabilize the real estate market. These measures include lifting construction halts in certain areas, providing ready-to-build residential lands for citizens under specific conditions, and revising related regulations. The primary objectives are to create a balanced and sustainable real estate market, increase homeownership among citizens, protect the rights of all stakeholders, and ultimately contribute to the Kingdom’s economic growth by stimulating construction activities.

    4. How is Saudi Arabia developing its e-sports industry, and what achievements have been made in this sector? Saudi Arabia is making significant strides in developing its e-sports industry to become a global hub. This involves creating a supportive environment for players and developers through continuous support and substantial investments in infrastructure and initiatives. Saudi teams have achieved international recognition by winning major tournaments, such as the “Falcon” team’s victory in the e-sports World Cup in the “Gaming” season. These successes, backed by the leadership’s strategic vision, are positioning Saudi Arabia as a major force in the global e-sports arena and contributing to the diversification of the national economy and the digital sector.

    5. What efforts are being made to preserve and develop historical mosques in Saudi Arabia? Saudi Arabia has launched a comprehensive project, spearheaded by Crown Prince Mohammed bin Salman, to restore and rehabilitate historical mosques across the Kingdom. The second phase of this initiative includes the development of the Al-Mashqi Mosque in Asir, aiming to revive its original architectural style and historical significance. The project focuses on using natural materials from the region and adhering to traditional architectural designs. The broader goals of this initiative are to preserve the historical and architectural heritage of these mosques, enhance their role in worship, and highlight the cultural and religious depth of Saudi Arabia, aligning with the Vision 2030’s emphasis on national heritage.

    6. How might the recent US tariffs impact Saudi Arabia’s stock market and economy? According to financial experts cited in the article, the recent US tariffs could potentially increase the attractiveness of the Saudi stock market due to concerns related to the effects of these tariffs and the possible return of migrating capital. The stability of the Saudi economy and the available investment opportunities, especially in line with the diversification goals of Vision 2030, could draw investors seeking safer and more promising markets. This inflow of funds might improve liquidity in the Saudi financial market and contribute to overall economic growth, particularly as investors look for alternatives amid global trade uncertainties.

    7. What role does the King Salman Humanitarian Aid and Relief Centre (“KSrelief”) play in international humanitarian efforts? The King Salman Humanitarian Aid and Relief Centre (“KSrelief”) is the Kingdom of Saudi Arabia’s primary entity for providing international humanitarian aid and relief. It undertakes a wide range of projects aimed at alleviating suffering and addressing the needs of vulnerable populations around the world. Recent examples include the distribution of food baskets in Sudan and Lebanon to support food security for those affected by crises. KSrelief’s efforts reflect Saudi Arabia’s commitment to humanitarian principles and its active role in addressing global humanitarian challenges.

    8. How is Saudi Arabia supporting people with disabilities and promoting their inclusion in society and the workforce? Saudi Arabia, in line with its Vision 2030, is actively working to empower people with disabilities and ensure their full rights and integration into society. The Ministry of Education and related administrations are investing in educational and rehabilitation programs tailored to their needs. Initiatives like the “World of Industry” program in Al-Ahsa exemplify these efforts by providing vocational training and opportunities for individuals with disabilities to contribute to the nation’s development and showcase their capabilities, including participating in significant national projects.

    01
    كوماندو جروب” تحصد بطولة دبي الدولية لرابطة أبوظبي لمحترفي الجوجيتسو

    Saudi-Georgia Bilateral Relations: Growth and Cooperation

    Saudi Arabia and Georgia share increasingly strong bilateral relations characterized by growing cooperation in various fields. These relations have witnessed notable development in diplomatic and political ties.

    A significant aspect of Saudi-Georgia relations is the growing economic cooperation and investment between the two nations. The bilateral trade volume reached approximately 162 million Saudi Riyals in 2023. During this period, Saudi exports constituted 31% of this volume, while Georgian imports represented 69%.

    Further bolstering economic ties, the Saudi-Georgian Business Forum was held in Tbilisi in October 2024, with the participation of over 200 companies from both sides. This forum witnessed the signing of several important commercial agreements and partnerships in key sectors such as transport, energy, and tourism, reflecting a mutual commitment to enhancing economic and investment cooperation.

    Tourism also plays a role in the relationship, with Georgia experiencing a notable increase in the number of Saudi tourists visiting the country. This rise is partly attributed to the fact that Saudi citizens do not require a visa to enter Georgia, facilitating travel between the two nations.

    Both Saudi Arabia and Georgia have expressed their commitment to strengthening bilateral relations and developing cooperation across various fields in a way that serves the interests of both countries. This commitment is further evidenced by the signing of an agreement for the Saudi-Georgian Coordination Council.

    His Excellency the Saudi Ambassador to Georgia, Sheikh Ali bin Abdulrahman bin Salman Al Sheikh, who is also the non-resident Ambassador to Armenia, has highlighted the efforts undertaken by the Saudi embassy in Georgia to further develop relations between the two friendly countries. Georgia is described in the sources as a friendly country with a focus on sustainable development.

    The fourth edition of the Tbilisi Silk Road Forum, held in Tbilisi in 2023, also saw the participation of Saudi officials and a delegation of dignitaries, aiming to strengthen partnerships with international partners, including Georgia.

    01
    بيت لا يطرق فيه باب

    Sudan Conflict: Two Years of War and Humanitarian Crisis

    The Sudan conflict is approaching its second year since it began on April 15, 2023, between the army and the Rapid Support Forces. This conflict has resulted in a devastating human cost, with tens of thousands killed and over 12 million people displaced, leading to a worsening humanitarian crisis.

    01
    ترمب: سأوقع أمراً تنفيذياً لإبقاء «تيك توك» قيد التشغيل لـ 75 يوماً إضافية

    Saudi Stock Market Attractiveness and Capital Migration

    Based on the sources, the Saudi stock market is viewed as increasingly attractive.

    Specifically, Dr. Ali bin Mohammed Al-Hazmi states that Saudi stock markets are considered enticing and in a good position. He also anticipates a potential migration of global capital from American financial markets to the Saudi stock market. This expected inflow of capital to the local stock market is linked to the application of new customs tariffs.

    Dr. Al-Hazmi suggests that diversifying the Saudi economy opens up opportunities and reduces risks, which could contribute to the attractiveness of its financial markets.

    The sources also mention that a recent trend shows a migration of capital from American financial markets to global markets, which is described as a complex phenomenon with economic and political dimensions. Factors contributing to this include global economic changes, monetary policies, and geopolitical tensions. This capital migration is not just a movement of funds but also reflects changing confidence in American markets and evolving investor preferences.

    In this context, Dr. Al-Hazmi advises that decision-makers and investors should deal with the capital migration phenomenon cautiously, understand the real reasons behind it, and develop appropriate strategies to maintain financial and economic stability in the United States. However, from a Saudi perspective, this migration could signify a positive outlook for the local stock market.

    01
    الألكسو» تدعو إلى حماية المخطوطات العربية وحفظها ورقمنتها

    South Lebanon: Diplomacy, Security, and Resolution 1701

    Based on the sources, the situation in South Lebanon is a topic of ongoing discussion and concern, involving multiple actors and international resolutions.

    Key aspects of the South Lebanon situation, as highlighted in the sources, include:

    • Diplomatic Engagement: Meetings have taken place between high-ranking Lebanese officials, including President Michel Aoun and Prime Minister Najib Mikati, and Morgan Ortagus, the US envoy’s deputy for the Middle East. These meetings were described as “constructive” and “positive”, focusing on the situation in South Lebanon and other issues.
    • UN Resolution 1701: Discussions have revolved around the implementation of UN Security Council Resolution 1701, which ended the 2006 war between Israel and Hezbollah. This includes the withdrawal of Israeli forces from Lebanese territory and the cessation of hostilities. The Lebanese army is reportedly taking measures to implement this resolution and extend state authority over all Lebanese territories, including the south, aiming to confine arms to the state.
    • Security Concerns: The sources mention ongoing Israeli raids in southern and eastern Lebanon. Furthermore, a recent Israeli air strike in South Lebanon resulted in the death of a Hamas official along with his family. The Lebanese National News Agency reported that the strike was carried out by an “enemy drone” targeting an apartment in Sidon.
    • Border Control: Discussions between Lebanese Prime Minister Najib Mikati and Morgan Ortagus also emphasized the need to control the border with Syria to prevent chaos, tensions, and smuggling.
    • Hezbollah’s Role: The situation is complicated by the significant influence of Hezbollah in Lebanese affairs, and there is an ongoing debate about disarming the group. The new head of Lebanon’s central bank, Said, has identified combating money laundering and the financing of terrorism as top priorities, amid concerns about Hezbollah’s financial activities and the US Treasury’s sanctions on its financial institution, Al-Qard Al-Hassan. Said has stated that any financial activities by Hezbollah outside the legal framework are unlawful and will be prevented.
    • Ceasefire Agreement: These events are occurring despite a ceasefire agreement that has been in place since November 27th.
    • Lebanese Economic Situation: The context of these discussions includes Lebanon’s efforts to be removed from the FATF “grey list” and the ongoing repercussions of a severe financial crisis that began in 2019.

    In summary, the situation in South Lebanon is characterized by ongoing diplomatic efforts, particularly involving the US, focused on maintaining stability and implementing UN Resolution 1701. However, the situation remains tense due to continued Israeli military activity, the significant presence and influence of Hezbollah, and the complex internal political and economic challenges facing Lebanon.

    01
    دايم السيف”… الإرث والثراء الخالد

    Saudi Arabia: Humanitarian Aid Under King Salman

    While the sources don’t explicitly discuss an entity or program named “King Salman Relief,” they do provide insights into Saudi Arabia’s commitment to humanitarian aid, charitable activities, and support for those in need, which can be understood as reflecting the values and directives under the leadership of King Salman.

    Several instances in the sources highlight this commitment:

    • During Ramadan, a significant emphasis is placed on providing aid to those fasting. The distribution of Iftar meals near the Grand Mosque in Mecca is mentioned. This demonstrates a dedication to supporting pilgrims and the needy during a holy time.
    • The sources show Saudi Arabia’s concern for humanitarian crises in the region, as evidenced by the strong condemnation of Israeli actions in the Palestinian territories and Syria, including the targeting of civilians and shelters. The kingdom also stressed the importance of international accountability for these violations.
    • The Palestinian Red Crescent Society’s efforts to provide mobile health clinics, online learning, and other services to the displaced are noted. While not directly attributed to “King Salman Relief,” it indicates a broader regional effort in humanitarian aid.
    • The sources mention the role of charitable institutions in achieving national development needs and building the capabilities of individuals and societies, suggesting a structured approach to aid and development within the Kingdom.
    • The general atmosphere of charity and giving during the Eid celebrations is also indicated.

    Furthermore, the emphasis on providing the best services for pilgrims at the holy sites underscores a commitment to the well-being of those visiting Saudi Arabia for religious purposes.

    In summary, while the specific term “King Salman Relief” isn’t used in the provided sources, the content strongly suggests a continuous effort by Saudi Arabia, under its leadership, towards humanitarian aid, charitable giving, and supporting vulnerable populations both domestically and in the wider region. These actions align with the principles of relief and assistance that would be expected under a leadership focused on humanitarian values.

    01
    بدور القاسمي: “الكتب تلعب دوراً مركزياً في تحقيق الوحدة والتقدم وتعزيز التفاهم بين الثقافات

    Main Headings

    • ولي العهد والرئيس الإيراني يبحثان تطورات الأحداث في المنطقة The Crown Prince and the Iranian President discuss developments in the region.
    • المملكة تدين التصعيد الإسرائيلي في الأراضي الفلسطينية وسورية The Kingdom condemns the Israeli escalation in the Palestinian territories and Syria.
    • السفير آل الشيخ : المملكة وجورجيا تعززان الشراكة والاستثمار Ambassador Al-Sheikh: The Kingdom and Georgia are strengthening partnership and investment.
    • عون وسلام يبحثان مع أورتاغوس الوضع في جنوبي لبنان Aoun and Salam discuss the situation in southern Lebanon with Ortagus
    • الرسوم الأميركية» ترفع جاذبية سوق الأسهم السعودية US tariffs increase the attractiveness of the Saudi stock market
    • حرب السودان تقترب من إتمام عامها الثاني Sudan’s war nears its second year

    By Amjad Izhar
    Contact: amjad.izhar@gmail.com
    https://amjadizhar.blog

  • After my divorce at 40, struggled everything alone. The loneliness of everyday.

    After my divorce at 40, struggled everything alone. The loneliness of everyday.

    Nothing prepares you for the silence that follows a sudden loss. One moment, you are part of a shared life, with routines, conversations, and laughter filling the air. The next, you are alone—left to navigate a world that feels both familiar and alien. Divorce at 40 is not just about signing legal papers; it is about confronting the deep void in your daily existence. The loneliness is not always dramatic; sometimes, it is the quiet hum of an empty house or the absence of a simple goodnight text that stings the most.

    When my partner left and asked for a divorce, I was blindsided. It felt as though my entire world had crumbled in an instant. I had built a life around shared responsibilities, mutual dreams, and the comfort of companionship. Suddenly, I found myself staring at a future I never planned for—one where I had to figure out everything on my own. From the mundane tasks of grocery shopping to the weightier burdens of financial stability, I was thrust into an unfamiliar reality where loneliness became my closest companion.

    But this is not just a story of loss; it is also one of rebuilding. In the aftermath of heartbreak, I realized that independence is not just about survival—it is about rediscovering myself outside of my past relationship. The journey has been painful, but it has also been enlightening. Through leaning on friends, embracing solitude, and slowly reconstructing my identity, I am learning that while divorce is an end, it is also an opportunity for a new beginning.


    1 – My partner suddenly left me and asked for a divorce.

    There is a certain security that comes with a long-term relationship—the belief that no matter what happens, you will face it together. When my partner left unexpectedly, that illusion shattered. I was left questioning everything: Was it something I did? Could I have prevented this? The abruptness of it all was the most devastating part. One day, we were making weekend plans; the next, I was alone, trying to piece together the fragments of my old life. Psychologists often describe sudden separation as a form of psychological trauma, akin to grief, because it involves the loss of a loved one—except, in this case, they chose to leave.

    In her book Runaway Husbands: The Abandoned Wife’s Guide to Recovery and Renewal, Vikki Stark explores the profound emotional shock of unexpected divorce. She describes it as a “betrayal trauma,” where the brain struggles to process the abrupt departure of a partner. That was exactly how I felt—like I had been emotionally ambushed. The pain was overwhelming, but with time, I began to understand that the end of my marriage did not define my worth. I could either let it break me or use it as fuel to rebuild a stronger, more independent version of myself.


    2 – I struggled to handle everyday activities alone — like grocery shopping and finances.

    It is the small, everyday responsibilities that make loneliness truly sink in. Grocery shopping used to be a shared task—debating over brands, splitting the cart, planning meals together. Now, it felt like a reminder of what I had lost. Every aisle held memories, from the way we used to laugh over impulse purchases to the quiet moments of decision-making. It wasn’t just about food; it was about the presence that was missing. Simple tasks that once felt effortless became daunting when I had to do them alone.

    Finances were another overwhelming hurdle. I had relied on my partner to handle most of the bills, investments, and budgeting, and now, I was staring at spreadsheets and account statements, trying to make sense of it all. As financial expert Suze Orman states, “Owning your financial future is the most powerful thing you can do for yourself.” It took time, research, and a lot of mistakes, but I slowly started to take control. Learning to manage money was not just about survival—it was about reclaiming my independence.


    3 – I am working on my independence and now lean on my friends for support.

    In the wake of my divorce, I initially thought I had to do everything alone. I equated independence with isolation, assuming that asking for help was a sign of weakness. But I soon realized that independence is not about rejecting support—it is about choosing the right people to lean on. My friends became my lifeline, stepping in with encouragement, advice, and a simple presence that reminded me I was not alone.

    According to Brené Brown, author of The Gifts of Imperfection, true strength comes from vulnerability. She writes, “We don’t have to do all of it alone. We were never meant to.” This lesson reshaped my healing process. I no longer felt ashamed of reaching out for help, whether it was for emotional support or practical advice. My friends did not just fill the void left by my ex-partner; they helped me see that my life was still full of love, laughter, and meaning.


    4 – I’m alone on my most painful days.

    No matter how strong my support system is, there are moments of loneliness that no one else can fill. Birthdays, anniversaries, holidays—these days come with a hollow ache, a reminder of what used to be. Grief does not operate on a schedule; it sneaks up in unexpected ways. A song on the radio, an inside joke only we understood, a familiar scent—all of these can trigger an emotional landslide.

    Psychologist Judith Sills, in The Comfort Trap, explains that solitude can be both a curse and a gift. While painful, it also forces us to confront our emotions, process our loss, and grow from it. Instead of drowning in sadness, I started using these lonely moments as a time for self-reflection. I began journaling, meditating, and rediscovering hobbies I had set aside. Loneliness, when embraced, became a stepping stone toward healing.


    5 – The financial burden is all on me now.

    One of the harshest realities of divorce is financial instability. What was once a shared responsibility suddenly became mine alone. The weight of mortgage payments, utility bills, and daily expenses felt suffocating. I had to reevaluate my lifestyle, cut unnecessary costs, and rethink my financial goals. It was terrifying, but it was also an eye-opening experience that forced me to take control of my future.

    Experts like Jean Chatzky, author of Women with Money, emphasize the importance of financial literacy, especially for women post-divorce. She states, “Taking charge of your money is taking charge of your life.” I started educating myself—reading books, attending financial planning workshops, and seeking advice from professionals. Slowly, I went from feeling powerless to feeling empowered.


    6 – The small, daily moments are the hardest.

    It is not the grand occasions that hurt the most; it is the tiny, everyday moments. Making coffee in the morning without someone to share it with. Coming home to an empty house. Cooking for one. These small, seemingly insignificant rituals once carried warmth, but now they serve as quiet reminders of solitude.

    In The Unexpected Joy of Being Single, Catherine Gray highlights that embracing solitude is key to rediscovering oneself. She writes, “Being alone doesn’t mean being lonely. It means you are enough as you are.” I started focusing on self-care, turning these moments into acts of self-love rather than reminders of loss. My morning coffee became a time for reflection, my solo dinners turned into a chance to explore new recipes, and my evenings became a sanctuary rather than a void.


    7 – I’m rebuilding my life without my partner.

    The process of rebuilding after divorce is neither quick nor linear. It is a journey filled with setbacks, revelations, and moments of unexpected joy. In the beginning, I saw my future as a blank, terrifying slate. But over time, I started to view it as a canvas—one I could paint however I wanted.

    Elizabeth Gilbert, in Eat, Pray, Love, describes reinvention after heartbreak as an opportunity to “build the life you truly want.” That is what I am doing now. I am redefining what happiness looks like, setting new goals, and discovering strengths I never knew I had. My past relationship was a chapter, but it is not my whole story. My future belongs to me.


    Conclusion

    Divorce at 40 shattered my world, but it also forced me to rebuild it in a way that was uniquely mine. The loneliness, the financial struggles, and the daily adjustments were painful, but they also taught me resilience. I have learned that independence does not mean facing everything alone—it means creating a life that is fulfilling on my own terms. While the journey is far from over, I now know that I am strong enough to walk it.

    By Amjad Izhar
    Contact: amjad.izhar@gmail.com
    https://amjadizhar.blog