I’m trying to change two SQL queries I have right now so that in addition to giving me a result from a table, it only gives me that result based on the newest say 150 entries within the table. My two …
Trying to JOIN columns from two different tables
I have one table (city_data) with the columns ‘year’, ‘city_name’ and ‘avg_temp’. The other table is global_data and has the columns ‘avg_temp’ and ‘year’. I am trying to create a table which has the …
What is the advantage of using multiple cursors in psycopg2 for PostgreSQL queries?
What is the difference between using a single cursor in psycopg2 to perform all your queries against using multiple cursors. I.e, say I do this: import psycopg2 as pg2 con = psycopg2.connect(…) …
SQL Query subquery with COUNT()
I’m trying to return the ‘conm’ that has 79 rows only. Here is my query: SELECT * FROM combinedata1 WHERE EXISTS ( SELECT conm, COUNT(conm) AS ‘Number of Rows’ FROM combinedata1 …
how to select all the values in hive with distinct of 2 columns in hive
I have a hive table that looks like this (total 460 columns) colA colB ……. ce_id filename ……… dt v j 4 gg 40 v j 5 gg …
System Catalog vs Information Schema
When looking at SQL Server Management Studio (SSMS), which one is better and why? Are there cases where we should use one over the other? I can’t tell the difference between them. Answer INFORMATION_SCHEMA is there for compatibility, it doesn’t expose all the information about objects on the insta…
Migrating data from old table to new table Postgres with extra column
Table Structure: Old Table Structure: New Table Structure: Query: INSERT INTO hotel (id, name, hotel_type, active, parent_hotel_id) SELECT id, name, hotel_type, active, parent_hotel_id FROM …
Country-wise Analysis of Movies
Write a query to find the number of movies rented across each country. Display only those countries where at least one movie was rented. Arrange these countries in the alphabetical order. DB: https://dev.mysql.com/doc/sakila/en/sakila-structure.html Below is the written code my output is displayed as below Ho…
Postgres get multiple rows into a single json object
I have a users table with columns like id, name, email, etc. I want to retrieve information of some users in the following format in a single json object: Wherein the users unique id is the key and a json containing his information is its corresponding value. I am able to get this information in two separate …
Cascade DELETE to row of another table
CREATE OR REPLACE FUNCTION removerCapitulo() RETURNS trigger AS $BODY$ declare counter int; BEGIN select count(*) into counter FROM capitulos where id_capitulo = NEW.id_livro; if (counter >1) …