SQL counting total by type - mysql

Hi everyone.
i have a question here that i was trying to practice on the web. however i do not know how write the MySQL query for this question. Can you please help me with this.
i keep getting errors in my codes. so far i only succeeded in concating the last name and first name together it seems.i do not know how to resolve the other parts of the questions
I hope you can help me with this

Related

SQL Implementation - Social Media Like Functionality

I am building a full stack app, that is kind of like Pinterest or Instagram.
I've gotten stuck, which is a horrible feeling, and I'd love any help I could get from any kind soul out there! :)
So I'm trying to implement the "like" functionality. As y'all know, you can like an entity once, and only once. What I wonder is how to constrain the database in such a way that a user can't like more than once. The way I thought I'd do this is to have a separate Like table like this:
Now of course, if I UNIQUE the user_id, then users can only like one thing on the website, which obviously would be a disaster, hah. So my question is, how do I kind of make sure there are no duplicate rows with exactly the same information in them? Or make some kind of CHECK condition when creating the table so that there can't be more than one row where the user_id and the artpoem_id match?
Or am I thinking about this the wrong way? Should I have like a separate Like table for each and every ArtPoem-entry, and then UNIQUE the user_id?
I would be SO grateful for any help, as this has been bugging me for days. Thank you kindly!
Problem solved! If anyone else sees this in the future, here's how it happened:
With the help of #Solarflare here who pointed me in the right direction, I did this in my ORM (TypeOrm):
Which yielded this raw SQL:
And now my database gives me this error below when I try to add an additional like-table entry with matching artpoemIds and userIds, which is just what I was looking for! Yippie and onwards!

MYSQL split date string to standard format

This is my first post on the forums.
I would like your help to have MySQL to convert from 20200416174119Z to 2020-04-16 17:41:19.
Thank you in advance for providing light to the world.
Best regards,
Well, after several for days of frustration, and failed attempts, here is a code that can help someone that is trying to do this
SELECT CONCAT(SUBSTR(date,1,4),'-',SUBSTR(date,5,2),'-',SUBSTR(date,7,2),' ',SUBSTR(date,9,2),':',SUBSTR(date,11,2),':',SUBSTR(date,13,2))

SQL find users that consistently search with in five months during the whole year

I am facing a SQL problem that I can't think a way to solve it.
Please check the below table.
I want to find users that search at least once within consistent 5 months
Can someone help me please?

MySQL parse XML to table with unknown number or rows and no column names?

If it was any other programming language I could usually work it out in no time. But after spending 6 hours flat "googlling" how to do it and having a few arrogant people tell me I should "google it", as If I haven't spent half my morning doing that. I still can not work out how to do this.
The problem is every example seems to be either SQL not MYSQL and I have had a very hard time converting it to MYSQL, failed at that. Or other examples are for fixed column names and a number of columns.
The XML will be like this:
<root>
<interest> name of interest 1</interest>
<interest> name of interest 2</interest>
<interest> name of interest 3</interest>
<interest> name of interest 4</interest>
</root>
Not that complicated. But despite this I seem to have had no luck working out how to do this.
I know I could accomplish the same task using an IN clause and dynamically generating the SQL statement. But I want to do this properly and efficiently using a stored procedure.

Database displays less records

I have a file with 4.300.000 records, but when I do SELECT COUNT(*) FROM 'mytable', It just displays 4.270.000. I don't know why is this happening, and I have no idea how to check what's going on. I've tried looking in Webmin, but I don't get it. Do you have any idea of how to see why is this failing?
Thank you and sorry for the bad English.