Skip to content

Tag: sql

how to use wildcard for a column jsonb type

I have a table (named profile) in my Postgres database, which has 3 columns: ID, Day, Ftfm_profile of type jsonb, I tried to extract the row where the profile name (ftfm_profile->’name’) begins with ‘LFBB’ ( sql: LFBB%) using the wildcard as following: the expected result: I can&#82…

inserting a variable into openquery

I’m trying to insert a variable into the openquery expression, but unfortunately I get an error, does anyone know where I got this error? Arithmetic overflow error when converting expression data to int data type. Answer OPENQUERY requires a literal string, you can’t put variables into it. As such…

Count seen users per week

My input table looks like: id user_id at 1 1 2020-12-07 13:07:35 2 794 2020-12-07 13:12:17 3 794 2020-12-07 13:12:26 4 794 2020-12-07 13:12:27 5 263 2020-12-07 13:12:50 6 263 2020-12-07 13:12:50 7 263 2020-12-07 13:13:10 8 1029 2020-12-07 13:18:07 9 1029 2020-12-07 13:18:07 10 378 2020-12-07 13:19:10 11 378 2…

AWK – Parsing SQL output

I have a SQL output something like below from the output of a custom tool. Would appreciate any help in finding what I am doing incorrectly. I am trying to pipe this output the columns I need in my case column1, column2, and column7. I have tried piping out like this but it just prints column1 tool check | aw…

SQL how to select only single row using joining?

I have the tables: tblClients: tblKeys: tblEntries: lClientID and lKeyID (optional) refer to above tables. I need a SQL query which gives me the list of the users from the tblEntries only with maximum datDate field. Now i used the follwing SQL query: The problem i encountered is the datLastAccess can contains…

How to list last 7 days records in postgresql?

I want to display current date and previous 7 days. the query doesnt work for me. Answer I doubt you have future entry dates. So don’t use between. Instead: Note: If you want to count the current date as a day, then you want interval ‘6 days’.

Table, Row valued UDFs in SQL Server

SQL Server (and some other databases) support a Table-value function. Is there a such thing as a Row-valued function — where based on a set of input values, a specific row would be returned, or is that type of function type not supported. If not, why isn’t it supported? The example SQL Server give…