Skip to content
Advertisement

Tag: sql

SQL get the value of a nested key in a jsonb field

Let’s suppose I have a table my_table with a field named data, of type jsonb, which thus contains a json data structure. let’s suppose that if I run I get so in pretty formatting, the content of column data is I know that If I want to get directly in a column the value of a key (of “level 1”)

Compare two VAT numbers

I`m trying to list only the vat numbers which look like DDDDDDDDDLLDDDD else i have to list NULL https://i.stack.imgur.com/4PYR8.png Pretty sure that I`m close but still missing something 🙁 Answer You can use the regular expression ^d{9}[A-Z]{2}d{4}$ to match the start-of-the-string, then any 9 digits, then any 2 upper-case letters, then any 4 digits and, finally, the end-of-the-string: If you

Problem with Ambiguous Column Name in SQL script

I am new to SQL and using this online compiler. https://www.programiz.com/sql/online-compiler/ I have the following script and I am getting the error: Error: ambiguous column name: Customers.customer_id There is a customer_id column in multiple tables, but I am specifying which table to pull each column from. Why is it still saying it is ambiguous? Answer An UPDATE statement with a

SQL – count rows between dynamic number of date ranges

I have a table to store events like this: and another table to store posts like this: if I want to get count of posts that happened during a single event I can write: but how can I get the count of posts that happened during multiple events, when the target events are only known at runtime? Edit: the database

dates from the DATEDIFF()

I am using the query in Snowflake: It gives me no. of days as: days start_date end_date 14 2022-09-03 2022-09-17 28 2022-08-19 2022-09-16 but I need to find the dates for the days instead of just the no. of days i.e I want to see those all 14 dates instead of just no. of days. can anyone help. Answer so

PostgreSQL : Hint: No operator matches the given name and argument types

When I execute my query I have this error : Query failed: ERROR: operator does not exist: “GOOD_RECIEPT_ANOMALY_DETECTION_V2_last_alerts_sent_gsheet_histo” > timestamp without time zone Hint: No operator matches the given name and argument types. You might need to add explicit type casts. Position: 176 Here is my SQL query : I work on PostgreSQL database. I think the problem comes from

How unnest h2 table’s result

I have this field now in h2 want to select it but it doesn’t work Answer UNNEST in SQL is not a regular function, it is a collection derived table. You can use it in the FROM clause:

Advertisement