So I have a shell script which returns me the week number using an SQL query : This query returns 1. (Starting at 1st Jan) Python code: I have tried the following however it returns 52 rather than 1 : Week starting from Mon-Sun Is there another way in which I can get the week number of year based on
Tag: sql
SQL GROUP BY and HAVING but have results include column not included in GROUP BY to provide more detail?
Sample data: Week Client Amount 1 A 20 1 B 20 2 A 20 2 B 10 3 C 40 I want a query where if the total for the week is 40 or more, include those rows in the result set, but ALSO include the Client. So the results would look something like this: Week Client Amount 1 A
SQLServer – Is it possible to divide the results of the same column?
I have a table containing the input and output parameters of different APIs. Here is the structure of my database : The only way to differentiate if a parameter is input or output is the type. If the type is NULL ? It is an output parameter. So, I would like to know if it is possible in a simple
grouping equal values – aggregate function problem
I’ve created a table that lists venues in which several events take place. The same event in the same venue can have a different price. The last column calculates the total revenue for one venue. venue event totalprice sum Venue A Event A 5 30 Venue A Event A 10 30 Venue A Event B 5 30 Venue A Event
Postgres duplicate column based on value in column
I’ve the following table in postgresql id product customer price amount 1 Television Alfred 12.00 1 2 Radio Richard 20.00 3 3 Mobile Richard 40.00 5 Is there some way via SQL to duplicate the line n-times in case the amount is greater than one? This is how the table should look like after running the query: id product customer
Microsoft SQL Server Streak Counter
I have data in the following format: ID Period Date 1 1 2020-09-05 1 2 2020-10-01 1 3 2020-10-30 2 2 2020-10-01 2 4 2020-12-05 2 6 2021-02-05 3 1 2020-09-05 I want to calculate a streak grouping by both ID and period. The first date instance for each group should start at one, and if the date in the
How to add two conditions in merge statement using rowid and rownum
Query to load the sequence for e_uuid 13 & 15 Then I want to merge into the same table for e_uuid 14 & 16 For 14: It should check e_uuid = 13 and maximum seq_cnt. Here(after executing my merge statement) maximum seq_cnt is 2 then the seq_cnt for 14 will come as 3 & 4. And if there are any
How to get NULL or Zero values in SQL Server results set
Trying to get the output of all mentioned accounts(total of 9) even though there are no existing records for the GB.periode = 11 Tried using ISNULL(SUM(GB.bdr_val), 0) but still I’m only getting output for GB.reknr = 5210 OR GB.reknr = 5211 OR GB.reknr = 5250 OR GB.reknr = 5340. I have a sample DB layout below, I still need the
Sequelize raw query update array of objects as replacements
I am using sequelize (postgres) and I need to properly escape a query like this: Sample input.pets: Does anyone have an idea how to achieve this with replacements? I have found a thread on github which suggested something like this: However, a 2d array is being used here not an array of objects. Is there a way to access individual
How can I extend an SQL query in a variable?
I am testing possible SQL injections on my DB, and I am running a simple function to get results which a user should not be getting. The return value is correct based on id, however, the rest of the query is completely being ignored. I want to return all the data from the data table. Is there something wrong in