[Solved] Creating a database table (MySQL)

You should take a look at the mysql manual to learn about creating databases/tables: Create Table Syntax there are also examples of how to create tables. Edit: you can do either: INSERT INTO recipe (name, category) VALUES (‘Recipename’, ‘Categoryname’); since you only specify the columns where you want to add data or INSERT INTO recipe … Read more

[Solved] SQL query to get time spent on specific statuses based on single datetime column [closed]

with SQL Server you can use those very usefull windowed functions LEAD and FIRST_VALUE : select * ,[duration(sec)] = DATEDIFF(SECOND ,ticketTime ,LEAD(ticketTime,1,ticketTime)over(partition by ticketNumber order by ticketTime) ) ,[cumulative duration(sec)] = DATEDIFF( SECOND , FIRST_VALUE(ticketTime)over(partition by ticketNumber order by ticketTime) , ticketTime) from (values (1,cast(‘20211101 10:00:01′ as datetime)) ,(1,’20211101 10:00:33′) ,(1,’20211101 10:01:59’) )T(ticketNumber,ticketTime) ticketNumber ticketTime … Read more

[Solved] How to Select A number of data of table record, but before apply a condition on this record?

To expand on my comment about moving the [Gu-Id] IS NULL, try this: ALTER PROC [dbo].[SPFetchAllDisActiveUser] ( @StartRowIndex INT, @MaxRows INT ) AS BEGIN SELECT * FROM ( SELECT *, ROW_NUMBER() OVER(ORDER BY [User-ID] ASC) AS RowNum FROM [User-Tbl] WHERE [Gu-Id] IS NULL ) AS DisActiveUser WHERE RowNum BETWEEN @StartRowIndex + 1 AND @MaxRows; END … Read more

[Solved] Mysql Query error in where clause on left join

I think there should be A.created_date instead of A.created_at select `plans`.`name`, `A`.`subscription_id`, `A`.`amount`, `A`.`created_date`, `A`.`end_date`, `A`.`subscription_status`, `users`.`email`, `A`.`plan_id`, `A`.`user_id`, `usage`.`created_at` as `usagedate`, COUNT(usage.id) as used_count from `subscriptions` A left join `users` on `users`.`id` = `A`.`user_id` left join `plans` on `A`.`plan_id` = `plans`.`Id` left join `usage` on `A`.`user_id` = `usage`.`user_id` where `usage`.`created_at` between A.created_date and A.end_date … Read more

[Solved] I have a query with a between clause that is return wrong days [closed]

Let’s break this down: WHERE convert(varchar(10),F_Presence.ts, 120) between ‘2022-03-01’ and ‘2022-03-02’ Converting the column to a string means you will never, ever, ever be able to take advantage of an index on that column, whether it exists yet or not. Using BETWEEN is horrible for date ranges for multiple reasons. Using a format like YYYY-MM-DD … Read more

[Solved] Query to get a output in desired format

Another approach using CTE and Joins. declare @table table(Proce int, type char(1), addi int, sub int, multi int, div int) insert into @table values (1,’A’, 1, 0, 1, 1), (1,’B’, 2, 2, 0, 1); ;with cte_a as ( SELECT proce, max(addi) as Aadd, max(sub) as Asub, max(multi) as Amulti, max(div) as Adiv FROM @table where … Read more

[Solved] how to export specific column after query meets criteria?

Just include the column(s) you want after select instead of using * (“all”): select body from message where date between ‘2001-09-09 00:00:00’ and ‘2001-09-10 00:00:00’ The column(s) you select and the column(s) by which you filter can be two entirely different sets of columns. 1 solved how to export specific column after query meets criteria?

[Solved] Get first day of week T-SQL

DECLARE @YEAR int = 2020; DECLARE @WEEKSTOADD int = 6; SET DATEFIRST 1; SELECT DATEADD(day, 1 – DATEPART(dw,DATEADD(week,@WEEKSTOADD,cast(cast(@YEAR as varchar(4)) + ‘0101’ as date))), DATEADD(week,@WEEKSTOADD,cast(cast(@YEAR as varchar(4)) + ‘0101’ as date))) 3 solved Get first day of week T-SQL

[Solved] Weird accessing SQL data [closed]

SELECT meta_value FROM tablename WHERE meta_key = first_name SHould do the trick! What we are doing is selecting the value in the meta-value column if the meta_key column says ‘first_name’ You can do the same for all fields SELECT meta_value FROM tablename WHERE meta_key = admin_color Would return ‘fresh’ from your screen-shot. 2 solved Weird … Read more

[Solved] Line break gets replaced with rn in php

Try removing any stripslahes(). Stripslashes removes any backslashes and forward slashes. For example, line breaks are being sent as \n or \r and the stripslashes() takes away the backslashes in those, so that’s why it says ‘rn’. I had this very problem, and this solution helped me. Good luck! 1 solved Line break gets replaced … Read more

[Solved] SQL Query to fetch salary and distinct no of employees geting that sal from emp table [closed]

select emp.Salary, COUNT(*) from emp GROUP BY emp.Salary Will return a distinct list of Salaries and the number of Employees who have that salary, provided that Salary and Employee are both contained on a communal table (can’t tell from the question wording). Try expanding your question a little to get a better response. 1 solved … Read more