Counts on Changed data
Try this: SELECT CONCAT(‘Change from ‘, OrgMatch, ‘ to ‘, ReMatchConfidence) AS Data, Count(IF(Date=”2017″, 1, NULL)) as ‘2017’, Count(IF(Date=”2016″, 1, NULL)) as ‘2016’ FROM tables GROUP BY OrgMatch, ReMatchConfidence;
Try this: SELECT CONCAT(‘Change from ‘, OrgMatch, ‘ to ‘, ReMatchConfidence) AS Data, Count(IF(Date=”2017″, 1, NULL)) as ‘2017’, Count(IF(Date=”2016″, 1, NULL)) as ‘2016’ FROM tables GROUP BY OrgMatch, ReMatchConfidence;
A Cartesian join (note there is no JOIN condition). All possible combinations of records are in the results: tableA (charfield Char(2)) tableB (numberfield Number(1)) INSERT ‘A’ INTO tableA; INSERT ‘B’ INTO tableA; INSERT 1 INTO tableB; INSERT 2 INTO tableB; SELECT * FROM tablea CROSS JOIN tableb Results: charfield|numberfield ===================== A |1 A |2 B … Read more
in requires parenthesis: in (…)
You can use a running, conditional MAX to get the latest datetime value when value = 2. You can exclude the current row by using ROWS BETWEEN UNBOUNDED PRECEDING AND 1 PRECEDING SELECT t.id, t.value, t.datetime, datetime2 = MAX(CASE WHEN t.value = 2 THEN t.datetime END) OVER (PARTITION BY t.id ORDER BY t.datetime ROWS BETWEEN … Read more
EDIT From SQL Server 2012 and later you might use the FORMAT function if you want to force a date into a formatted text: https://msdn.microsoft.com/en-us/library/hh213505.aspx With earlier versions you might use something like this: DECLARE @d DATETIME=GETDATE(); DECLARE @TargetFormat VARCHAR(100)=’DD/MM/YYYY’; SELECT CONVERT(VARCHAR(100),@d, CASE @TargetFormat WHEN ‘MM/DD/YYYY’ THEN 101 WHEN ‘DD/MM/YYYY’ THEN 103 –add all formats … Read more
Tables in SQL don’t have a defined order (they might have, depending on the concrete implementation, but you cannot count on it). If you require a certain ordering, you must order your result set when selecting. Therefore, I can see two possibilities: Update every id above the ‘missing’ row, and insert your new row using … Read more
There are several problems with Query 1. First, why does it have trailing ))? Either they shouldn’t be there, or there are some missing ( elsewhere. Second, the placement of the EXCEPT is wrong. The example is this… SELECT sname FROM … WHERE NOT EXISTS (…) EXCEPT SELECT bid FROM … But it appears that, … Read more
select to_char(systimestamp,’YYYY-MM-DD”T”HH24:MI:SS.FF2TZHTZM’) from dual; 2018-02-07T11:43:37.47+0800
You’ll have to get the percentage of the year worked and multiply it by the salary. If the joined_date is before January of that year, use ‘1.00’. Since you did not specify a SQL type, I chose MSSQL as I’m most familiar with it. Here’s an example using MSSQL: DECLARE @yearToFindSalaryFor INT = 2018 DECLARE … Read more
That table is really a very bad design. Anyway, here you have the code. It uses dynamic sql: DECLARE @sql nvarchar(max) SET @sql = N’CREATE TABLE TheMostStupidTableIHaveEverSeen(ID int, Name varchar(100)’ DECLARE @i int = 1 WHILE @i <= 598 BEGIN SET @sql = @sql + N’, A’ + CAST(@i AS nvarchar(4)) + N’ int’ SET … Read more