I am using SQL Server 2014 and I have a T-SQL query running against a specific Table (t1). Table t1 includes 3 columns named [HR_LeftDate], [Payroll_LeftDate] and [Status]. In that table, there are records which have their [HR_LeftDate] and [Payroll_LeftDate] as ‘NULL’ and some other records which…
problem with constraint order in create table in livesql
This gives error: This doesn’t: Why? Answer Each DBMS defined it’s syntax to write SQL. It only works if you obey their rules. It’s kind of obeying the law of a country while you are in it. You can’t ask why I should do that? You have to. Or choose any dbms you like. If your dbms tells…
Oracle sql pivoting values separated by commas
I have the below input ID LOTYP PROID LOCKR XXXXX 06 01 Y XXXXX 06 02 X XXXXX 06 02 S XXXXX 06 01 R XXXXX 02 01 Y XXXXX 02 02 X XXXXX 02 02 S XXXXX 02 01 R YYYYY 06 01 Y YYYYY 06 02 X YYYYY 06 02 S YYYYY 06 01 R YYYYY 02 01
How to select Maximum and minimum date values and pass those as a query
I have a table with the following entries CustomeID TransDate WorkID 1 2012-12-01 12 1 2012-12-03 45 1 2013-01-21 3 2 2012-12-23 11 3 2013-01-04 13 3 2013-12-24 16 4 2014-01-02 2 I am trying get the data between two dates and the required date values are minimum and maximum values of the column. I am able to …
How to replace identical values with incremental integers?
I have this SQL select: The output will look something like this: How can I replace the identical values of UserId with incremental integers, so that the output will look something like this: I have tried grouping the identical UserId rows first then joining it with the same table while having an incremental …
BOM Explosion with Blanks
I have a simple BOM table that contains a parent and a child column. Every row contains values. There are no blanks. To bring that table into a BI-Tool I need to add blank values for the parents, like …
For the GROUP BY function in PostgreSQL, how to set a value if any rows meet a condition?
I have a use case that needs to set a value if any rows meet a condition in the GROUP BY function of PostgreSQL. The example is as following. The table contains the following data. I want to run the SQL query to group by based on id. If any rows of the same id have type as ‘A’, then
Query which outputs the number of athletes that voted for someone in the same athletePosition? [closed]
Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed last year. Improve this question Like the title says, SQL query which outputs the number of athletes that voted for someone in …
SQL Order By on multiple columns containing Nulls
I have a table containing multiple columns, and I want to order by three of the columns within the table. I want to order by lot, then unit, and lastly number. Lot and Unit can contain nulls (need them listed at the bottom) whereas Number column does not contain Null. I’ve tried a bunch of case statemen…
Display duplicate row indicator and get only one row when duplicate
I built the schema at http://sqlfiddle.com/#!18/7e9e3 I would like to write a query that would produce the following result characteristics : Returns only one owner per boat When multiple owners on a single boat, return the youngest owner. Display a column to indicate if a boat has multiple owners. So the fol…