{"id":39823225,"url":"https://github.com/muhammadfarooq85/postgresql-views-having-clause","last_synced_at":"2026-01-18T13:01:19.636Z","repository":{"id":282566200,"uuid":"878763745","full_name":"muhammadfarooq85/PostgreSQL-Views-Having-Clause","owner":"muhammadfarooq85","description":"This repository is how to use views and having clause in PostgreSQL.","archived":false,"fork":false,"pushed_at":"2024-10-26T04:27:49.000Z","size":3,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-15T13:37:16.816Z","etag":null,"topics":["database","postgresql","sql"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/muhammadfarooq85.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-26T03:45:35.000Z","updated_at":"2024-10-27T03:31:24.000Z","dependencies_parsed_at":"2025-03-15T13:47:22.241Z","dependency_job_id":null,"html_url":"https://github.com/muhammadfarooq85/PostgreSQL-Views-Having-Clause","commit_stats":null,"previous_names":["muhammadfarooq85/postgresql-views-having-clause"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/muhammadfarooq85/PostgreSQL-Views-Having-Clause","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/muhammadfarooq85%2FPostgreSQL-Views-Having-Clause","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/muhammadfarooq85%2FPostgreSQL-Views-Having-Clause/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/muhammadfarooq85%2FPostgreSQL-Views-Having-Clause/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/muhammadfarooq85%2FPostgreSQL-Views-Having-Clause/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/muhammadfarooq85","download_url":"https://codeload.github.com/muhammadfarooq85/PostgreSQL-Views-Having-Clause/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/muhammadfarooq85%2FPostgreSQL-Views-Having-Clause/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28536686,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-18T10:13:46.436Z","status":"ssl_error","status_checked_at":"2026-01-18T10:13:11.045Z","response_time":98,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","postgresql","sql"],"created_at":"2026-01-18T13:01:07.648Z","updated_at":"2026-01-18T13:01:19.620Z","avatar_url":"https://github.com/muhammadfarooq85.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# PostgreSQL-Views-Having-Clause\n\n## This repository is how to use views and having clause in PostgreSQL.\n\n### 1) `What is view?`\n\n```\n    In PostgreSQL, a view is a virtual table that is based on the result of a SQL query. It does not store data itself but provides a way to present data from one or more tables in a specific format. Views can simplify complex queries, enhance security by restricting access to specific data, and encapsulate frequently used queries.\n```\n\n#### Key Features of Views:\n\n- Virtual Table: Views act like tables but do not hold data.\n- Simplified Queries: They can simplify complex SQL queries by encapsulating them.\n- Security: You can grant access to a view without exposing the underlying tables.\n- Updatable: Some views can be updated, allowing you to change data in the underlying tables.\n\n### 2) `Create a emplyees table?`\n\n```\nCREATE TABLE employees (\n    id SERIAL PRIMARY KEY,\n    name VARCHAR(100),\n    department_id INT,\n    salary NUMERIC\n);\n```\n\n### 3) `Create a department table?`\n\n```\nCREATE TABLE departments (\n    id SERIAL PRIMARY KEY,\n    name VARCHAR(100)\n);\n```\n\n### 4) `Create view that shows employees along with their department names`\n\n```\nCREATE VIEW employee_departments AS\nSELECT\n    e.id,\n    e.name AS employee_name,\n    d.name AS department_name,\n    e.salary\nFROM\n    employees e\nJOIN\n    departments d ON e.department_id = d.id;\n```\n\n### 5) `querying view`\n\n```\nSELECT * FROM employee_departments;\n```\n\n### 6) `Update view`\n\n```\nUPDATE employee_departments\nSET salary = salary * 1.10\nWHERE department_name = 'Sales';\n```\n\n### 7) `Drop view`\n\n```\nDROP VIEW employee_departments;\n```\n\n### `What is having clause?`\n\n```\nThe HAVING clause in PostgreSQL is used to filter the results of a GROUP BY query. It is similar to the WHERE clause but is applied after the aggregation of data has occurred. This means that HAVING can filter based on aggregate functions like SUM(), COUNT(), AVG(), etc.\n```\n\n### 1) `Create a sales table`\n\n```\nCREATE TABLE sales (\n    id SERIAL PRIMARY KEY,\n    product VARCHAR(100),\n    quantity INT,\n    price NUMERIC\n);\n\n```\n\n### 2) `Insert dummy data into sales table`\n\n```\nINSERT INTO sales (product, quantity, price) VALUES\n('Widget A', 10, 5.00),\n('Widget B', 20, 7.50),\n('Widget A', 5, 5.00),\n('Widget C', 15, 10.00);\n```\n\n### 3) `Querying a view`\n\n```\nSELECT product, SUM(quantity) AS total_quantity\nFROM sales\nGROUP BY product\nHAVING SUM(quantity) \u003e 20;\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmuhammadfarooq85%2Fpostgresql-views-having-clause","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmuhammadfarooq85%2Fpostgresql-views-having-clause","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmuhammadfarooq85%2Fpostgresql-views-having-clause/lists"}